// be undeployed and deleted.
// job4 - Created, not deployed, not locked. Simulates an old job no longer in use, which
// should be deleted.
// job1 - create and deploy
final JobId jobId1 = createJob(testJobName + "_1", testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId1, testHost1);
// job2 - create
final JobId jobId2 = createJob(testJobName + "_2", testJobVersion, BUSYBOX, IDLE_COMMAND);
// job3 - create and deploy
final JobId jobId3 = createJob(testJobName + "_3", testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId3, testHost1);
// job4 - create
final JobId jobId4 = createJob(testJobName + "_4", testJobVersion, BUSYBOX, IDLE_COMMAND);
try (
// Create prefix files for all four jobs. They will be locked by default.
JobPrefixFile file1 = JobPrefixFile.create(jobId1.getName(), prefixDirectory);
JobPrefixFile file2 = JobPrefixFile.create(jobId2.getName(), prefixDirectory);
JobPrefixFile file3 = JobPrefixFile.create(jobId3.getName(), prefixDirectory);
JobPrefixFile file4 = JobPrefixFile.create(jobId4.getName(), prefixDirectory)
) {
// Release the locks of jobs 3 and 4 so they can be cleaned up
file3.release();
file4.release();
assertThat(testResult(JobNamePrefixTestImpl.class), isSuccessful());
final Map<JobId, Job> jobs = client.jobs().get();
// Verify job1 is still deployed and the prefix file has not been deleted.
assertThat(jobs, hasKey(jobId1));
final JobStatus status1 = client.jobStatus(jobId1).get();
assertThat(status1.getDeployments().size(), is(1));
assertTrue(fileExists(prefixDirectory, jobId1.getName()));
// Verify job2 still exists, is not deployed, and the prefix file is still there.
assertThat(jobs, hasKey(jobId2));
final JobStatus status2 = client.jobStatus(jobId2).get();
assertThat(status2.getDeployments().size(), is(0));
assertTrue(fileExists(prefixDirectory, jobId2.getName()));
// Verify that job3 has been deleted (which means it has also been undeployed), and
// the prefix file has been deleted.
assertThat(jobs, not(hasKey(jobId3)));
assertFalse(fileExists(prefixDirectory, jobId3.getName()));
// Verify that job4 and its prefix file have been deleted.
assertThat(jobs, not(hasKey(jobId4)));
assertFalse(fileExists(prefixDirectory, jobId4.getName()));
// Verify the prefix file created during the run of JobNamePrefixTest was deleted
assertFalse(fileExists(prefixDirectory, jobPrefixFile.prefix()));
}
}