use of org.drools.core.time.Trigger in project drools by kiegroup.
the class JDKTimerServiceTest method testSingleExecutionJob.
@Test
public void testSingleExecutionJob() throws Exception {
SessionConfiguration config = SessionConfiguration.newInstance();
config.setClockType(ClockType.REALTIME_CLOCK);
TimerService timeService = TimerServiceFactory.getTimerService(config);
Trigger trigger = new DelayedTrigger(100);
HelloWorldJobContext ctx = new HelloWorldJobContext("hello world", timeService);
timeService.scheduleJob(new HelloWorldJob(), ctx, trigger);
Thread.sleep(500);
timeService.shutdown();
assertEquals(1, ctx.getList().size());
}
use of org.drools.core.time.Trigger in project drools by kiegroup.
the class CompositeMaxDurationTimerTest method testMixedDurationAndTimer.
@Test
public void testMixedDurationAndTimer() {
CompositeMaxDurationTimer timer = new CompositeMaxDurationTimer();
timer.addDurationTimer(new DurationTimer(25));
timer.addDurationTimer(new DurationTimer(50));
timer.addDurationTimer(new DurationTimer(70));
timer.setTimer(new IntervalTimer(null, null, 6, 40, 25));
Date timestamp = new Date();
Trigger trigger = timer.createTrigger(timestamp.getTime(), null, null, null, null, null, null);
// ignores the first interval timer at 65
assertEquals(new Date(timestamp.getTime() + 70), trigger.hasNextFireTime());
assertEquals(new Date(timestamp.getTime() + 90), trigger.nextFireTime());
assertEquals(new Date(timestamp.getTime() + 115), trigger.nextFireTime());
assertEquals(new Date(timestamp.getTime() + 140), trigger.nextFireTime());
assertNull(trigger.nextFireTime());
assertNull(trigger.hasNextFireTime());
}
use of org.drools.core.time.Trigger in project drools by kiegroup.
the class CompositeMaxDurationTimerTest method testJustMaxDuration.
@Test
public void testJustMaxDuration() {
CompositeMaxDurationTimer timer = new CompositeMaxDurationTimer();
timer.addDurationTimer(new DurationTimer(25));
timer.addDurationTimer(new DurationTimer(50));
timer.addDurationTimer(new DurationTimer(70));
Date timestamp = new Date();
Trigger trigger = timer.createTrigger(timestamp.getTime(), null, null, null, null, null, null);
assertEquals(new Date(timestamp.getTime() + 70), trigger.hasNextFireTime());
assertNull(trigger.nextFireTime());
assertNull(trigger.hasNextFireTime());
}
use of org.drools.core.time.Trigger in project drools by kiegroup.
the class TimerNodeTimerInputMarshaller method deserialize.
@Override
public void deserialize(MarshallerReaderContext inCtx, ProtobufMessages.Timers.Timer _timer) {
ProtobufMessages.Timers.TimerNodeTimer _tn = _timer.getTimerNode();
int timerNodeId = _tn.getNodeId();
TupleKey tuple = PersisterHelper.createTupleKey(_tn.getTuple());
Trigger trigger = ProtobufInputMarshaller.readTrigger(inCtx, _tn.getTrigger());
PhreakTimerNode.Scheduler scheduler = inCtx.removeTimerNodeScheduler(timerNodeId, tuple);
if (scheduler != null) {
scheduler.schedule(trigger);
}
}
Aggregations