Search in sources :

Example 1 with ScheduledJobRunnable

use of uk.gov.gchq.gaffer.store.Store.ScheduledJobRunnable in project Gaffer by gchq.

the class StoreTest method shouldRescheduleJobsCorrectlyWhenInitialisationCountIs.

private void shouldRescheduleJobsCorrectlyWhenInitialisationCountIs(final int initialisationCount) throws Exception {
    // Given
    final StoreProperties properties = mock(StoreProperties.class);
    given(properties.getJobTrackerEnabled()).willReturn(true);
    given(properties.getJobExecutorThreadCount()).willReturn(1);
    final Repeat repeat = new Repeat(0, 100, TimeUnit.SECONDS);
    final OperationChain opChain = new OperationChain.Builder().first(new DiscardOutput()).build();
    final User user = new User.Builder().userId("testUser").opAuth("opAuth").dataAuth("dataAuth").build();
    final JobDetail scheduledJobDetail = new JobDetail.Builder().jobId("jobId").user(user).opChain(opChain.toOverviewString()).serialisedOperationChain(opChain).repeat(repeat).build();
    given(jobTracker.getAllScheduledJobs()).willReturn(new WrappedCloseableIterable(singletonList(scheduledJobDetail)));
    StoreImpl2 store = new StoreImpl2();
    // When - initialise store
    for (int i = 0; i < initialisationCount; i++) {
        store.initialise("graphId", schema, properties);
    }
    ScheduledExecutorService service = store.getExecutorService();
    // Then - assert scheduled
    final ArgumentCaptor<ScheduledJobRunnable> scheduledJobRunnableCaptor = ArgumentCaptor.forClass(ScheduledJobRunnable.class);
    verify(service).scheduleAtFixedRate(scheduledJobRunnableCaptor.capture(), eq(repeat.getInitialDelay()), eq(repeat.getRepeatPeriod()), eq(repeat.getTimeUnit()));
    assertEquals(scheduledJobDetail, scheduledJobRunnableCaptor.getValue().getJobDetail());
    assertEquals(user, scheduledJobRunnableCaptor.getValue().getContext().getUser());
    assertArrayEquals(JSONSerialiser.serialise(opChain), JSONSerialiser.serialise(scheduledJobRunnableCaptor.getValue().getOperationChain()));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) User(uk.gov.gchq.gaffer.user.User) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ScheduledJobRunnable(uk.gov.gchq.gaffer.store.Store.ScheduledJobRunnable) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput)

Aggregations

ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)1 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)1 Repeat (uk.gov.gchq.gaffer.jobtracker.Repeat)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)1 ValidateOperationChain (uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain)1 ScheduledJobRunnable (uk.gov.gchq.gaffer.store.Store.ScheduledJobRunnable)1 User (uk.gov.gchq.gaffer.user.User)1