You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/06/07 16:32:32 UTC

[1/7] usergrid git commit: Cherrypicking first of the changes to account for future possible instances of the class cast exception

Repository: usergrid
Updated Branches:
  refs/heads/release-2.1.1 38909adaa -> 3df07791c


Cherrypicking first of the changes to account for future possible instances of the class cast exception


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/c46e1b68
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/c46e1b68
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/c46e1b68

Branch: refs/heads/release-2.1.1
Commit: c46e1b6871516009edeb4ab1a35603850f3645d8
Parents: 6b195a0
Author: George Reyes <gr...@apache.org>
Authored: Fri May 6 15:36:11 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Fri May 6 15:36:11 2016 -0700

----------------------------------------------------------------------
 .../persistence/entities/Notification.java      | 37 +++++++++-----
 .../impl/ApplicationQueueManagerImpl.java       | 52 +++++++++++++++-----
 .../AbstractServiceNotificationIT.java          | 26 ++++------
 3 files changed, 75 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/c46e1b68/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index d4f3529..bb2e03f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -17,18 +17,28 @@
 package org.apache.usergrid.persistence.entities;
 
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
 import javax.xml.bind.annotation.XmlRootElement;
-import java.util.*;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.annotations.EntityCollection;
 import org.apache.usergrid.persistence.annotations.EntityProperty;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.utils.InflectionUtils;
 
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
 /**
  * The entity class for representing Notifications.
  */
@@ -112,7 +122,7 @@ public class Notification extends TypedEntity {
 
     /** Map containing a count for "sent" and "errors" */
     @EntityProperty
-    protected Map<String, Long> statistics;
+    protected Map<String, Object> statistics;
 
     @EntityProperty
     protected Map<String, Object> filters;
@@ -275,11 +285,11 @@ public class Notification extends TypedEntity {
     }
 
     @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-    public Map<String, Long> getStatistics() {
+    public Map<String, Object> getStatistics() {
         return statistics;
     }
 
-    public void setStatistics(Map<String, Long> statistics) {
+    public void setStatistics(Map<String, Object> statistics) {
         this.statistics = statistics;
     }
 
@@ -294,13 +304,18 @@ public class Notification extends TypedEntity {
 
     public void updateStatistics(long sent, long errors) {
         if (this.statistics == null) {
-            this.statistics = new HashMap<String, Long>(2);
+            this.statistics = new HashMap<String, Object>(2);
             this.statistics.put("sent", sent);
             this.statistics.put("errors", errors);
         } else {
-            this.statistics.put("sent", sent + this.statistics.get("sent"));
-            this.statistics.put("errors",
-                    errors + this.statistics.get("errors"));
+            if(this.statistics.get( "sent" ) instanceof Integer){
+                this.statistics.put( "sent", sent + (Integer) this.statistics.get( "sent" ) );
+                this.statistics.put( "errors", errors + (Integer) this.statistics.get( "errors" ) );
+            }
+            else if (this.statistics.get( "sent" ) instanceof Long ) {
+                this.statistics.put( "sent", sent + (Long) this.statistics.get( "sent" ) );
+                this.statistics.put( "errors", errors + (Long) this.statistics.get( "errors" ) );
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c46e1b68/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
index eb5d794..23b21f2 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
@@ -16,29 +16,55 @@
  */
 package org.apache.usergrid.services.notifications.impl;
 
-import com.codahale.metrics.Meter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.usergrid.batch.JobExecution;
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.core.executor.TaskExecutorFactory;
-import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
-import org.apache.usergrid.persistence.entities.*;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
 import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
+import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.persistence.queue.QueueManager;
 import org.apache.usergrid.persistence.queue.QueueMessage;
-import org.apache.usergrid.services.notifications.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.usergrid.services.notifications.ApplicationQueueManager;
+import org.apache.usergrid.services.notifications.ApplicationQueueMessage;
+import org.apache.usergrid.services.notifications.JobScheduler;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.ProviderAdapterFactory;
+import org.apache.usergrid.services.notifications.TaskManager;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import com.codahale.metrics.Meter;
+
 import rx.Observable;
-import rx.Scheduler;
 import rx.Subscriber;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
 
-import java.io.IOException;
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicInteger;
 
 
 public class ApplicationQueueManagerImpl implements ApplicationQueueManager {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c46e1b68/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index 91b94b2..775827e 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -16,24 +16,18 @@
  */
 package org.apache.usergrid.services.notifications;
 
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.persistence.Query;
-import org.apache.usergrid.services.ServiceManagerFactory;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Receipt;
 import org.apache.usergrid.services.AbstractServiceIT;
-import org.springframework.beans.factory.annotation.Autowired;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -106,17 +100,17 @@ public abstract class AbstractServiceNotificationIT extends AbstractServiceIT {
     }
 
     protected void checkStatistics(Notification notification, long sent,  long errors) throws Exception{
-        Map<String, Long> statistics = null;
+        Map<String, Object> statistics = null;
         long timeout = System.currentTimeMillis() + 10000;
         while (System.currentTimeMillis() < timeout) {
             Thread.sleep(200);
             statistics = app.getEntityManager().get(notification.getUuid(), Notification.class).getStatistics();
-            if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
+            if ((Long)statistics.get("sent")==sent && (Long)statistics.get("errors")==errors) {
                 break;
             }
         }
-        assertEquals(sent, statistics.get("sent").longValue());
-        assertEquals(errors, statistics.get("errors").longValue());
+        assertEquals(sent, ((Long)statistics.get("sent")).longValue());
+        assertEquals(errors, ((Long)statistics.get("errors")).longValue());
     }
 
 }


[2/7] usergrid git commit: Added test and cleaned up imports that proves that the class cast issue will no longer occur.

Posted by mr...@apache.org.
Added test and cleaned up imports that proves that the class cast issue will no longer occur.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/0f13650f
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/0f13650f
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/0f13650f

Branch: refs/heads/release-2.1.1
Commit: 0f13650f500809b2d044568570dbf11f4a57f70c
Parents: c46e1b6
Author: George Reyes <gr...@apache.org>
Authored: Thu May 5 09:29:03 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Fri May 6 15:38:34 2016 -0700

----------------------------------------------------------------------
 .../collection/CollectionsResourceIT.java       | 82 +++++++++++++++-----
 1 file changed, 64 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/0f13650f/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index db07c3f..7afc87a 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -17,12 +17,28 @@
 package org.apache.usergrid.rest.applications.collection;
 
 
-import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.ClientErrorException;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import org.apache.commons.lang.RandomStringUtils;
+
 import org.apache.usergrid.persistence.Schema;
 import org.apache.usergrid.persistence.entities.Application;
-
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.test.resource.AbstractRestIT;
 import org.apache.usergrid.rest.test.resource.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource.model.Collection;
@@ -30,24 +46,16 @@ import org.apache.usergrid.rest.test.resource.model.Credentials;
 import org.apache.usergrid.rest.test.resource.model.Entity;
 import org.apache.usergrid.rest.test.resource.model.QueryParameters;
 import org.apache.usergrid.rest.test.resource.model.Token;
-import org.apache.usergrid.services.ServiceParameter;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.ClientErrorException;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.MediaType;
-
-import java.io.IOException;
-import java.util.*;
 
-import org.apache.commons.lang.NullArgumentException;
+import com.fasterxml.jackson.databind.JsonNode;
 
-import static org.junit.Assert.*;
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 
 /**
@@ -1096,4 +1104,42 @@ public class CollectionsResourceIT extends AbstractRestIT {
         assertEquals( 0, connectionsByQuery.getNumOfEntities() );
     }
 
+    @Test
+    public void testBeingAbleToRetreiveMigratedValues() throws Exception {
+
+
+        Entity notifier = new Entity().chainPut("name", "mynotifier").chainPut("provider", "noop");
+
+        ApiResponse notifierNode = this.pathResource(getOrgAppPath("notifier")).post(ApiResponse.class,notifier);
+
+        UUID uuid = UUIDUtils.newTimeUUID();
+        // create user
+
+        Map payloads = new HashMap<>(  );
+        payloads.put( "mynotifier","hello world" );
+
+        Map statistics = new HashMap<>(  );
+        statistics.put( "sent",1 );
+        statistics.put( "errors",0 );
+
+        Entity payload = new Entity();
+        payload.put("debug", false);
+        payload.put( "expectedCount",0 );
+        payload.put( "finished",1438279671229L);
+        payload.put( "payloads",payloads);
+        payload.put( "priority","normal");
+        payload.put( "state","FINISHED");
+        payload.put( "statistics",statistics);
+
+
+
+
+        ApiResponse user = this.app().collection("notifications/"+ UUIDUtils.newTimeUUID()).put(null,payload );
+        this.refreshIndex();
+
+        Collection user2 = this.app().collection("notifications").get();
+
+        assertEquals(1,user2.getNumOfEntities());
+
+    }
 }


[6/7] usergrid git commit: Merge commit 'refs/pull/517/head' of github.com:apache/usergrid into release-2.1.1

Posted by mr...@apache.org.
Merge commit 'refs/pull/517/head' of github.com:apache/usergrid into release-2.1.1


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/72c9df14
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/72c9df14
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/72c9df14

Branch: refs/heads/release-2.1.1
Commit: 72c9df14a4185a9dafe55255b9d2cda73ad27882
Parents: 0eaea98 9edfda6
Author: Michael Russo <mr...@apigee.com>
Authored: Tue Jun 7 09:15:25 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Tue Jun 7 09:15:25 2016 -0700

----------------------------------------------------------------------
 .../persistence/entities/Notification.java      | 38 ++++++---
 .../collection/CollectionsResourceIT.java       | 87 ++++++++++++++++----
 .../resource/endpoints/CollectionEndpoint.java  | 24 +++---
 .../impl/ApplicationQueueManagerImpl.java       | 52 +++++++++---
 .../AbstractServiceNotificationIT.java          | 26 +++---
 5 files changed, 158 insertions(+), 69 deletions(-)
----------------------------------------------------------------------



[5/7] usergrid git commit: bug fix - When cursor queryparam is passed in with an empty value then throw 400.

Posted by mr...@apache.org.
bug fix - When cursor queryparam is passed in with an empty value then throw 400.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/0eaea989
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/0eaea989
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/0eaea989

Branch: refs/heads/release-2.1.1
Commit: 0eaea9890b5149f2e7203a90c1dd37a886bbd12c
Parents: 38909ad
Author: Ayesha Dastagiri <ay...@gmail.com>
Authored: Mon Jun 6 13:55:41 2016 -0700
Committer: Ayesha Dastagiri <ay...@gmail.com>
Committed: Mon Jun 6 13:55:41 2016 -0700

----------------------------------------------------------------------
 .../pipeline/cursor/RequestCursor.java            | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/0eaea989/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
index dc6ae71..acd6e25 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
@@ -20,17 +20,15 @@
 package org.apache.usergrid.corepersistence.pipeline.cursor;
 
 
-import java.util.Base64;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import com.fasterxml.jackson.core.Base64Variant;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
 
 /**
  * A cursor that has been passed in with our request.  Adds utils for parsing values
@@ -76,13 +74,13 @@ public class RequestCursor {
      * Deserialize from the cursor as json nodes
      */
     private Map<Integer, JsonNode> fromCursor( final String cursor ) throws CursorParseException {
-        try {
-
-
+        if(cursor.isEmpty()){
+            throw new IllegalArgumentException("cursor cannot be empty");
+        }
 
+        try {
             JsonNode jsonNode = CursorSerializerUtil.fromString( cursor );
 
-
             Preconditions
                 .checkArgument( jsonNode.size() <= MAX_CURSOR_COUNT, " You cannot have more than " + MAX_CURSOR_COUNT + " cursors" );
 


[3/7] usergrid git commit: Fixed error with a PUT call actually sending a POST. Added additional assert to make sure that a POST will not encounter this issue as well.

Posted by mr...@apache.org.
Fixed error with a PUT call actually sending a POST.
Added additional assert to make sure that a POST will not encounter this issue as well.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/987ffdc0
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/987ffdc0
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/987ffdc0

Branch: refs/heads/release-2.1.1
Commit: 987ffdc01592b0b6e61b701720e04cfc8ba29331
Parents: 0f13650
Author: George Reyes <gr...@apache.org>
Authored: Mon May 9 10:50:36 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Mon May 9 10:50:36 2016 -0700

----------------------------------------------------------------------
 .../collection/CollectionsResourceIT.java       | 15 ++++++++----
 .../resource/endpoints/CollectionEndpoint.java  | 24 +++++++++++---------
 2 files changed, 23 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/987ffdc0/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index 7afc87a..0908f5c 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -24,7 +24,6 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
-import java.util.UUID;
 
 import javax.ws.rs.BadRequestException;
 import javax.ws.rs.ClientErrorException;
@@ -1112,7 +1111,6 @@ public class CollectionsResourceIT extends AbstractRestIT {
 
         ApiResponse notifierNode = this.pathResource(getOrgAppPath("notifier")).post(ApiResponse.class,notifier);
 
-        UUID uuid = UUIDUtils.newTimeUUID();
         // create user
 
         Map payloads = new HashMap<>(  );
@@ -1132,14 +1130,21 @@ public class CollectionsResourceIT extends AbstractRestIT {
         payload.put( "statistics",statistics);
 
 
-
-
-        ApiResponse user = this.app().collection("notifications/"+ UUIDUtils.newTimeUUID()).put(null,payload );
+        this.app().collection("notifications/"+ UUIDUtils.newTimeUUID()).post(payload );
         this.refreshIndex();
 
         Collection user2 = this.app().collection("notifications").get();
 
         assertEquals(1,user2.getNumOfEntities());
 
+        this.app().collection("notifications/"+ UUIDUtils.newTimeUUID()).put(null,payload );
+        this.refreshIndex();
+
+        user2 = this.app().collection("notifications").get();
+
+        assertEquals(2,user2.getNumOfEntities());
+
     }
+
+
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/987ffdc0/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java
index ad5d9a6..d1c7ab4 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/endpoints/CollectionEndpoint.java
@@ -16,22 +16,24 @@
  */
 package org.apache.usergrid.rest.test.resource.endpoints;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.usergrid.rest.test.resource.model.Collection;
-import org.apache.usergrid.rest.test.resource.state.ClientContext;
-import org.apache.usergrid.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.rest.test.resource.model.Collection;
+import org.apache.usergrid.rest.test.resource.state.ClientContext;
+import org.apache.usergrid.utils.StringUtils;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 
 /**
  * //myorg/myapp/mycollection
@@ -358,7 +360,7 @@ public class CollectionEndpoint extends NamedResource {
         // use string type so we can log actual response from server
         String responseString = resource.request()
             .accept(acceptHeader)
-            .post( javax.ws.rs.client.Entity.json( entity ), String.class);
+            .put( javax.ws.rs.client.Entity.json( entity ), String.class);
 
         if (logger.isDebugEnabled()) {
             logger.debug("Response from put: " + responseString);


[7/7] usergrid git commit: Additional enhancements to cursor validation and error messages.

Posted by mr...@apache.org.
Additional enhancements to cursor validation and error messages.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/3df07791
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/3df07791
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/3df07791

Branch: refs/heads/release-2.1.1
Commit: 3df07791c394de2e7ec7e1f9559e1490f63af630
Parents: 72c9df1
Author: Michael Russo <mr...@apigee.com>
Authored: Tue Jun 7 09:32:15 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Tue Jun 7 09:32:15 2016 -0700

----------------------------------------------------------------------
 .../pipeline/cursor/CursorSerializerUtil.java   |  9 ---------
 .../pipeline/cursor/RequestCursor.java          | 21 ++++++++++++++++----
 2 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/3df07791/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
index 7acdd00..5728433 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/CursorSerializerUtil.java
@@ -40,12 +40,6 @@ public class CursorSerializerUtil {
 
     private static final ObjectMapper MAPPER = new ObjectMapper( SMILE_FACTORY );
 
-    /**
-     * Aritrary number, just meant to keep us from having a DOS issue
-     */
-    private static final int MAX_SIZE = 1024;
-
-
     public static ObjectMapper getMapper() {
         return MAPPER;
     }
@@ -75,9 +69,6 @@ public class CursorSerializerUtil {
      */
     public static JsonNode fromString( final String base64EncodedJson ) {
 
-        Preconditions.checkArgument( base64EncodedJson.length() <= MAX_SIZE,
-            "Your cursor must be less than " + MAX_SIZE + " chars in length" );
-
         final byte[] data = Base64.getUrlDecoder().decode( base64EncodedJson );
 
         JsonNode jsonNode;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/3df07791/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
index acd6e25..0209794 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/pipeline/cursor/RequestCursor.java
@@ -35,6 +35,10 @@ import java.util.Map;
  */
 public class RequestCursor {
 
+    /**
+     * Arbitrary number, just meant to keep us from having a DOS issue
+     */
+    private static final int MAX_SIZE = 1024;
 
     private static final int MAX_CURSOR_COUNT = 100;
 
@@ -74,9 +78,15 @@ public class RequestCursor {
      * Deserialize from the cursor as json nodes
      */
     private Map<Integer, JsonNode> fromCursor( final String cursor ) throws CursorParseException {
-        if(cursor.isEmpty()){
-            throw new IllegalArgumentException("cursor cannot be empty");
-        }
+
+
+        Preconditions.checkArgument( cursor != null, "Cursor cannot be null");
+
+        Preconditions.checkArgument( cursor.length() <= MAX_SIZE,
+            "Your cursor must be less than " + MAX_SIZE + " chars in length" );
+
+        Preconditions.checkArgument( !cursor.isEmpty(), "Cursor cannot have an empty value");
+
 
         try {
             JsonNode jsonNode = CursorSerializerUtil.fromString( cursor );
@@ -95,8 +105,11 @@ public class RequestCursor {
 
             return cursors;
         }
+        catch ( IllegalArgumentException ie ){
+            throw new IllegalArgumentException("Provided cursor has an invalid format and cannot be parsed.");
+        }
         catch ( Exception e ) {
-            throw new CursorParseException( "Unable to serialize cursor", e );
+            throw new CursorParseException( "Unable to deserialize cursor", e );
         }
     }
 }


[4/7] usergrid git commit: Removed the type checking for integers since updateStatistics is only used once for guaranteed longs.

Posted by mr...@apache.org.
Removed the type checking for integers since updateStatistics is only used once for guaranteed longs.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/9edfda62
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/9edfda62
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/9edfda62

Branch: refs/heads/release-2.1.1
Commit: 9edfda620eefae7ce74a54ac1eff24b94d02094c
Parents: 987ffdc
Author: George Reyes <gr...@apache.org>
Authored: Mon May 9 12:19:28 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Mon May 9 12:19:28 2016 -0700

----------------------------------------------------------------------
 .../usergrid/persistence/entities/Notification.java      | 11 ++++++-----
 .../applications/collection/CollectionsResourceIT.java   |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/9edfda62/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index bb2e03f..c4867c3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -308,12 +308,13 @@ public class Notification extends TypedEntity {
             this.statistics.put("sent", sent);
             this.statistics.put("errors", errors);
         } else {
-            if(this.statistics.get( "sent" ) instanceof Integer){
-                this.statistics.put( "sent", sent + (Integer) this.statistics.get( "sent" ) );
-                this.statistics.put( "errors", errors + (Integer) this.statistics.get( "errors" ) );
-            }
-            else if (this.statistics.get( "sent" ) instanceof Long ) {
+            //Don't need to account for integers here because this is only called internally
+            //We won't ever need to call updateStatistics for a postedNotification as that only happens once
+            //after the notification is completed.
+            if (this.statistics.get( "sent" ) instanceof Long ) {
                 this.statistics.put( "sent", sent + (Long) this.statistics.get( "sent" ) );
+            }
+            if( this.statistics.get( "errors" ) instanceof Long){
                 this.statistics.put( "errors", errors + (Long) this.statistics.get( "errors" ) );
             }
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9edfda62/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index 0908f5c..690cec2 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -1118,7 +1118,7 @@ public class CollectionsResourceIT extends AbstractRestIT {
 
         Map statistics = new HashMap<>(  );
         statistics.put( "sent",1 );
-        statistics.put( "errors",0 );
+        statistics.put( "errors",2 );
 
         Entity payload = new Entity();
         payload.put("debug", false);