public void deleteJob(int jobId, boolean keepDatabase) { EcsSync sync = syncCache.get(jobId); if (sync == null) throw new JobNotFoundException("the specified job ID does not exist"); if (!getJobStatus(sync).isFinalState()) throw new UnsupportedOperationException("the job must be stopped before it can be deleted"); syncCache.remove(jobId); configCache.remove(jobId); // delete database if (sync.getDbService() != null) { if (!keepDatabase) sync.getDbService().deleteDatabase(); try { sync.getDbService().close(); } catch (IOException e) { log.warn("could not close database", e); } } }
@After public void stopRestServer() throws InterruptedException { if (restServer != null) restServer.stop(0); restServer = null; // wait for all jobs to stop to prevent leakage into other tests for (JobInfo jobInfo : SyncJobService.getInstance().getAllJobs().getJobs()) { while (!SyncJobService.getInstance().getJobControl(jobInfo.getJobId()).getStatus().isFinalState()) Thread.sleep(500); SyncJobService.getInstance().deleteJob(jobInfo.getJobId(), false); } }
@Test public void testGetJob() throws Exception { SyncConfig syncConfig = new SyncConfig(); syncConfig.setSource(new TestConfig().withObjectCount(10).withMaxSize(10240).withDiscardData(false)); syncConfig.setTarget(new TestConfig().withReadData(true).withDiscardData(false)); // create sync job ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobId = response.getHeaders().getFirst("x-emc-job-id"); try { Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); response.close(); // must close all responses // get job SyncConfig syncConfig2 = client.resource(endpoint).path("/job/" + jobId).get(SyncConfig.class); Assert.assertNotNull(syncConfig2); Assert.assertEquals(syncConfig, syncConfig2); // wait for job to complete while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); } } finally { // delete job response = client.resource(endpoint).path("/job/" + jobId).delete(ClientResponse.class); if (response.getStatus() != 200) log.warn("could not delete job: {}", response.getEntity(String.class)); response.close(); // must close all responses } }
while (!client.resource(endpoint).path("/job/" + jobId1 + "/control").get(JobControl.class).getStatus().isFinalState() && !client.resource(endpoint).path("/job/" + jobId2 + "/control").get(JobControl.class).getStatus().isFinalState() && !client.resource(endpoint).path("/job/" + jobId3 + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000);
@Test public void testCreateDelete() throws Exception { SyncConfig syncConfig = new SyncConfig(); syncConfig.setSource(new TestConfig().withObjectCount(10).withMaxSize(10240).withDiscardData(false)); syncConfig.setTarget(new TestConfig().withReadData(true).withDiscardData(false)); // create sync job ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobIdStr = response.getHeaders().getFirst("x-emc-job-id"); try { Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); response.close(); // must close all responses Assert.assertNotNull(jobIdStr); int jobId = Integer.parseInt(jobIdStr); // wait for job to complete while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); } // get status (should be complete) JobControl jobControl = client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class); Assert.assertNotNull(jobControl); Assert.assertEquals(JobControlStatus.Complete, jobControl.getStatus()); } finally { // delete job response = client.resource(endpoint).path("/job/" + jobIdStr).delete(ClientResponse.class); if (response.getStatus() != 200) log.warn("could not delete job: {}", response.getEntity(String.class)); response.close(); // must close all responses } }
while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000);
while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000);
while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000);