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()));
}
Aggregations