use of org.drools.core.common.AgendaItem in project drools by kiegroup.
the class ActivationIteratorTest method testSingleLian.
@Test
public void testSingleLian() {
String str = "package org.kie.test \n" + "\n" + "rule rule1 @Propagation(EAGER) when\n" + " $s : String( this != 'xx' )\n" + "then\n" + "end\n" + "rule rule6 @Propagation(EAGER) when\n" + " java.util.Map()\n" + "then\n" + "end\n" + "\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
for (int i = 0; i < 5; i++) {
ksession.insert(new String("" + i));
}
evaluateEagerList(ksession);
Iterator it = ActivationIterator.iterator(ksession);
List list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s") + ":" + act.isQueued());
}
assertContains(new String[] { "rule1:0:true", "rule1:1:true", "rule1:2:true", "rule1:3:true", "rule1:4:true" }, list);
ksession.fireAllRules();
it = ActivationIterator.iterator(ksession);
list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s") + ":" + act.isQueued());
}
assertContains(new String[] { "rule1:0:false", "rule1:1:false", "rule1:2:false", "rule1:3:false", "rule1:4:false" }, list);
}
use of org.drools.core.common.AgendaItem in project drools by kiegroup.
the class ActivationIteratorTest method testSingleJoinNodePlusEvalnWithSharing.
@Test
public void testSingleJoinNodePlusEvalnWithSharing() {
String str = "package org.kie.test \n" + "\n" + "rule rule1 @Propagation(EAGER) when\n" + " $s1 : String( )\n" + " $s2 : String( )\n" + " eval( 1 == 1 ) \n" + "then\n" + "end\n" + "rule rule2 @Propagation(EAGER) when\n" + " $s1 : String( )\n" + "then\n" + "end\n" + "rule rule3 @Propagation(EAGER) when\n" + " $s1 : String( )\n" + " $s2 : String( )\n" + " $s3 : String( )\n" + " eval( 1 == 1 ) \n" + "then\n" + "end\n" + "\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
for (int i = 0; i < 2; i++) {
ksession.insert(new String("" + i));
}
evaluateEagerList(ksession);
Iterator it = ActivationIterator.iterator(ksession);
List list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
if (act.getRule().getName().equals("rule3")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.getDeclarationValue("$s2") + ":" + act.getDeclarationValue("$s3") + ":" + act.isQueued());
} else if (act.getRule().getName().equals("rule1")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.getDeclarationValue("$s2") + ":" + act.isQueued());
} else if (act.getRule().getName().equals("rule2")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.isQueued());
}
}
assertContains(new String[] { "rule1:0:0:true", "rule1:0:1:true", "rule1:1:0:true", "rule1:1:1:true", "rule2:1:true", "rule2:0:true", "rule3:0:0:0:true", "rule3:0:0:1:true", "rule3:1:0:0:true", "rule3:1:0:1:true", "rule3:0:1:0:true", "rule3:0:1:1:true", "rule3:1:1:0:true", "rule3:1:1:1:true" }, list);
ksession.fireAllRules();
it = ActivationIterator.iterator(ksession);
list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
if (act.getRule().getName().equals("rule3")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.getDeclarationValue("$s2") + ":" + act.getDeclarationValue("$s3") + ":" + act.isQueued());
} else if (act.getRule().getName().equals("rule1")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.getDeclarationValue("$s2") + ":" + act.isQueued());
} else if (act.getRule().getName().equals("rule2")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.isQueued());
}
}
assertContains(new String[] { "rule1:0:0:false", "rule1:0:1:false", "rule1:1:0:false", "rule1:1:1:false", "rule2:1:false", "rule2:0:false", "rule3:0:0:0:false", "rule3:0:0:1:false", "rule3:1:0:0:false", "rule3:1:0:1:false", "rule3:0:1:0:false", "rule3:0:1:1:false", "rule3:1:1:0:false", "rule3:1:1:1:false" }, list);
}
use of org.drools.core.common.AgendaItem in project drools by kiegroup.
the class ActivationIteratorTest method testSingleJoinNodePlusEvaln.
@Test
public void testSingleJoinNodePlusEvaln() {
String str = "package org.kie.test \n" + "\n" + "rule rule1 @Propagation(EAGER) when\n" + " $s1 : String( )\n" + " $s2 : String( )\n" + " eval( 1 == 1 ) \n" + "then\n" + "end\n" + "\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
for (int i = 0; i < 2; i++) {
ksession.insert(new String("" + i));
}
evaluateEagerList(ksession);
Iterator it = ActivationIterator.iterator(ksession);
List list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.getDeclarationValue("$s2") + ":" + act.isQueued());
}
assertContains(new String[] { "rule1:0:1:true", "rule1:1:0:true", "rule1:1:1:true", "rule1:0:0:true" }, list);
ksession.fireAllRules();
it = ActivationIterator.iterator(ksession);
list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.getDeclarationValue("$s2") + ":" + act.isQueued());
}
assertContains(new String[] { "rule1:0:1:false", "rule1:1:0:false", "rule1:1:1:false", "rule1:0:0:false" }, list);
}
use of org.drools.core.common.AgendaItem in project drools by kiegroup.
the class ActivationIteratorTest method testNotSharingWithMixedDormantAndActive.
@Test
public void testNotSharingWithMixedDormantAndActive() {
String str = "package org.kie.test \n" + "\n" + "rule rule1 @Propagation(EAGER) salience 10 when\n" + " not String( this == '1' )\n" + "then\n" + "end\n" + "rule rule2 @Propagation(EAGER) salience ( Integer.parseInt( $s1+'1' ) ) when\n" + " not String( this == '1' )\n" + " $s1 : String( )\n" + " eval( 1 == 1 ) \n" + "then\n" + "end\n" + "rule rule3 @Propagation(EAGER) salience ( Integer.parseInt( $s1+'2' ) ) when\n" + " $s1 : String( )\n" + " not String( this == '1' )\n" + " eval( 1 == 1 ) \n" + " eval( 1 == 1 ) \n" + "then\n" + " kcontext.getKieRuntime().halt();\n" + "end\n" + "\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
ksession.insert("0");
ksession.insert("2");
ksession.fireAllRules();
Iterator it = ActivationIterator.iterator(ksession);
List list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
if (act.getRule().getName().equals("rule3")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.isQueued());
} else if (act.getRule().getName().equals("rule1")) {
list.add(act.getRule().getName() + ":" + act.isQueued());
} else if (act.getRule().getName().equals("rule2")) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s1") + ":" + act.isQueued());
}
}
assertContains(new String[] { "rule1:true", "rule2:0:true", "rule2:2:true", "rule3:0:true", "rule3:2:false" }, list);
}
use of org.drools.core.common.AgendaItem in project drools by kiegroup.
the class ActivationIteratorTest method testLianPlusEvaln.
@Test
public void testLianPlusEvaln() {
String str = "package org.kie.test \n" + "\n" + "rule rule1 @Propagation(EAGER) when\n" + " $s : String( this != 'xx' )\n" + " eval( 1 == 1 ) \n" + "then\n" + "end\n" + "rule rule6 @Propagation(EAGER) when\n" + " java.util.Map()\n" + "then\n" + "end\n" + "\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
for (int i = 0; i < 5; i++) {
ksession.insert(new String("" + i));
}
evaluateEagerList(ksession);
Iterator it = ActivationIterator.iterator(ksession);
List list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s") + ":" + act.isQueued());
}
assertContains(new String[] { "rule1:0:true", "rule1:1:true", "rule1:2:true", "rule1:3:true", "rule1:4:true" }, list);
ksession.fireAllRules();
it = ActivationIterator.iterator(ksession);
list = new ArrayList();
for (AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next()) {
list.add(act.getRule().getName() + ":" + act.getDeclarationValue("$s") + ":" + act.isQueued());
}
assertContains(new String[] { "rule1:0:false", "rule1:1:false", "rule1:2:false", "rule1:3:false", "rule1:4:false" }, list);
}
Aggregations