You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/09/29 22:00:36 UTC
[10/15] usergrid git commit: Wrote a test that creates 1000
connections but still needs to fail and verify how may connections we have.
Added a paging iterator for the connections that seems to be crashing
Wrote a test that creates 1000 connections but still needs to fail and verify how may connections we have.
Added a paging iterator for the connections that seems to be crashing
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/6650a203
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/6650a203
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/6650a203
Branch: refs/heads/export-feature
Commit: 6650a20382351dc2bcd8ec3f33db177995450491
Parents: 0c7203a
Author: GERey <gr...@apigee.com>
Authored: Wed Sep 23 10:38:10 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Wed Sep 23 10:38:10 2015 -0700
----------------------------------------------------------------------
.../management/export/ExportServiceImpl.java | 21 +++++--
.../management/export/MockExportServiceIT.java | 60 ++++++--------------
2 files changed, 32 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6650a203/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
index da94d1c..31ea556 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
@@ -34,6 +34,7 @@ import org.apache.usergrid.batch.JobExecution;
import org.apache.usergrid.batch.service.SchedulerService;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.ManagementService;
+import org.apache.usergrid.persistence.ConnectedEntityRef;
import org.apache.usergrid.persistence.ConnectionRef;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManager;
@@ -558,14 +559,22 @@ public class ExportServiceImpl implements ExportService {
jg.writeFieldName( connectionType );
jg.writeStartArray();
- Results results = em.getTargetEntities( entity,connectionType, null, Level.IDS );
-
- List<ConnectionRef> connections = results.getConnections();
-
- for ( ConnectionRef connectionRef : connections ) {
- jg.writeObject( connectionRef.getTargetRefs().getUuid() );
+ Results results = em.getTargetEntities( entity,connectionType, null, Level.ALL_PROPERTIES );
+ PagingResultsIterator connectionResults = new PagingResultsIterator( results );
+ int count = 0;
+ for(Object c : connectionResults){
+ ConnectedEntityRef connectionRef = (ConnectedEntityRef) c;
+ jg.writeObject( connectionRef.getUuid());
+ System.out.println("Currently on "+count++);
}
+// List<ConnectionRef> connections = results.getConnections();
+//
+//
+// for ( ConnectionRef connectionRef : connectionResults. ) {
+// jg.writeObject( connectionRef.getTargetRefs().getUuid() );
+// }
+
jg.writeEndArray();
}
jg.writeEndObject();
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6650a203/stack/services/src/test/java/org/apache/usergrid/management/export/MockExportServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/export/MockExportServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/export/MockExportServiceIT.java
index 68f453c..76ced98 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/export/MockExportServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/export/MockExportServiceIT.java
@@ -387,7 +387,7 @@ public class MockExportServiceIT extends AbstractServiceIT {
@Test //Connections won't save when run with maven, but on local builds it will.
- public void test2001EntitiesOnApplicationEndpoint() throws Exception {
+ public void test1000ConnectionsToSingleEntity() throws Exception {
String testFileName ="testConnectionsOnApplicationEndpoint.json";
@@ -406,7 +406,7 @@ public class MockExportServiceIT extends AbstractServiceIT {
// intialize user object to be posted
Map<String, Object> userProperties = null;
Entity[] entity;
- int numberOfEntitiesToBeWritten = 999;
+ int numberOfEntitiesToBeWritten = 997;
entity = new Entity[numberOfEntitiesToBeWritten];
// creates entities
@@ -417,6 +417,11 @@ public class MockExportServiceIT extends AbstractServiceIT {
entity[i] = em.create( "users", userProperties );
}
+ for(int i = 1; i<numberOfEntitiesToBeWritten; i++){
+ em.createConnection( em.get( new SimpleEntityRef( "user", entity[0].getUuid() ) ), "testConnections",
+ em.get( new SimpleEntityRef( "user", entity[i].getUuid() ) ) );
+ }
+
setup.getEntityIndex().refresh( applicationId );
Thread.sleep( 1000 );
@@ -443,6 +448,9 @@ public class MockExportServiceIT extends AbstractServiceIT {
Iterator jsonIterator = mapper.readValues( jp, typeRef);
while(jsonIterator.hasNext()){
Object jsonEntity = jsonIterator.next();
+ //Instead we could probably make a hashmap of the uuid of the entities then delete out of the map
+ //as we find it thus ensuring we have a. nothing in the hashmap ( meaning all entities found )
+ //and b. no other entities that we wouldn't expect ( exception is made for roles which are default )
assertNotNull( ( ( HashMap ) jsonEntity ).get( "uuid" ));
validEntitiesCounter++;
}
@@ -453,47 +461,13 @@ public class MockExportServiceIT extends AbstractServiceIT {
}
//need to add three to all verifies because of the three default roles.
- assertEquals( "There should have been "+(numberOfEntitiesToBeWritten+3)+" valid entities in the file",numberOfEntitiesToBeWritten+3,validEntitiesCounter );
-
- //Read the connection entities and verify that they are correct
+ assertEquals( "There should have been 1000 valid entities in the file",1000,validEntitiesCounter );
-// int validConnectionCounter = 0;
-// final InputStream connectionsInputStream = new FileInputStream( "connections1"+testFileName );
-// try{
-// ObjectMapper mapper = new ObjectMapper();
-// JsonParser jp = new JsonFactory( ).createParser( connectionsInputStream );
-//
-// Iterator jsonIterator = mapper.readValues( jp, typeRef);
-// while(jsonIterator.hasNext()){
-// Object jsonConnection = jsonIterator.next();
-// if(( ( HashMap ) jsonConnection ).get( entity[1].getUuid().toString() )!=null){
-// Object jsonEntityConnection = ( ( HashMap ) jsonConnection ).get( entity[1].getUuid().toString() );
-// assertNotNull( ( ( HashMap ) jsonEntityConnection ).get( "vibrations" ) );
-//
-// //String is stored in an array so we need to trim array fixings off the end of the string to compare.
-// String connectionUuid = ( ( HashMap ) jsonEntityConnection ).get( "vibrations" ).toString();
-// connectionUuid=connectionUuid.substring( 1,connectionUuid.length()-1 );
-// if(connectionUuid.equals( entity[0].getUuid().toString() ))
-// validConnectionCounter++;
-// }
-// else if(( ( HashMap ) jsonConnection ).get( entity[0].getUuid().toString() )!=null){
-// Object jsonEntityConnection = ( ( HashMap ) jsonConnection ).get( entity[0].getUuid().toString());
-// assertNotNull( ( ( HashMap ) jsonEntityConnection ).get( "vibrations" ) );
-//
-// String connectionUuid = ( ( HashMap ) jsonEntityConnection ).get( "vibrations" ).toString();
-// connectionUuid=connectionUuid.substring( 1,connectionUuid.length()-1 );
-//
-// if(connectionUuid.equals( entity[1].getUuid().toString() ))
-// validConnectionCounter++;
-// }
-// }
-// }finally{
-// in.close();
- File exportedFile = new File("connections1"+testFileName);
- exportedFile.delete();
-// }
-//
-// assertEquals( "There should have been two valid connections in the file",2,validConnectionCounter );
+ //Delete the created connection files
+// File exportedFile = new File("connections1"+testFileName);
+// exportedFile.delete();
+// exportedFile = new File("connections2"+testFileName);
+// exportedFile.delete();
}
@Test //Connections won't save when run with maven, but on local builds it will.
@@ -516,7 +490,7 @@ public class MockExportServiceIT extends AbstractServiceIT {
// intialize user object to be posted
Map<String, Object> userProperties = null;
Entity[] entity;
- int numberOfEntitiesToBeWritten = 1100;
+ int numberOfEntitiesToBeWritten = 1000;
entity = new Entity[numberOfEntitiesToBeWritten];
// creates entities