usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [13/50] [abbrv] usergrid git commit: Added the decrement call to delete so that entity counters are decremented. Added test proving that entity counters are decremented.
Date Mon, 02 May 2016 17:54:44 GMT
Added the decrement call to delete so that entity counters are decremented.
Added test proving that entity counters are decremented.


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

Branch: refs/heads/USERGRID-1246-MASTER
Commit: 6c00a1c2a76a4597d34557b13e193ea2e961baea
Parents: 60ec582
Author: George Reyes <grey@apache.org>
Authored: Fri Apr 15 14:40:27 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Mon May 2 10:47:48 2016 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  4 +-
 .../events/ApplicationRequestCounterIT.java     | 48 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/6c00a1c2/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index b74995a..68f5d71 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -651,15 +651,15 @@ public class CpEntityManager implements EntityManager {
      */
     @Override
     public void delete( EntityRef entityRef ) throws Exception {
-        //TODO: since we want the user to mark it and we sweep it later. It should be marked
by the graph manager here.
         //Step 1 & 2 Currently to block so we ensure that marking is done immediately
         //If this returns null then nothing was marked null so the entity doesn't exist
         markEntity( entityRef ).toBlocking().lastOrDefault( null );
 
-        //TODO: figure out how to return async call to service tier? Do I not need to?
         //Step 3
         deleteAsync( entityRef );
 
+        decrementEntityCollection( Schema.defaultCollectionName( entityRef.getType() ));
+
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6c00a1c2/stack/rest/src/test/java/org/apache/usergrid/rest/applications/events/ApplicationRequestCounterIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/events/ApplicationRequestCounterIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/events/ApplicationRequestCounterIT.java
index a1c07c5..cf07dff 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/events/ApplicationRequestCounterIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/events/ApplicationRequestCounterIT.java
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
 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;
+import org.apache.usergrid.rest.test.resource.model.Entity;
 import org.apache.usergrid.rest.test.resource.model.QueryParameters;
 
 import static org.junit.Assert.assertEquals;
@@ -62,4 +63,51 @@ public class ApplicationRequestCounterIT extends AbstractRestIT {
         assertEquals( 2, ( ( LinkedHashMap ) ( ( ArrayList)counters.get( "values" )).get(
0 )).get( "value" ));
 
     }
+
+    @Test
+    public void testDecrementingEntityCounters() throws Exception {
+
+        //Create test collection with test entity that is full text indexed.
+        int numberOfEntitiesToCreate = 10;
+
+        Entity[] entities = new Entity[numberOfEntitiesToCreate];
+        Entity testEntity = new Entity();
+        for(int i = 0; i < numberOfEntitiesToCreate; i++){
+            testEntity.put( "one","value"+i );
+            testEntity.put( "two","valuetwo"+i );
+            entities[i]= this.app().collection( "testCollection" ).post( testEntity );
+        }
+
+        //get default application
+       // ApiResponse defaultApp = org().app( clientSetup.getAppName() ).get();
+
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.addParam( "resolution", "all" ).addParam( "counter", "application.collection.testcollections"
);
+        Collection countersResponse = org().app( clientSetup.getAppName() ).collection( "counters"
).get( queryParameters ,true );
+
+        assertNotNull( countersResponse );
+        ArrayList counterValues = ( ArrayList ) countersResponse.getResponse().getProperties().get(
"counters" );
+        LinkedHashMap counters = ( LinkedHashMap ) counterValues.get( 0 );
+        assertEquals( "application.collection.testcollections", counters.get( "name" ) );
+
+        //Since it was accessed twice above.
+        assertEquals( 10, ( ( LinkedHashMap ) ( ( ArrayList)counters.get( "values" )).get(
0 )).get( "value" ));
+
+        for(int i = 0; i < numberOfEntitiesToCreate; i++){
+            this.app().collection( "testCollection" ).entity( entities[i] ).delete( );
+        }
+        
+        queryParameters.addParam( "resolution", "all" ).addParam( "counter", "application.collection.testcollections"
);
+        countersResponse = org().app( clientSetup.getAppName() ).collection( "counters" ).get(
queryParameters ,true );
+
+        assertNotNull( countersResponse );
+        counterValues = ( ArrayList ) countersResponse.getResponse().getProperties().get(
"counters" );
+        counters = ( LinkedHashMap ) counterValues.get( 0 );
+        assertEquals( "application.collection.testcollections", counters.get( "name" ) );
+
+        //Since it was accessed twice above.
+        assertEquals( 0, ( ( LinkedHashMap ) ( ( ArrayList)counters.get( "values" )).get(
0 )).get( "value" ));
+
+
+    }
 }


Mime
View raw message