You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/06/02 17:07:28 UTC
[10/54] [abbrv] usergrid git commit: Additional tests to show how
connection queries work when some entities are not indexed.
Additional tests to show how connection queries work when some entities are not indexed.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/44d81fb5
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/44d81fb5
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/44d81fb5
Branch: refs/heads/apm
Commit: 44d81fb5b628677f71e54fb719a8996806be3fb2
Parents: fbced58
Author: Dave Johnson <sn...@apache.org>
Authored: Thu Apr 14 19:18:07 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Thu Apr 14 19:18:07 2016 -0400
----------------------------------------------------------------------
.../collection/CollectionsResourceIT.java | 113 ++++++++++++++++++-
1 file changed, 110 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/44d81fb5/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index b240629..35ee2f8 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -209,7 +209,8 @@ public class CollectionsResourceIT extends AbstractRestIT {
this.app().collection( "testCollections" ).collection( "_indexes" ).delete();
refreshIndex();
- this.app().collection( "testCollections" ).collection( "_reindex" ).post(true,clientSetup.getSuperuserToken(),ApiResponse.class,null,null,false);
+ this.app().collection( "testCollections" ).collection( "_reindex" )
+ .post(true,clientSetup.getSuperuserToken(),ApiResponse.class,null,null,false);
refreshIndex();
@@ -370,7 +371,8 @@ public class CollectionsResourceIT extends AbstractRestIT {
//Reindex and verify that the entity only has field one index.
- this.app().collection( "testCollection" ).collection( "_reindex" ).post(true,clientSetup.getSuperuserToken(),ApiResponse.class,null,null,false);
+ this.app().collection( "testCollection" ).collection( "_reindex" )
+ .post(true,clientSetup.getSuperuserToken(),ApiResponse.class,null,null,false);
for(int i = 0; i < 10; i++) {
String query = "one ='value"+ i + "'";
@@ -430,7 +432,8 @@ public class CollectionsResourceIT extends AbstractRestIT {
//Reindex and verify that the entity only has field one index.
- this.app().collection( "testCollection" ).collection( "_reindex" ).post(true,clientSetup.getSuperuserToken(),ApiResponse.class,null,null,false);
+ this.app().collection( "testCollection" ).collection( "_reindex" )
+ .post(true,clientSetup.getSuperuserToken(),ApiResponse.class,null,null,false);
indexingArray.add( "one" );
@@ -989,4 +992,108 @@ public class CollectionsResourceIT extends AbstractRestIT {
.get( new QueryParameters().setQuery( "select * where color='magenta'" ) ).iterator();
assertFalse( getByQuery.hasNext() );
}
+
+
+ /**
+ * Test that indexed entities can be connected to un-indexed Entities and connections still work.
+ */
+ @Test
+ public void testIndexedEntityToUnindexedEntityConnections() {
+
+ // create entities in an un-indexed collection
+
+ ArrayList<String> indexingArray = new ArrayList<>( );
+ indexingArray.add( "!" );
+ Entity payload = new Entity();
+ payload.put( "fields", indexingArray);
+
+ String randomizer = RandomStringUtils.randomAlphanumeric(10);
+ String unIndexedCollectionName = "col_" + randomizer;
+ app().collection( unIndexedCollectionName ).collection( "_indexes" ).post( payload );
+ refreshIndex();
+
+ String entityName1 = "unindexed1";
+ Entity unindexed1 = this.app().collection( unIndexedCollectionName )
+ .post( new Entity().withProp("name", entityName1).withProp( "color", "violet" ) );
+
+ String entityName2 = "unindexed2";
+ Entity unindexed2 = this.app().collection( unIndexedCollectionName )
+ .post( new Entity().withProp("name", entityName2).withProp( "color", "violet" ) );
+
+ // create an indexed entity
+
+ String indexedCollection = "col_" + randomizer;
+ String indexedEntityName = "indexedEntity";
+ Entity indexedEntity = this.app().collection( indexedCollection )
+ .post( new Entity().withProp("name", indexedEntityName).withProp( "color", "orange" ) );
+
+ // create connections from indexed entity to un-indexed entities
+
+ app().collection(indexedCollection).entity(indexedEntity).connection("likes").entity(unindexed1).post();
+ app().collection(indexedCollection).entity(indexedEntity).connection("likes").entity(unindexed2).post();
+
+ Collection connectionsByGraph = app().collection( indexedCollection )
+ .entity(indexedEntity).connection( "likes" ).get();
+ assertEquals( 2, connectionsByGraph.getNumOfEntities() );
+
+ Collection connectionsByQuery = app().collection( indexedCollection )
+ .entity(indexedEntity).connection( "likes" )
+ .get( new QueryParameters().setQuery( "select * where color='violet'" ));
+ assertEquals( 0, connectionsByQuery.getNumOfEntities() );
+
+ }
+
+
+ /**
+ * Test that index entities can be connected to un-indexed Entities and connections still work.
+ */
+ @Test
+ public void testUnindexedEntityToIndexedEntityConnections() {
+
+ // create two entities in an indexed collection
+
+ String randomizer = RandomStringUtils.randomAlphanumeric(10);
+ String indexedCollection = "col_" + randomizer;
+ String indexedEntityName = "indexedEntity";
+
+ Entity indexedEntity1 = this.app().collection( indexedCollection )
+ .post( new Entity().withProp("name", indexedEntityName + "_1").withProp( "color", "orange" ) );
+
+ Entity indexedEntity2 = this.app().collection( indexedCollection )
+ .post( new Entity().withProp("name", indexedEntityName + "_2").withProp( "color", "orange" ) );
+
+ // create an un-indexed entity
+
+ ArrayList<String> indexingArray = new ArrayList<>( );
+ indexingArray.add( "!" );
+ Entity payload = new Entity();
+ payload.put( "fields", indexingArray);
+
+ String unIndexedCollectionName = "col_" + randomizer;
+ app().collection( unIndexedCollectionName ).collection( "_indexes" ).post( payload );
+ refreshIndex();
+
+ String entityName1 = "unindexed1";
+ Entity unindexed1 = this.app().collection( unIndexedCollectionName )
+ .post( new Entity().withProp("name", entityName1).withProp( "color", "violet" ) );
+
+ // create connections from un-indexed entity to indexed entities
+
+ app().collection(unIndexedCollectionName).entity(unindexed1).connection("likes").entity(indexedEntity1).post();
+ app().collection(unIndexedCollectionName).entity(unindexed1).connection("likes").entity(indexedEntity2).post();
+
+ // should be able to get connections via graph from un-indexed to index
+
+ Collection connectionsByGraph = app().collection( indexedCollection )
+ .entity(unindexed1).connection( "likes" ).get();
+ assertEquals( 2, connectionsByGraph.getNumOfEntities() );
+
+ // should not be able to get connections via query from unindexed to indexed
+
+ Collection connectionsByQuery = app().collection( indexedCollection )
+ .entity(unindexed1).connection( "likes" )
+ .get( new QueryParameters().setQuery( "select * where color='orange'" ));
+ assertEquals( 0, connectionsByQuery.getNumOfEntities() );
+ }
+
}