use of gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore in project beneficiary-fhir-data by CMSgov.
the class PipelineManagerIT method runUninterruptibleJobsThenStop.
/**
* 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 runUninterruptibleJobsThenStop() throws Exception {
// Create the pipeline and have it run a mock job.
PipelineJobRecordStore jobRecordStore = new PipelineJobRecordStore(PipelineTestUtils.get().getPipelineApplicationState().getMetrics());
try (PipelineManager pipelineManager = new PipelineManager(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), jobRecordStore)) {
MockJob mockJob = new MockJob(Optional.of(new PipelineJobSchedule(1, ChronoUnit.MILLIS)), false, () -> {
return PipelineJobOutcome.WORK_DONE;
});
pipelineManager.registerJob(mockJob);
jobRecordStore.submitPendingJob(MockJob.JOB_TYPE, null);
// Wait until the mock job 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. If this doesn't hang, we're good.
pipelineManager.stop();
}
}
use of gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore 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());
}
}
use of gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore in project beneficiary-fhir-data by CMSgov.
the class PipelineManagerIT method runSuccessfulMockOneshotJob.
/**
* Verifies that {@link PipelineManager} runs a successful mock one-shot job, as expected.
*
* @throws Exception Any unhandled {@link Exception}s will cause this test case to fail.
*/
@Test
public void runSuccessfulMockOneshotJob() throws Exception {
// Create the pipeline and have it run a mock job.
PipelineJobRecordStore jobRecordStore = new PipelineJobRecordStore(PipelineTestUtils.get().getPipelineApplicationState().getMetrics());
try (PipelineManager pipelineManager = new PipelineManager(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), jobRecordStore)) {
MockJob mockJob = new MockJob(Optional.empty(), () -> PipelineJobOutcome.WORK_DONE);
pipelineManager.registerJob(mockJob);
jobRecordStore.submitPendingJob(MockJob.JOB_TYPE, null);
// Wait until a completed iteration of the mock job can be found.
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> jobRecordStore.getJobRecords().stream().filter(j -> MockJob.JOB_TYPE.equals(j.getJobType()) && j.isCompleted()).findAny().isPresent());
// Verify that one of the completed mock job iterations looks correct.
Optional<PipelineJobRecord<?>> mockJobRecord = jobRecordStore.getJobRecords().stream().filter(j -> MockJob.JOB_TYPE.equals(j.getJobType())).findAny();
assertEquals(Optional.of(PipelineJobOutcome.WORK_DONE), mockJobRecord.get().getOutcome());
}
}
use of gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore in project beneficiary-fhir-data by CMSgov.
the class PipelineManagerIT method runInterruptibleJobsThenStop.
/**
* 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 runInterruptibleJobsThenStop() throws Exception {
// Create the pipeline and have it run a mock job.
PipelineJobRecordStore jobRecordStore = new PipelineJobRecordStore(PipelineTestUtils.get().getPipelineApplicationState().getMetrics());
try (PipelineManager pipelineManager = new PipelineManager(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), jobRecordStore)) {
MockJob mockJob = new MockJob(Optional.of(new PipelineJobSchedule(1, ChronoUnit.MILLIS)), () -> {
// Add an artificial delay that we'll be able to measure.
Thread.sleep(500);
return PipelineJobOutcome.WORK_DONE;
});
pipelineManager.registerJob(mockJob);
jobRecordStore.submitPendingJob(MockJob.JOB_TYPE, null);
// Wait until the mock job 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 then make sure that the job was actually interrupted.
pipelineManager.stop();
PipelineJobRecord<NullPipelineJobArguments> mockJobRecord = jobRecordStore.findMostRecent(MockJob.JOB_TYPE).get();
assertTrue(mockJobRecord.getCanceledTime().isPresent());
assertTrue(mockJobRecord.getDuration().get().toMillis() < 500);
}
}
use of gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore in project beneficiary-fhir-data by CMSgov.
the class PipelineManagerIT method runSuccessfulScheduledJob.
/**
* Verifies that {@link PipelineManager} runs a successful mock scheduled job, as expected.
*
* @throws Exception Any unhandled {@link Exception}s will cause this test case to fail.
*/
@Test
public void runSuccessfulScheduledJob() throws Exception {
// Create the pipeline and have it run a mock job.
PipelineJobRecordStore jobRecordStore = new PipelineJobRecordStore(PipelineTestUtils.get().getPipelineApplicationState().getMetrics());
try (PipelineManager pipelineManager = new PipelineManager(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), jobRecordStore)) {
MockJob mockJob = new MockJob(Optional.of(new PipelineJobSchedule(1, ChronoUnit.MILLIS)), () -> PipelineJobOutcome.WORK_DONE);
pipelineManager.registerJob(mockJob);
jobRecordStore.submitPendingJob(MockJob.JOB_TYPE, null);
// Wait until a completed iteration of the mock job can be found.
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> jobRecordStore.getJobRecords().stream().filter(j -> MockJob.JOB_TYPE.equals(j.getJobType()) && j.isCompleted()).findAny().isPresent());
// Verify that one of the completed mock job iterations looks correct.
Optional<PipelineJobRecord<?>> mockJobRecord = jobRecordStore.getJobRecords().stream().filter(j -> MockJob.JOB_TYPE.equals(j.getJobType()) && j.isCompleted()).findAny();
assertEquals(Optional.of(PipelineJobOutcome.WORK_DONE), mockJobRecord.get().getOutcome());
}
}
Aggregations