use of org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJobContext in project drools by kiegroup.
the class CronJobTest method testCronTriggerJob.
@Test
public void testCronTriggerJob() throws Exception {
SessionConfiguration config = SessionConfiguration.newInstance();
config.setClockType(ClockType.PSEUDO_CLOCK);
PseudoClockScheduler timeService = (PseudoClockScheduler) TimerServiceFactory.getTimerService(config);
timeService.advanceTime(0, TimeUnit.MILLISECONDS);
CronTrigger trigger = new CronTrigger(0, null, null, -1, "15 * * * * ?", null, null);
HelloWorldJobContext ctx = new HelloWorldJobContext("hello world", timeService);
timeService.scheduleJob(new HelloWorldJob(), ctx, trigger);
assertEquals(0, ctx.getList().size());
timeService.advanceTime(10, TimeUnit.SECONDS);
assertEquals(0, ctx.getList().size());
timeService.advanceTime(10, TimeUnit.SECONDS);
assertEquals(1, ctx.getList().size());
timeService.advanceTime(30, TimeUnit.SECONDS);
assertEquals(1, ctx.getList().size());
timeService.advanceTime(30, TimeUnit.SECONDS);
assertEquals(2, ctx.getList().size());
}
Aggregations