use of org.kie.api.event.rule.AgendaGroupPoppedEvent in project drools by kiegroup.
the class CepEspTest method testFireExpiredEventOnInactiveGroup.
@Test
public void testFireExpiredEventOnInactiveGroup() {
// DROOLS-1523
final String drl = "global java.util.List list;\n" + "declare String @role(event) @expires( 6d ) end\n" + "declare Integer @role(event) @expires( 3d ) end\n" + "\n" + "rule \"RG_1\"\n" + " agenda-group \"rf-grp1\"\n" + " when\n" + " $event: Integer()\n" + " not String(this after [1ms, 48h] $event)\n" + " then\n" + " System.out.println(\"RG_1 fired\");\n" + " retract($event);\n" + " list.add(\"RG_1\");\n" + "end\n" + "\n" + "rule \"RG_2\"\n" + " agenda-group \"rf-grp1\"\n" + " when\n" + " $event: String()\n" + " not Integer(this after [1ms, 144h] $event)\n" + " then\n" + " System.out.println(\"RG_2 fired\");\n" + " list.add(\"RG_2\");\n" + "end\n";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cep-esp-test", kieBaseTestConfiguration, drl);
final KieSession kieSession = kbase.newKieSession(KieSessionTestConfiguration.STATEFUL_PSEUDO.getKieSessionConfiguration(), null);
try {
kieSession.addEventListener(new DefaultAgendaEventListener() {
public void agendaGroupPopped(final AgendaGroupPoppedEvent event) {
if (event.getAgendaGroup().getName().equals("rf-grp0")) {
event.getKieRuntime().getAgenda().getAgendaGroup("rf-grp1").setFocus();
}
}
});
final List<String> list = new ArrayList<>();
kieSession.setGlobal("list", list);
final PseudoClockScheduler sessionClock = kieSession.getSessionClock();
kieSession.insert("DummyEvent");
// <- OtherDummyEvent
kieSession.insert(1);
kieSession.getAgenda().getAgendaGroup("rf-grp0").setFocus();
// OK nothing happens
kieSession.fireAllRules();
assertEquals(2, kieSession.getFactCount());
sessionClock.advanceTime(145, TimeUnit.HOURS);
kieSession.getAgenda().getAgendaGroup("rf-grp0").setFocus();
kieSession.fireAllRules();
assertEquals("Expiration occured => no more fact in WM", 0, kieSession.getFactCount());
assertEquals("RG_1 should fire once", 1, list.stream().filter(r -> r.equals("RG_1")).count());
assertEquals("RG_2 should fire once", 1, list.stream().filter(r -> r.equals("RG_2")).count());
} finally {
kieSession.dispose();
}
}
Aggregations