You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/09/01 01:31:01 UTC

[26/38] usergrid git commit: more tests for aggregation

more tests for aggregation


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

Branch: refs/heads/USERGRID-545
Commit: a9e54d34ba4f108f35bbde20d6c25bef344587ec
Parents: 061ba91
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 31 10:13:32 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 31 10:13:32 2015 -0600

----------------------------------------------------------------------
 .../service/AggregationService.java             | 17 ++++++++++++
 .../service/AggregationServiceImpl.java         | 28 +++++++++++++++++++-
 .../corepersistence/AggregationServiceTest.java |  4 +++
 3 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/a9e54d34/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java
index 296b7d0..089ca2b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java
@@ -22,6 +22,8 @@ package org.apache.usergrid.corepersistence.service;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.index.SearchEdge;
 
+import java.util.Map;
+
 /**
  * Service to retrieve aggregations by application scope.
  */
@@ -35,6 +37,13 @@ public interface AggregationService {
      * @return
      */
     long sumAllCollections(ApplicationScope applicationScope);
+    /**
+     * get entity size for app
+     *
+     * @param applicationScope
+     * @return
+     */
+    Map<String,Long> sumEachCollection(ApplicationScope applicationScope);
 
     /**
      * get total entity size for an edge
@@ -44,4 +53,12 @@ public interface AggregationService {
      * @return
      */
     long sum(final ApplicationScope applicationScope, final SearchEdge edge);
+
+    /**
+     * get sum by collection name
+     * @param applicationScope
+     * @param collectionName
+     * @return
+     */
+    long getCollectionSum(final ApplicationScope applicationScope, final String collectionName);
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a9e54d34/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
index b8786d1..29b48d8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
@@ -39,7 +39,7 @@ import org.apache.usergrid.persistence.index.impl.SearchEdgeImpl;
 import org.apache.usergrid.utils.IndexUtils;
 import rx.observables.MathObservable;
 
-import java.util.Observable;
+import java.util.*;
 
 /**
  * Aggregation Service get counts for an application
@@ -83,9 +83,35 @@ public class AggregationServiceImpl implements AggregationService {
     }
 
     @Override
+    public Map<String, Long> sumEachCollection(ApplicationScope applicationScope) {
+        final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
+        EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy);
+        GraphManager graphManager = graphManagerFactory.createEdgeManager(applicationScope);
+        Map<String,Long> sumMap = ObservableTimer.time(
+                graphManager.getEdgeTypesFromSource(new SimpleSearchEdgeType(applicationScope.getApplication(), CpNamingUtils.EDGE_COLL_PREFIX, Optional.<String>absent()))
+                    .collect(() -> new HashMap<String,Long>(), ((map, type) ->
+                        {
+                            SearchEdge edge = CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), type);
+                            final String collectionName = CpNamingUtils.getCollectionNameFromEdgeName(type);
+                            long sumType =  entityIndex.getEntitySize(edge);
+                            map.put(collectionName,sumType);
+                        })
+                    )
+            , sumTimer).toBlocking().last();
+        return sumMap;
+
+    }
+
+    @Override
     public long sum(ApplicationScope applicationScope, SearchEdge edge) {
         final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
         EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy);
         return entityIndex.getEntitySize(edge);
     }
+
+    @Override
+    public long getCollectionSum(final ApplicationScope applicationScope, final String collectionName) {
+        return sum(applicationScope, CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), collectionName));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a9e54d34/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
index cc8adf1..d7d1ffa 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
@@ -71,5 +71,9 @@ public class AggregationServiceTest extends AbstractCoreIT {
         long sum3 = aggregationService.sum(applicationScope, CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), "tests"));
         Assert.assertEquals(sum3, entity1.getSize()+entity3.getSize());
 
+        Map<String,Long> sumEach = aggregationService.sumEachCollection(applicationScope);
+        Assert.assertTrue(sumEach.containsKey("tests") && sumEach.containsKey("test2s"));
+        Assert.assertEquals(sum3, (long)sumEach.get("tests"));
+
     }
 }