Search in sources :

Example 1 with PipelineJobRecordStore

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();
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NullPipelineJobArguments(gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments) LoggerFactory(org.slf4j.LoggerFactory) SchedulerJob(gov.cms.bfd.pipeline.app.scheduler.SchedulerJob) PipelineJob(gov.cms.bfd.pipeline.sharedutils.PipelineJob) Callable(java.util.concurrent.Callable) VolunteerJob(gov.cms.bfd.pipeline.app.volunteer.VolunteerJob) Disabled(org.junit.jupiter.api.Disabled) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) PipelineJobRecord(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PipelineJobOutcome(gov.cms.bfd.pipeline.sharedutils.PipelineJobOutcome) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) Set(java.util.Set) PipelineJobType(gov.cms.bfd.pipeline.sharedutils.PipelineJobType) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Slf4jReporter(com.codahale.metrics.Slf4jReporter) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) Test(org.junit.jupiter.api.Test)

Example 2 with PipelineJobRecordStore

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());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NullPipelineJobArguments(gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments) LoggerFactory(org.slf4j.LoggerFactory) SchedulerJob(gov.cms.bfd.pipeline.app.scheduler.SchedulerJob) PipelineJob(gov.cms.bfd.pipeline.sharedutils.PipelineJob) Callable(java.util.concurrent.Callable) VolunteerJob(gov.cms.bfd.pipeline.app.volunteer.VolunteerJob) Disabled(org.junit.jupiter.api.Disabled) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) PipelineJobRecord(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PipelineJobOutcome(gov.cms.bfd.pipeline.sharedutils.PipelineJobOutcome) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) Set(java.util.Set) PipelineJobType(gov.cms.bfd.pipeline.sharedutils.PipelineJobType) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Slf4jReporter(com.codahale.metrics.Slf4jReporter) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) Test(org.junit.jupiter.api.Test)

Example 3 with PipelineJobRecordStore

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());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NullPipelineJobArguments(gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments) LoggerFactory(org.slf4j.LoggerFactory) SchedulerJob(gov.cms.bfd.pipeline.app.scheduler.SchedulerJob) PipelineJob(gov.cms.bfd.pipeline.sharedutils.PipelineJob) Callable(java.util.concurrent.Callable) VolunteerJob(gov.cms.bfd.pipeline.app.volunteer.VolunteerJob) Disabled(org.junit.jupiter.api.Disabled) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) PipelineJobRecord(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PipelineJobOutcome(gov.cms.bfd.pipeline.sharedutils.PipelineJobOutcome) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) Set(java.util.Set) PipelineJobType(gov.cms.bfd.pipeline.sharedutils.PipelineJobType) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Slf4jReporter(com.codahale.metrics.Slf4jReporter) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) PipelineJobRecord(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord) Test(org.junit.jupiter.api.Test)

Example 4 with PipelineJobRecordStore

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);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NullPipelineJobArguments(gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments) LoggerFactory(org.slf4j.LoggerFactory) SchedulerJob(gov.cms.bfd.pipeline.app.scheduler.SchedulerJob) PipelineJob(gov.cms.bfd.pipeline.sharedutils.PipelineJob) Callable(java.util.concurrent.Callable) VolunteerJob(gov.cms.bfd.pipeline.app.volunteer.VolunteerJob) Disabled(org.junit.jupiter.api.Disabled) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) PipelineJobRecord(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PipelineJobOutcome(gov.cms.bfd.pipeline.sharedutils.PipelineJobOutcome) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) Set(java.util.Set) PipelineJobType(gov.cms.bfd.pipeline.sharedutils.PipelineJobType) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Slf4jReporter(com.codahale.metrics.Slf4jReporter) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) NullPipelineJobArguments(gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments) Test(org.junit.jupiter.api.Test)

Example 5 with PipelineJobRecordStore

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());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NullPipelineJobArguments(gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments) LoggerFactory(org.slf4j.LoggerFactory) SchedulerJob(gov.cms.bfd.pipeline.app.scheduler.SchedulerJob) PipelineJob(gov.cms.bfd.pipeline.sharedutils.PipelineJob) Callable(java.util.concurrent.Callable) VolunteerJob(gov.cms.bfd.pipeline.app.volunteer.VolunteerJob) Disabled(org.junit.jupiter.api.Disabled) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) PipelineJobRecord(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PipelineJobOutcome(gov.cms.bfd.pipeline.sharedutils.PipelineJobOutcome) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) Set(java.util.Set) PipelineJobType(gov.cms.bfd.pipeline.sharedutils.PipelineJobType) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Slf4jReporter(com.codahale.metrics.Slf4jReporter) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) PipelineJobRecordStore(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore) PipelineJobSchedule(gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule) PipelineJobRecord(gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord) Test(org.junit.jupiter.api.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)10 Slf4jReporter (com.codahale.metrics.Slf4jReporter)10 NullPipelineJobArguments (gov.cms.bfd.pipeline.sharedutils.NullPipelineJobArguments)10 PipelineJobRecordStore (gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecordStore)10 SchedulerJob (gov.cms.bfd.pipeline.app.scheduler.SchedulerJob)9 VolunteerJob (gov.cms.bfd.pipeline.app.volunteer.VolunteerJob)9 PipelineJob (gov.cms.bfd.pipeline.sharedutils.PipelineJob)9 PipelineJobOutcome (gov.cms.bfd.pipeline.sharedutils.PipelineJobOutcome)9 PipelineJobSchedule (gov.cms.bfd.pipeline.sharedutils.PipelineJobSchedule)9 PipelineJobType (gov.cms.bfd.pipeline.sharedutils.PipelineJobType)9 PipelineTestUtils (gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils)9 PipelineJobRecord (gov.cms.bfd.pipeline.sharedutils.jobs.store.PipelineJobRecord)9 BadCodeMonkeyException (gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException)9 ChronoUnit (java.time.temporal.ChronoUnit)9 Optional (java.util.Optional)9 Set (java.util.Set)9 Callable (java.util.concurrent.Callable)9 TimeUnit (java.util.concurrent.TimeUnit)9 Collectors (java.util.stream.Collectors)9 Awaitility (org.awaitility.Awaitility)9