usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [5/8] usergrid git commit: fixed tests so edges don't get left behind
Date Fri, 04 Sep 2015 13:42:05 GMT
fixed tests so edges don't get left behind


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

Branch: refs/heads/two-dot-o-dev
Commit: a691ada9b0ad825eb0578d579c8bf043376d33de
Parents: ba8922b
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Thu Sep 3 17:14:07 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Thu Sep 3 17:14:07 2015 -0600

----------------------------------------------------------------------
 .../service/ApplicationServiceImpl.java         | 74 +++++++++++++++++---
 .../org/apache/usergrid/persistence/Query.java  |  4 +-
 .../persistence/ApplicationServiceIT.java       | 48 +++++++++++--
 3 files changed, 110 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/a691ada9/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
index 07f7c13..2e4700a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
@@ -22,15 +22,26 @@ package org.apache.usergrid.corepersistence.service;
 import com.google.inject.Inject;
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
 import org.apache.usergrid.corepersistence.asyncevents.EventBuilder;
+import org.apache.usergrid.corepersistence.index.IndexService;
 import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.EntityRef;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
 import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.map.MapManager;
+import org.apache.usergrid.persistence.map.MapManagerFactory;
+import org.apache.usergrid.persistence.map.MapScope;
 import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
 import rx.Observable;
 
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createGraphOperationTimestamp;
+import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
+
 /**
  * implementation of application operations
  */
@@ -40,33 +51,80 @@ public class ApplicationServiceImpl  implements ApplicationService{
     private final EntityCollectionManagerFactory entityCollectionManagerFactory;
     private final AsyncEventService asyncEventService;
     private final EventBuilder eventBuilder;
+    private final MapManagerFactory mapManagerFactory;
+    private final GraphManagerFactory graphManagerFactory;
 
     @Inject
-    public ApplicationServiceImpl(AllEntityIdsObservable allEntityIdsObservable, EntityCollectionManagerFactory
entityCollectionManagerFactory, AsyncEventService asyncEventService, EventBuilder eventBuilder){
+    public ApplicationServiceImpl(AllEntityIdsObservable allEntityIdsObservable,
+                                  EntityCollectionManagerFactory entityCollectionManagerFactory,
+                                  AsyncEventService asyncEventService,
+                                  EventBuilder eventBuilder,
+                                  MapManagerFactory mapManagerFactory,
+                                  GraphManagerFactory graphManagerFactory
+    ){
 
         this.allEntityIdsObservable = allEntityIdsObservable;
         this.entityCollectionManagerFactory = entityCollectionManagerFactory;
         this.asyncEventService = asyncEventService;
         this.eventBuilder = eventBuilder;
+        this.mapManagerFactory = mapManagerFactory;
+        this.graphManagerFactory = graphManagerFactory;
     }
     @Override
     public Observable<Id> deleteAllEntities(ApplicationScope applicationScope) {
-        if(applicationScope.getApplication().getUuid().equals(CpNamingUtils.MANAGEMENT_APPLICATION_ID)){
+        if (applicationScope.getApplication().getUuid().equals(CpNamingUtils.MANAGEMENT_APPLICATION_ID))
{
             throw new IllegalArgumentException("Can't delete from management app");
         }
 
         //EventBuilder eventBuilder = injector.getInstance(EventBuilder.class);
-        Observable appObservable  = Observable.just(applicationScope);
+        Observable appObservable = Observable.just(applicationScope);
         EntityCollectionManager entityCollectionManager = entityCollectionManagerFactory.createCollectionManager(applicationScope);
-
+        GraphManager graphManager = graphManagerFactory.createEdgeManager(applicationScope);
+        MapManager mapManager = getMapManagerForTypes(applicationScope);
 
         Observable<Id> countObservable = allEntityIdsObservable.getEntities(appObservable)
             //.map(entity -> eventBuilder.buildEntityDelete(applicationScope, entity.getId()).getEntitiesCompacted())
             .map(entityIdScope -> ((EntityIdScope) entityIdScope).getId())
-            .doOnNext(id ->
-                    entityCollectionManager.mark((Id) id)
-                        .doOnNext(id2 -> asyncEventService.queueEntityDelete(applicationScope,
(Id) id2))
-            );
+            .skip(1)
+            .map(id -> {
+                    return entityCollectionManager.mark((Id) id)
+                        .mergeWith(graphManager.markNode((Id) id, createGraphOperationTimestamp()))
+                        .map(id2 -> id).toBlocking().last();
+                }
+            ).doOnNext(id -> deleteAsync(mapManager ,applicationScope, (Id) id));
+
+
         return countObservable;
     }
+
+    /**
+     * 4. Delete all entity documents out of elasticsearch.
+     * 5. Compact Graph so that it deletes the marked values.
+     * 6. Delete entity from cassandra using the map manager.
+     **/
+    private Id deleteAsync(MapManager mapManager, ApplicationScope applicationScope, Id entityId
)  {
+        try {
+            //Step 4 && 5
+            asyncEventService.queueEntityDelete(applicationScope, entityId);
+            //Step 6
+            //delete from our UUID index
+            mapManager.delete(entityId.getUuid().toString());
+            return entityId;
+        }catch (Exception e){
+            throw new RuntimeException(e);
+        }
+
+    }
+    /**
+     * Get the map manager for uuid mapping
+     */
+    private MapManager getMapManagerForTypes( ApplicationScope applicationScope) {
+        Id mapOwner = new SimpleId( applicationScope.getApplication().getUuid(), TYPE_APPLICATION
);
+
+        final MapScope ms = CpNamingUtils.getEntityTypeMapScope(mapOwner);
+
+        MapManager mm = mapManagerFactory.createMapManager(ms);
+
+        return mm;
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a691ada9/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
index 0074cc9..52e3b4e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
@@ -158,7 +158,9 @@ public class Query {
 
         return query;
     }
-
+    public static Query all( ){
+        return fromQL("select *");
+    }
 
     /**
      * Create a query from a property equals

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a691ada9/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
index 5274987..d438304 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
@@ -19,8 +19,20 @@
  */
 package org.apache.usergrid.persistence;
 
+import com.google.common.base.Optional;
+import com.google.inject.Injector;
 import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.cassandra.SpringResource;
+import org.apache.usergrid.corepersistence.service.AggregationService;
+import org.apache.usergrid.corepersistence.service.AggregationServiceFactory;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.graph.SearchByEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.junit.Assert;
 import org.junit.Test;
@@ -29,14 +41,16 @@ import org.slf4j.LoggerFactory;
 import rx.Observable;
 
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.UUID;
 
 /**
  * testy test
  */
 public class ApplicationServiceIT extends AbstractCoreIT {
-    private static final Logger LOG = LoggerFactory.getLogger(ApplicationServiceIT.class);
 
+    private static final Logger LOG = LoggerFactory.getLogger( ApplicationServiceIT.class
);
 
     public ApplicationServiceIT() {
         super();
@@ -46,16 +60,36 @@ public class ApplicationServiceIT extends AbstractCoreIT {
     public void testDeletes() throws Exception{
         EntityManager entityManager = this.app.getEntityManager();
         Map<String,Object> map = new HashMap<>();
-        Entity entity = entityManager.create("tests", map);
+        for(int i =0;i<10;i++) {
+            map.put("somekey", UUID.randomUUID());
+           Entity entity = entityManager.create("tests", map);
+        }
         this.app.refreshIndex();
         Thread.sleep(500);
+        ApplicationScope appScope  = CpNamingUtils.getApplicationScope(entityManager.getApplicationId());
         Observable<Id> ids =
-            this.app.getApplicationService().deleteAllEntities(CpNamingUtils.getApplicationScope(entityManager.getApplicationId()));
-        ids.toBlocking().last();
+            this.app.getApplicationService().deleteAllEntities(appScope);
+        int count = ids.count().toBlocking().last();
+        Assert.assertEquals(count, 13);
         this.app.refreshIndex();
-        Thread.sleep(500);
-        entity = entityManager.get(entity);
-        Assert.assertNull(entity);
+        Thread.sleep(5000);
+        Injector injector = SpringResource.getInstance().getBean(Injector.class);
+        GraphManagerFactory factory = injector.getInstance(GraphManagerFactory.class);
+        GraphManager graphManager = factory.createEdgeManager(appScope);
+        SimpleSearchByEdgeType simpleSearchByEdgeType = new SimpleSearchByEdgeType(
+            appScope.getApplication(),
+            CpNamingUtils.getEdgeTypeFromCollectionName("tests")
+            , Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING,
+            Optional.<Edge>absent() );
+
+        Iterator<Edge> results = graphManager.loadEdgesFromSource(simpleSearchByEdgeType).toBlocking().getIterator();
+        if(results.hasNext()){
+            Assert.fail();
+           
+        }else{
+
+            //success
+        }
     }
 
 }


Mime
View raw message