Added additional error checking for Export Service. Revised test to contain smaller entities written for test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c17cf346 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c17cf346 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c17cf346 Branch: refs/heads/master Commit: c17cf34635f6103798afcd397d10942b282421fd Parents: 027a754 Author: grey <[email protected]> Authored: Sun Mar 2 10:21:15 2014 -0800 Committer: grey <[email protected]> Committed: Sun Mar 2 10:21:15 2014 -0800 ---------------------------------------------------------------------- .../management/export/ExportServiceImpl.java | 28 ++++++++++++++++++-- .../cassandra/ManagementServiceIT.java | 10 +++---- 2 files changed, 31 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c17cf346/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 7f28bc7..649c197 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 @@ -60,7 +60,7 @@ public class ExportServiceImpl implements ExportService { private ManagementService managementService; //Maximum amount of entities retrieved in a single go. - public static final int MAX_ENTITY_FETCH = 100; + public static final int MAX_ENTITY_FETCH = 100000; //Amount of time that has passed before sending another heart beat in millis public static final int TIMESTAMP_DELTA = 5000; @@ -133,13 +133,24 @@ public class ExportServiceImpl implements ExportService { public String getState( final UUID appId, final UUID uuid ) throws Exception { //get application entity manager + if(appId == null) { + logger.error( "Application context cannot be found." ); + return "Application context cannot be found."; + } + + if(uuid == null) { + logger.error( "UUID passed in cannot be null." ); + return "UUID passed in cannot be null"; + } + EntityManager rootEm = emf.getEntityManager( appId ); //retrieve the export entity. Export export = rootEm.get( uuid, Export.class ); if ( export == null ) { - return null; + logger.error( "no entity with that uuid was found" ); + return "No Such Element found"; } return export.getState().toString(); } @@ -148,8 +159,16 @@ public class ExportServiceImpl implements ExportService { @Override public void doExport( final ExportInfo config, final JobExecution jobExecution ) throws Exception { + if (config == null) { + logger.error( "Export Information passed through is null" ); + return; + } //get the entity manager for the application, and the entity that this Export corresponds to. UUID exportId = ( UUID ) jobExecution.getJobData().getProperty( EXPORT_ID ); + if(config.getApplicationId() == null) { + logger.error( "Export Information application uuid is null" ); + return; + } EntityManager em = emf.getEntityManager( config.getApplicationId() ); Export export = em.get( exportId, Export.class ); @@ -160,6 +179,10 @@ public class ExportServiceImpl implements ExportService { if ( config.getCollection() == null ) { //exports all the applications for a given organization. Map<UUID, String> organizations = getOrgs(); + if(organizations == null){ + logger.error( "No organizations could be found" ); + return; + } for ( Map.Entry<UUID, String> organization : organizations.entrySet() ) { try { exportApplicationsForOrg( organization, config, jobExecution ); @@ -208,6 +231,7 @@ public class ExportServiceImpl implements ExportService { if ( info == null ) { logger.error( "Organization info is null!" ); + return null; } organizationNames = new HashMap<UUID, String>(); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c17cf346/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 990c26b..2ea5513 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 @@ -746,7 +746,7 @@ public class ManagementServiceIT { //Tests to make sure we can call the job with mock data and it runs. - @Ignore //Connections won't save when run with maven, but on local builds it will. + @Test //Connections won't save when run with maven, but on local builds it will. public void testFileConnections() throws Exception { File f = null; @@ -754,7 +754,7 @@ public class ManagementServiceIT { try { f = new File( "testFileConnections.json" ); - //f.delete(); + 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. @@ -776,9 +776,9 @@ public class ManagementServiceIT { //intialize user object to be posted Map<String, Object> userProperties = null; Entity[] entity; - entity = new Entity[10]; + entity = new Entity[2]; //creates entities - for ( int i = 0; i < 10; i++ ) { + 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( "[email protected]", i ) ); @@ -806,7 +806,7 @@ public class ManagementServiceIT { JSONParser parser = new JSONParser(); org.json.simple.JSONArray a = ( org.json.simple.JSONArray ) parser.parse( new FileReader( f ) ); - //assertEquals(13, a.size() ); + assertEquals(2, a.size() ); org.json.simple.JSONObject objEnt = ( org.json.simple.JSONObject ) a.get( 0 ); org.json.simple.JSONObject objConnections = ( org.json.simple.JSONObject ) objEnt.get( "connections" );
