You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/03/30 21:58:32 UTC

[28/50] incubator-usergrid git commit: Fixing EMF getApplications() and the all-apps observable to use the app ID and not the application_info ID, plus some section comments in related tests.

Fixing EMF getApplications() and the all-apps observable to use the app ID and not the application_info ID, plus some section comments in related tests.


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

Branch: refs/heads/two-dot-o-dev
Commit: 7d7c54b9fab1fe322f5960f97dee979a5e8f9001
Parents: 9f3bb94
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 17 09:32:54 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 17 09:32:54 2015 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  9 ++--
 .../rx/impl/AllApplicationsObservableImpl.java  |  6 ++-
 .../rx/AllEntitiesInSystemObservableIT.java     | 44 ++++++++++----------
 .../PerformanceEntityRebuildIndexTest.java      | 12 ++----
 4 files changed, 38 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 010672e..efae477 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -449,16 +449,19 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                 appScope.getApplication(),
                 scopeName);
 
-            org.apache.usergrid.persistence.model.entity.Entity e =
+            org.apache.usergrid.persistence.model.entity.Entity appInfo =
                     managerCache.getEntityCollectionManager( collScope ).load( targetId )
                         .toBlockingObservable().lastOrDefault(null);
 
-            if ( e == null ) {
+            if ( appInfo == null ) {
                 logger.warn("Application {} in index but not found in collections", targetId );
                 continue;
             }
 
-            appMap.put( (String)e.getField( PROPERTY_NAME ).getValue(), e.getId().getUuid());
+            UUID applicationId = UUIDUtils.tryExtractUUID(
+                appInfo.getField( PROPERTY_APPLICATION_ID ).getValue().toString() );
+
+            appMap.put( (String)appInfo.getField( PROPERTY_NAME ).getValue(), applicationId);
         }
 
         return appMap;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
index 7f2b27d..8dbea19 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
@@ -23,6 +23,8 @@ package org.apache.usergrid.corepersistence.rx.impl;
 import java.util.Arrays;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -100,6 +102,7 @@ public class AllApplicationsObservableImpl implements AllApplicationsObservable
                         null ) ).flatMap( new Func1<Edge, Observable<ApplicationScope>>() {
             @Override
             public Observable<ApplicationScope> call( final Edge edge ) {
+
                 //get the app info and load it
                 final Id appInfo = edge.getTargetNode();
 
@@ -121,7 +124,8 @@ public class AllApplicationsObservableImpl implements AllApplicationsObservable
 
                         @Override
                         public ApplicationScope call( final Entity entity ) {
-                            final UUID uuid = entity.getId().getUuid();
+                            final UUID uuid = UUIDUtils.tryExtractUUID(
+                                entity.getField( Schema.PROPERTY_APPLICATION_ID ).getValue().toString());
                             return getApplicationScope( uuid );
                         }
                     } );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
index 7a6ec22..b2b8aaf 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
@@ -55,12 +55,16 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
 
     @Test
     public void testEntities() throws Exception {
+
         Injector injector =  SpringResource.getInstance().getBean(Injector.class);
-        AllEntitiesInSystemImpl allEntitiesInSystemObservableImpl =injector.getInstance(AllEntitiesInSystemImpl.class);
+        AllEntitiesInSystemImpl allEntitiesInSystemObservableImpl =
+            injector.getInstance(AllEntitiesInSystemImpl.class);
         TargetIdObservable targetIdObservable = injector.getInstance(TargetIdObservable.class);
 
         final EntityManager em = app.getEntityManager();
 
+        // create two types of entities
+
         final String type1 = "type1thing";
         final String type2 = "type2thing";
         final int size = 10;
@@ -68,9 +72,9 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
         final Set<Id> type1Identities = EntityWriteHelper.createTypes( em, type1, size );
         final Set<Id> type2Identities = EntityWriteHelper.createTypes( em, type2, size );
 
-        //create a connection and put that in our connection types
-        final Id source = type1Identities.iterator().next();
+        // connect the first type1 entity to all type2 entities
 
+        final Id source = type1Identities.iterator().next();
 
         final Set<Id> allEntities = new HashSet<>();
         allEntities.addAll( type1Identities );
@@ -79,20 +83,17 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
         final Set<Id> connections = new HashSet<>();
 
         for ( Id target : type2Identities ) {
-            em.createConnection( SimpleEntityRef.fromId( source ), "likes", SimpleEntityRef.fromId( target ) );
+            em.createConnection( SimpleEntityRef.fromId( source ),
+                "likes", SimpleEntityRef.fromId( target ) );
             connections.add( target );
         }
 
+        // use the all-entities-in-system observable to delete all type1 and type2 entities
 
-        //this is hacky, but our context integration b/t guice and spring is a mess.  We need to clean this up when we
-        //clean up our wiring
-        //
-        ManagerCache managerCache =  SpringResource.getInstance().getBean( Injector.class ).getInstance( ManagerCache.class );
-
-
+        // TODO: clean this up when we clean up our Guice and Spring wiring
+        ManagerCache managerCache =  SpringResource.getInstance()
+            .getBean( Injector.class ).getInstance( ManagerCache.class );
         final ApplicationScope scope = CpNamingUtils.getApplicationScope( app.getId() );
-
-
         final GraphManager gm = managerCache.getGraphManager( scope );
 
         allEntitiesInSystemObservableImpl.getData().doOnNext( new Action1<EntityIdScope>() {
@@ -102,22 +103,23 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
                 assertNotNull(entityIdScope.getCollectionScope());
                 assertNotNull(entityIdScope.getId());
 
-                    //we should only emit each node once
-                    if ( entityIdScope.getId().getType().equals( type1 ) ) {
-                        assertTrue( "Element should be present on removal", type1Identities.remove(entityIdScope.getId() ) );
-                    }
-                    else if ( entityIdScope.getId().getType().equals( type2 ) ) {
-                        assertTrue( "Element should be present on removal", type2Identities.remove(entityIdScope.getId() ) );
-                    }
-
+                // we should only emit each node once
+                if ( entityIdScope.getId().getType().equals( type1 ) ) {
+                    assertTrue( "Element should be present on removal",
+                        type1Identities.remove(entityIdScope.getId() ) );
+                }
+                else if ( entityIdScope.getId().getType().equals( type2 ) ) {
+                    assertTrue( "Element should be present on removal",
+                        type2Identities.remove(entityIdScope.getId() ) );
+                }
             }
         } ).toBlocking().lastOrDefault( null );
 
+        // there should now be no type1 or type2 entities
 
         assertEquals( "Every element should have been encountered", 0, type1Identities.size() );
         assertEquals( "Every element should have been encountered", 0, type2Identities.size() );
 
-
         //test connections
 
         targetIdObservable.getTargetNodes( gm, source ).doOnNext( new Action1<Id>() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index def9ed5..48191bf 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -174,8 +174,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
 
         // ----------------- delete the system and application indexes
 
-        logger.debug("Deleting app index index");
-        //deleteIndex( CpNamingUtils.SYSTEM_APP_ID );
+        logger.debug("Deleting apps");
         deleteIndex( em.getApplicationId() );
 
         // ----------------- test that we can read them, should fail
@@ -311,13 +310,10 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
 
         // ----------------- delete the system and application indexes
 
-        logger.debug("Deleting app index and system app index");
+        logger.debug("Deleting app index");
 
         deleteIndex( em.getApplicationId() );
 
-        // deleting sytem app index will interfere with other concurrently running tests
-        //deleteIndex( CpNamingUtils.SYSTEM_APP_ID );
-
 
         // ----------------- test that we can read them, should fail
 
@@ -373,14 +369,14 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
     }
 
     /**
-     * Delete index for all applications, just need the one to get started.
+     * Delete app index
      */
     private void deleteIndex( UUID appUuid ) {
 
         Injector injector = SpringResource.getInstance().getBean( Injector.class );
         EntityIndexFactory eif = injector.getInstance( EntityIndexFactory.class );
 
-        Id appId = new SimpleId( appUuid, "application");
+        Id appId = new SimpleId( appUuid, Schema.TYPE_APPLICATION );
         ApplicationScope scope = new ApplicationScopeImpl( appId );
         EntityIndex ei = eif.createEntityIndex(scope);
         EsEntityIndexImpl eeii = (EsEntityIndexImpl)ei;