use of org.kie.api.event.rule.AgendaEventListener in project drools by kiegroup.
the class ActivationIteratorTest method testEagerEvaluation.
@Test(timeout = 10000)
public void testEagerEvaluation() throws Exception {
String str = "package org.simple \n" + "rule xxx @Propagation(EAGER) \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n" + "rule yyy @Propagation(EAGER) \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n";
KieSessionConfiguration conf = RuleBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ForceEagerActivationOption.YES);
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession(conf, null);
final List list = new ArrayList();
AgendaEventListener agendaEventListener = new DefaultAgendaEventListener() {
public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
list.add("activated");
}
};
ksession.addEventListener(agendaEventListener);
ksession.insert("test");
assertEquals(2, list.size());
}
use of org.kie.api.event.rule.AgendaEventListener in project drools by kiegroup.
the class ActivationIteratorTest method testFilteredEagerEvaluation.
@Test(timeout = 10000)
public void testFilteredEagerEvaluation() throws Exception {
String str = "package org.simple \n" + "rule xxx @Propagation(EAGER) \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n" + "rule yyy @Propagation(EAGER) \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n";
KieSessionConfiguration conf = RuleBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(new ForceEagerActivationOption.FILTERED(new ForceEagerActivationFilter() {
@Override
public boolean accept(Rule rule) {
return rule.getName().equals("xxx");
}
}));
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession(conf, null);
final List list = new ArrayList();
AgendaEventListener agendaEventListener = new DefaultAgendaEventListener() {
public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
list.add("activated");
}
};
ksession.addEventListener(agendaEventListener);
ksession.insert("test");
((InternalWorkingMemory) ksession).flushPropagations();
assertEquals(1, list.size());
}
use of org.kie.api.event.rule.AgendaEventListener in project drools by kiegroup.
the class PseudoClockEventsTest method testEvenFirePseudoClockRuleB.
@Test(timeout = 10000)
public void testEvenFirePseudoClockRuleB() throws Exception {
AgendaEventListener ael = mock(AgendaEventListener.class);
processStocks(evalFirePseudoClockStockCount, ael, evalFirePseudoClockDeclaration + evalFirePseudoClockRuleB);
verify(ael, times(evalFirePseudoClockStockCount - 1)).afterMatchFired(any(AfterMatchFiredEvent.class));
}
use of org.kie.api.event.rule.AgendaEventListener in project drools by kiegroup.
the class PseudoClockEventsTest method testEvenFirePseudoClockRuleA.
@Test(timeout = 10000)
public void testEvenFirePseudoClockRuleA() throws Exception {
AgendaEventListener ael = mock(AgendaEventListener.class);
processStocks(evalFirePseudoClockStockCount, ael, evalFirePseudoClockDeclaration + evalFirePseudoClockRuleA);
verify(ael, times(evalFirePseudoClockStockCount * (evalFirePseudoClockStockCount - 1) / 2)).afterMatchFired(any(AfterMatchFiredEvent.class));
}
use of org.kie.api.event.rule.AgendaEventListener in project drools by kiegroup.
the class EnabledTest method testEnabledExpression2.
@Test
public void testEnabledExpression2() {
final String drl = "import " + MyFact.class.getName() + ";\n" + "rule R1\n" + " enabled( rule.name == $f.name )" + "when\n" + " $f : MyFact()\n" + "then end\n" + "rule R2\n" + "when\n" + " MyFact( name == \"R2\" )\n" + "then end\n";
final KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-enabled", "1.0.0");
final KieModule km = KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, drl);
// Create a session and fire rules
final KieContainer kc = ks.newKieContainer(km.getReleaseId());
AgendaEventListener ael = mock(AgendaEventListener.class);
KieSession ksession = kc.newKieSession();
try {
ksession.addEventListener(ael);
ksession.insert(new MyFact("R1", null));
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
ArgumentCaptor<AfterMatchFiredEvent> event = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
verify(ael).afterMatchFired(event.capture());
assertEquals("R1", event.getValue().getMatch().getRule().getName());
ael = mock(AgendaEventListener.class);
ksession.dispose();
ksession = kc.newKieSession();
ksession.addEventListener(ael);
ksession.insert(new MyFact("R2", null));
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
event = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
verify(ael).afterMatchFired(event.capture());
assertEquals("R2", event.getValue().getMatch().getRule().getName());
} finally {
ksession.dispose();
}
}
Aggregations