Search in sources :

Example 1 with HelloWorldJob

use of org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJob 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());
}
Also used : HelloWorldJobContext(org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJobContext) HelloWorldJob(org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJob) SessionConfiguration(org.drools.core.SessionConfiguration) Test(org.junit.Test)

Aggregations

SessionConfiguration (org.drools.core.SessionConfiguration)1 HelloWorldJob (org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJob)1 HelloWorldJobContext (org.drools.core.time.impl.JDKTimerServiceTest.HelloWorldJobContext)1 Test (org.junit.Test)1