use of gov.cms.bfd.pipeline.app.volunteer.VolunteerJob in project beneficiary-fhir-data by CMSgov.
the class PipelineManagerIT method runThenStopAndCancelPendingJobs.
/**
* Verifies that {@link PipelineManager#stop()} works, as expected.
*
* @throws Exception Any unhandled {@link Exception}s will cause this test case to fail.
*/
@Test
public void runThenStopAndCancelPendingJobs() throws Exception {
// Create the pipeline and a slow mock job that we can use.
PipelineJobRecordStore jobRecordStore = new PipelineJobRecordStore(PipelineTestUtils.get().getPipelineApplicationState().getMetrics());
try (PipelineManager pipelineManager = new PipelineManager(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), jobRecordStore)) {
MockJob mockJob = new MockJob(Optional.empty(), () -> {
// Add an artificial delay that we'll be able to measure.
Thread.sleep(500);
return PipelineJobOutcome.WORK_DONE;
});
pipelineManager.registerJob(mockJob);
/*
* Once the VolunteerJob is running, submit enough slow mock jobs to fill up the
* PipelineManager's executor threads/slots.
*/
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> jobRecordStore.getJobRecords().stream().filter(j -> VolunteerJob.JOB_TYPE.equals(j.getJobType()) && j.isStarted()).findAny().isPresent());
int openExecutorSlots = pipelineManager.getOpenExecutorSlots();
for (int i = 0; i < openExecutorSlots; i++) {
jobRecordStore.submitPendingJob(MockJob.JOB_TYPE, null);
}
// Add one extra job that should sit as pending for a bit.
jobRecordStore.submitPendingJob(MockJob.JOB_TYPE, null);
// Wait until one of the mock jobs has started.
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> jobRecordStore.getJobRecords().stream().filter(j -> MockJob.JOB_TYPE.equals(j.getJobType()) && j.isStarted()).findAny().isPresent());
// Stop the pipeline and verify that at least one job was cancelled before it started.
pipelineManager.stop();
assertTrue(jobRecordStore.getJobRecords().stream().filter(j -> MockJob.JOB_TYPE.equals(j.getJobType()) && !j.isStarted()).findAny().isPresent());
}
}
Aggregations