use of org.drools.time.SessionPseudoClock in project jBPM5-Developer-Guide by Salaboy.
the class MyFirstDrools5FusionRulesTest method testPatternDetectionEvents.
@Test
public void testPatternDetectionEvents() {
StatefulKnowledgeSession ksession = createKnowledgeSession();
SessionPseudoClock clock = ksession.getSessionClock();
int fired = 0;
// Initial time 0s -> t0
ksession.insert(new KeyA());
fired = ksession.fireAllRules();
clock.advanceTime(15, TimeUnit.MILLISECONDS);
assertEquals(0, fired);
ksession.insert(new KeyS());
fired = ksession.fireAllRules();
clock.advanceTime(15, TimeUnit.MILLISECONDS);
assertEquals(0, fired);
ksession.insert(new KeyD());
fired = ksession.fireAllRules();
clock.advanceTime(15, TimeUnit.MILLISECONDS);
assertEquals(1, fired);
ksession.dispose();
}
use of org.drools.time.SessionPseudoClock in project jBPM5-Developer-Guide by Salaboy.
the class MyFirstDrools5FusionRulesTest method testSimpleEvents.
@Test
public void testSimpleEvents() {
StatefulKnowledgeSession ksession = createKnowledgeSession();
// Uncomment to see all the logs
// KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
// We have our Session, now let's play with our Events
SessionPseudoClock clock = ksession.getSessionClock();
int fired = 0;
// Initial time 0s -> t0
ksession.insert(new KeyA());
fired = ksession.fireAllRules();
clock.advanceTime(2, TimeUnit.SECONDS);
assertEquals(0, fired);
// t1 -> 2s
ksession.insert(new KeyA());
fired = ksession.fireAllRules();
clock.advanceTime(2, TimeUnit.SECONDS);
assertEquals(0, fired);
// t2 -> 4s
ksession.insert(new KeyA());
fired = ksession.fireAllRules();
clock.advanceTime(2, TimeUnit.SECONDS);
assertEquals(0, fired);
// t3 -> 6s
ksession.insert(new KeyA());
fired = ksession.fireAllRules();
clock.advanceTime(2, TimeUnit.SECONDS);
assertEquals(1, fired);
// t4 -> 8s
ksession.insert(new KeyA());
fired = ksession.fireAllRules();
assertEquals(1, fired);
ksession.dispose();
}
Aggregations