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 2014/03/10 17:21:17 UTC
[08/50] [abbrv] git commit: Fixed complete application backup. Added
test cases for application backups.
Fixed complete application backup.
Added test cases for application backups.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c899c3db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c899c3db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c899c3db
Branch: refs/heads/master
Commit: c899c3dbd78da6fafa14726543e563d989ae6aa5
Parents: c17cf34
Author: grey <gr...@apigee.com>
Authored: Sun Mar 2 13:53:44 2014 -0800
Committer: grey <gr...@apigee.com>
Committed: Sun Mar 2 13:53:44 2014 -0800
----------------------------------------------------------------------
.../management/export/ExportServiceImpl.java | 6 +-
.../cassandra/ManagementServiceIT.java | 216 +++++++++++++++++--
2 files changed, 202 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c899c3db/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 649c197..e2e08fc 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
@@ -312,8 +312,12 @@ public class ExportServiceImpl implements ExportService {
// through the entities in the application (former namespace).
//could support queries, just need to implement that in the rest endpoint.
for ( String collectionName : metadata.keySet() ) {
+ if(collectionName.equals( "exports" )) {
+ continue;
+ }
//if the collection you are looping through doesn't match the name of the one you want. Don't export it.
- if ( collectionName.equals( config.getCollection() ) ) {
+
+ if ( (config.getCollection() == null)||collectionName.equals( config.getCollection() ) ) {
//Query entity manager for the entities in a collection
Query query = new Query();
query.setLimit( MAX_ENTITY_FETCH );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c899c3db/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
index 2ea5513..fce3147 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
@@ -747,7 +747,7 @@ public class ManagementServiceIT {
//Tests to make sure we can call the job with mock data and it runs.
@Test //Connections won't save when run with maven, but on local builds it will.
- public void testFileConnections() throws Exception {
+ public void testConnectionsOnCollectionExport() throws Exception {
File f = null;
@@ -820,9 +820,81 @@ public class ManagementServiceIT {
f.delete();
}
+ @Test //Connections won't save when run with maven, but on local builds it will.
+ public void testConnectionsOnApplicationEndpoint() throws Exception {
+
+ File f = null;
+
+
+ try {
+ f = new File( "testConnectionsOnApplicationEndpoint.json" );
+ f.delete();
+ }
+ catch ( Exception e ) {
+ //consumed because this checks to see if the file exists. If it doesn't then don't do anything and carry on.
+ }
+
+
+ S3Export s3Export = new MockS3ExportImpl();
+ s3Export.setFilename( "testConnectionsOnApplicationEndpoint.json" );
+
+ ExportService exportService = setup.getExportService();
+ HashMap<String, Object> payload = payloadBuilder();
+
+ ExportInfo exportInfo = new ExportInfo( payload );
+ exportInfo.setOrganizationId( organization.getUuid() );
+ exportInfo.setApplicationId( applicationId );
+
+ EntityManager em = setup.getEmf().getEntityManager( applicationId );
+ //intialize user object to be posted
+ Map<String, Object> userProperties = null;
+ Entity[] entity;
+ entity = new Entity[2];
+ //creates entities
+ for ( int i = 0; i < 2; i++ ) {
+ userProperties = new LinkedHashMap<String, Object>();
+ userProperties.put( "username", "billybob" + i );
+ userProperties.put( "email", "test" + i + "@anuff.com" );//String.format( "test%i@anuff.com", i ) );
+
+ entity[i] = em.create( "users", userProperties );
+ }
+ //creates connections
+ em.createConnection( em.getRef( entity[0].getUuid() ), "Vibrations", em.getRef( entity[1].getUuid() ) );
+ em.createConnection( em.getRef( entity[1].getUuid() ), "Vibrations", em.getRef( entity[0].getUuid() ) );
+
+ UUID exportUUID = exportService.schedule( exportInfo );
+ exportService.setS3Export( s3Export );
+
+ //create and initialize jobData returned in JobExecution.
+ JobData jobData = new JobData();
+ jobData.setProperty( "jobName", "exportJob" );
+ jobData.setProperty( "exportInfo", exportInfo );
+ jobData.setProperty( "exportId", exportUUID );
+ JobExecution jobExecution = mock( JobExecution.class );
+ when( jobExecution.getJobData() ).thenReturn( jobData );
+
+ exportService.doExport( exportInfo, jobExecution );
+
+ JSONParser parser = new JSONParser();
+
+ org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) );
+
+ org.json.simple.JSONObject objEnt = ( org.json.simple.JSONObject ) a.get( 0 );
+ org.json.simple.JSONObject objConnections = ( org.json.simple.JSONObject ) objEnt.get( "connections" );
+
+ assertNotNull( objConnections );
+
+ org.json.simple.JSONArray objVibrations = ( org.json.simple.JSONArray ) objConnections.get( "Vibrations" );
+
+ assertNotNull( objVibrations );
+
+ f.delete();
+ }
+
+//need to add tests for the other endpoint as well.
@Test
- public void testFileValidity() throws Exception {
+ public void testValidityOfCollectionExport() throws Exception {
File f = null;
@@ -870,7 +942,54 @@ public class ManagementServiceIT {
}
@Test
- public void testFileExportOneOrg() throws Exception {
+ public void testValidityOfApplicationExport() throws Exception {
+
+ File f = null;
+
+ try {
+ f = new File( "testValidityOfApplicationExport.json" );
+ f.delete();
+ }
+ catch ( Exception e ) {
+ //consumed because this checks to see if the file exists. If it doesn't then don't do anything and carry on.
+ }
+
+ S3Export s3Export = new MockS3ExportImpl();
+ s3Export.setFilename( "testValidityOfApplicationExport.json" );
+ ExportService exportService = setup.getExportService();
+ HashMap<String, Object> payload = payloadBuilder();
+
+ ExportInfo exportInfo = new ExportInfo( payload );
+ exportInfo.setOrganizationId( organization.getUuid() );
+ exportInfo.setApplicationId( applicationId );
+
+ UUID exportUUID = exportService.schedule( exportInfo );
+ exportService.setS3Export( s3Export );
+
+ JobData jobData = new JobData();
+ jobData.setProperty( "jobName", "exportJob" );
+ jobData.setProperty( "exportInfo", exportInfo );
+ jobData.setProperty( "exportId", exportUUID );
+
+ JobExecution jobExecution = mock( JobExecution.class );
+ when( jobExecution.getJobData() ).thenReturn( jobData );
+
+ exportService.doExport( exportInfo, jobExecution );
+
+ JSONParser parser = new JSONParser();
+
+ org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) );
+
+ for ( int i = 0; i < a.size(); i++ ) {
+ org.json.simple.JSONObject entity = ( org.json.simple.JSONObject ) a.get( i );
+ org.json.simple.JSONObject entityData = ( JSONObject ) entity.get( "Metadata" );
+ assertNotNull( entityData );
+ }
+ f.delete();
+ }
+
+ @Test
+ public void testExportOneOrgCollectionEndpoint() throws Exception {
File f = null;
@@ -926,7 +1045,7 @@ public class ManagementServiceIT {
@Test
- public void testFileExportOneApp() throws Exception {
+ public void testExportOneAppOnCollectionEndpoint() throws Exception {
File f = null;
String orgName = "ed-organization";
@@ -947,11 +1066,11 @@ public class ManagementServiceIT {
//intialize user object to be posted
Map<String, Object> userProperties = null;
Entity[] entity;
- entity = new Entity[10];
+ entity = new Entity[1];
//creates entities
- for ( int i = 0; i < 10; i++ ) {
+ for ( int i = 0; i < 1; i++ ) {
userProperties = new LinkedHashMap<String, Object>();
- userProperties.put( "username", "billybob" + i );
+ userProperties.put( "username", "junkRealName");
userProperties.put( "email", "test" + i + "@anuff.com" );//String.format( "test%i@anuff.com", i ) );
entity[i] = em.create( "user", userProperties );
}
@@ -964,7 +1083,7 @@ public class ManagementServiceIT {
ExportInfo exportInfo = new ExportInfo( payload );
exportInfo.setOrganizationId( organization.getUuid() );
exportInfo.setApplicationId( applicationId );
- exportInfo.setCollection( "roles" );
+ exportInfo.setCollection( "roles" ); // <- this line determines if it is a collection back up or a application backup.
UUID exportUUID = exportService.schedule( exportInfo );
exportService.setS3Export( s3Export );
@@ -989,13 +1108,79 @@ public class ManagementServiceIT {
org.json.simple.JSONObject entityData = ( JSONObject ) data.get( "Metadata" );
String entityName = ( String ) entityData.get( "name" );
assertFalse( "junkRealName".equals( entityName ) );
- //assertNotEquals( "NotEquals","junkRealName",entityName );
}
f.delete();
}
@Test
- public void testFileExportOneCollection() throws Exception {
+ public void testExportOneAppOnApplicationEndpoint() throws Exception {
+
+ File f = null;
+ String orgName = "ed-organization";
+ String appName = "testAppNotExported";
+
+ try {
+ f = new File( "exportOneApp.json" );
+ f.delete();
+ }
+ catch ( Exception e ) {
+ //consumed because this checks to see if the file exists. If it doesn't, don't do anything and carry on.
+ }
+
+ UUID appId = setup.getEmf().createApplication( orgName, appName );
+
+
+ EntityManager em = setup.getEmf().getEntityManager( appId );
+ //intialize user object to be posted
+ Map<String, Object> userProperties = null;
+ Entity[] entity;
+ entity = new Entity[1];
+ //creates entities
+ for ( int i = 0; i < 1; i++ ) {
+ userProperties = new LinkedHashMap<String, Object>();
+ userProperties.put( "username", "junkRealName");
+ userProperties.put( "email", "test" + i + "@anuff.com" );//String.format( "test%i@anuff.com", i ) );
+ entity[i] = em.create( "users", userProperties );
+ }
+
+ S3Export s3Export = new MockS3ExportImpl();
+ s3Export.setFilename( "exportOneApp.json" );
+ ExportService exportService = setup.getExportService();
+ HashMap<String, Object> payload = payloadBuilder();
+
+ ExportInfo exportInfo = new ExportInfo( payload );
+ exportInfo.setOrganizationId( organization.getUuid() );
+ exportInfo.setApplicationId( applicationId );
+
+ UUID exportUUID = exportService.schedule( exportInfo );
+ exportService.setS3Export( s3Export );
+
+ JobData jobData = new JobData();
+ jobData.setProperty( "jobName", "exportJob" );
+ jobData.setProperty( "exportInfo", exportInfo );
+ jobData.setProperty( "exportId", exportUUID );
+
+ JobExecution jobExecution = mock( JobExecution.class );
+ when( jobExecution.getJobData() ).thenReturn( jobData );
+
+ exportService.doExport( exportInfo, jobExecution );
+
+ JSONParser parser = new JSONParser();
+
+ org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) );
+
+ //assertEquals( 3 , a.size() );
+ for ( int i = 0; i < a.size(); i++ ) {
+ org.json.simple.JSONObject data = ( org.json.simple.JSONObject ) a.get( i );
+ org.json.simple.JSONObject entityData = ( JSONObject ) data.get( "Metadata" );
+ String entityName = ( String ) entityData.get( "name" );
+ assertFalse( "junkRealName".equals( entityName ) );
+ }
+ f.delete();
+ }
+
+ @Test
+ public void testExportOneCollection() throws Exception {
File f = null;
@@ -1049,13 +1234,6 @@ public class ManagementServiceIT {
org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) );
assertEquals( 10 , a.size() );
- for ( int i = 0; i < a.size(); i++ ) {
- org.json.simple.JSONObject data = ( org.json.simple.JSONObject ) a.get( i );
- org.json.simple.JSONObject entityData = ( JSONObject ) data.get( "Metadata" );
- String entityName = ( String ) entityData.get( "name" );
- assertFalse( "junkRealName".equals( entityName ) );
- //assertNotEquals( "NotEquals","junkRealName",entityName );
- }
f.delete();
}
@@ -1092,7 +1270,7 @@ public class ManagementServiceIT {
}
@Test
- public void testExportDoExport() throws Exception {
+ public void testExportDoExportOnApplicationEndpoint() throws Exception {
EntityManagerFactory emf = setup.getEmf();
EntityManager em = emf.getEntityManager( applicationId );
@@ -1180,7 +1358,7 @@ public class ManagementServiceIT {
@Ignore //For this test please input your s3 credentials into payload builder.
- public void testIntegration100Entities() throws Exception {
+ public void testIntegration100EntitiesOn() throws Exception {
S3Export s3Export = new S3ExportImpl();
ExportService exportService = setup.getExportService();