usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [13/52] [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, 23 May 2016 14:16:56 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/f76aeaf5
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/f76aeaf5
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/f76aeaf5

Branch: refs/heads/asf-site
Commit: f76aeaf56e4b12516415db52da388eabc3ba20de
Parents: f064c49
Author: George Reyes <grey@apache.org>
Authored: Fri Apr 15 14:40:27 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Fri Apr 15 14:40:27 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/f76aeaf5/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 b2330f3..93f9b64 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
@@ -649,15 +649,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/f76aeaf5/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