use of org.kie.internal.runtime.conf.ForceEagerActivationFilter 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 = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(new ForceEagerActivationOption.FILTERED(new ForceEagerActivationFilter() {
@Override
public boolean accept(Rule rule) {
return rule.getName().equals("xxx");
}
}));
KieBase kbase = loadKnowledgeBaseFromString(str);
KieSession ksession = createKnowledgeSession(kbase, conf);
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.internal.runtime.conf.ForceEagerActivationFilter in project drools by kiegroup.
the class ActivateAndDeleteOnListenerTest method testOneLazyAndOneImmediateSubPath.
@Test
public void testOneLazyAndOneImmediateSubPath() throws Exception {
String str = "package org.simple \n" + "rule xxx \n" + "when \n" + " $s : String()\n" + " exists( Integer() or Long() )\n" + "then \n" + "end \n" + "rule yyy \n" + "when \n" + " $s : String()\n" + " exists( Integer() or Long() )\n" + "then \n" + "end \n";
KieServices ks = KieServices.Factory.get();
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(new ForceEagerActivationOption.FILTERED(new ForceEagerActivationFilter() {
@Override
public boolean accept(Rule rule) {
return rule.getName().equals("yyy");
}
}));
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession(conf, null);
final List list = new ArrayList();
AgendaEventListener agendaEventListener = new org.kie.api.event.rule.DefaultAgendaEventListener() {
public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
list.add(event.getMatch().getRule().getName());
}
};
ksession.addEventListener(agendaEventListener);
ksession.insert("test");
assertEquals(0, list.size());
ksession.insert(1);
assertEquals(1, list.size());
assertEquals("yyy", list.get(0));
}
use of org.kie.internal.runtime.conf.ForceEagerActivationFilter 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());
}
Aggregations