use of org.haiku.haikudepotserver.job.model.TestLockableJobSpecification in project haikudepotserver by haiku.
the class LocalJobServiceIT method testCoalescePicksTheMostRecentFinished.
/**
* This test will allow two jobs to go through. Then it will load another and lock it and put another
* into the queue. We can then check the statuses of the jobs and also check that if another is
* submitted with coalescing, that the correct code is returned.
*/
@Test
public void testCoalescePicksTheMostRecentFinished() {
// make sure that no old jobs from previous tests are coming through.
Assertions.assertThat(jobService.awaitAllJobsFinishedUninterruptibly(TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS))).isTrue();
// -------------------------
// setup the initial situation
String job1FinishedGuid = jobService.submit(new TestLockableJobSpecification(), JobSnapshot.COALESCE_STATUSES_NONE);
jobService.awaitJobFinishedUninterruptibly(job1FinishedGuid, TimeUnit.SECONDS.toMillis(10));
String job2FinishedGuid = jobService.submit(new TestLockableJobSpecification(), JobSnapshot.COALESCE_STATUSES_NONE);
jobService.awaitJobFinishedUninterruptibly(job2FinishedGuid, TimeUnit.SECONDS.toMillis(10));
Lock job3Lock = new ReentrantLock();
String job3StartedGuid;
String job4QueuedGuid;
job3Lock.lock();
try {
job3StartedGuid = jobService.submit(new TestLockableJobSpecification(job3Lock), JobSnapshot.COALESCE_STATUSES_NONE);
job4QueuedGuid = jobService.submit(new TestLockableJobSpecification(), JobSnapshot.COALESCE_STATUSES_NONE);
// -------------------------
assertStatus(job1FinishedGuid, JobSnapshot.Status.FINISHED);
assertStatus(job2FinishedGuid, JobSnapshot.Status.FINISHED);
assertStatus(job3StartedGuid, JobSnapshot.Status.STARTED);
assertStatus(job4QueuedGuid, JobSnapshot.Status.QUEUED);
// check some coalescing works.
Assertions.assertThat(jobService.submit(new TestLockableJobSpecification(), JobSnapshot.COALESCE_STATUSES_QUEUED)).isEqualTo(job4QueuedGuid);
Assertions.assertThat(jobService.submit(new TestLockableJobSpecification(), JobSnapshot.COALESCE_STATUSES_QUEUED_STARTED)).isEqualTo(job3StartedGuid);
Assertions.assertThat(jobService.submit(new TestLockableJobSpecification(), JobSnapshot.COALESCE_STATUSES_QUEUED_STARTED_FINISHED)).isEqualTo(job1FinishedGuid);
// -------------------------
// release the last two jobs and watch they come through OK.
} finally {
job3Lock.unlock();
}
jobService.awaitJobFinishedUninterruptibly(job3StartedGuid, TimeUnit.SECONDS.toMillis(10));
jobService.awaitJobFinishedUninterruptibly(job4QueuedGuid, TimeUnit.SECONDS.toMillis(10));
// -------------------------
assertStatus(job3StartedGuid, JobSnapshot.Status.FINISHED);
assertStatus(job3StartedGuid, JobSnapshot.Status.FINISHED);
}
Aggregations