@Test public void testJobScheduling() throws Exception { batchJobScheduler.scheduleAt(engine1, now); batchJobScheduler.scheduleAt(engine2, now); assertThat(batchJobScheduler.isScheduled(engine1)).isTrue(); assertThat(batchJobScheduler.isScheduled(engine2)).isTrue(); batchJobScheduler.start(); assertThat(batchJobScheduler.isStarted()).isTrue(); Thread.sleep(500); // sleep to ensure the next verify is called after calling the engine verify(engine1).call(); verify(engine2).call(); batchJobScheduler.unschedule(engine1); assertThat(batchJobScheduler.isScheduled(engine1)).isFalse(); batchJobScheduler.unschedule(engine2); assertThat(batchJobScheduler.isScheduled(engine2)).isFalse(); verify(engine1, times(4)).getExecutionId(); verify(engine2, times(4)).getExecutionId(); batchJobScheduler.stop(); assertThat(batchJobScheduler.isStopped()).isTrue(); }
@Before public void setUp() throws Exception { batchJobScheduler = BatchJobScheduler.getInstance(); when(engine1.getExecutionId()).thenReturn("engine1"); when(engine1.getExecutionId()).thenReturn("123"); when(engine2.getExecutionId()).thenReturn("engine2"); when(engine2.getExecutionId()).thenReturn("456"); }