use of org.drools.core.event.DebugAgendaEventListener in project drools by kiegroup.
the class PropertyReactivityBlockerTest method testUpdateRewrittenWithCorrectBitMaskAndCorrectClass.
@Test()
public void testUpdateRewrittenWithCorrectBitMaskAndCorrectClass() {
String drl = "import " + Cell.class.getCanonicalName() + ";\n" + "import " + Neighbor.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R when\n" + " Neighbor( $n : neighbor ) \n" + "then\n" + " modify( $n ) {\n" + " setValue( $n.getValue() + 1 )\n" + " }\n" + "end\n" + "rule C when\n" + " $c: Cell( value > 0 ) \n" + "then\n" + " list.add(\"C\"); \n" + "end\n";
/* The RHS was wrongly rewritten as:
{ org.kie.api.runtime.rule.FactHandle $n__Handle2__ = drools.getFactHandle($n);
$n.setValue( $n.getValue() + 1 );
drools.update( $n__Handle2__, org.drools.core.util.bitmask.EmptyBitMask.get(), org.drools.mvel.compiler.Neighbor.class ); }
instead of:
{ org.kie.api.runtime.rule.FactHandle $n__Handle2__ = drools.getFactHandle($n);
$n.setValue( $n.getValue() + 1 );
drools.update( $n__Handle2__, new org.drools.core.util.bitmask.LongBitMask(16L), org.drools.mvel.compiler.Cell.class ); }
*/
// making the default explicit:
Map<String, String> kieModuleConfigurationProperties = new HashMap<>();
kieModuleConfigurationProperties.put("drools.propertySpecific", "ALWAYS");
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, kieModuleConfigurationProperties, drl);
final KieSession ksession = kbase.newKieSession();
System.out.println(drl);
ReteDumper.dumpRete(ksession);
ksession.addEventListener(new DebugAgendaEventListener());
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
Cell c0 = new Cell(0);
Cell c1 = new Cell(0);
Neighbor n = new Neighbor(c0, c1);
System.out.println("c0: " + c0);
System.out.println("c1: " + c1);
System.out.println("n:" + n);
ksession.insert(c0);
ksession.insert(c1);
ksession.insert(n);
int x = ksession.fireAllRules();
System.out.println("from outside:");
System.out.println("c0: " + c0);
System.out.println("c1: " + c1);
System.out.println("n:" + n);
assertEquals(1, list.size());
assertEquals("C", list.get(0));
}
use of org.drools.core.event.DebugAgendaEventListener in project drools by kiegroup.
the class PropertyReactivityBlockerTest method testAbis_NotWorking.
@Test()
public void testAbis_NotWorking() {
// DROOLS-644
String drl = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R when\n" + " $p1 : Person( name == \"Mario\" ) \n" + " $p2 : Person( age > $p1.age ) \n" + "then\n" + " list.add(\"t0\");\n" + "end\n" + "rule Z when\n" + " $p1 : Person( name == \"Mario\" ) \n" + "then\n" + " modify($p1) { setAge(35); } \n" + "end\n";
// making the default explicit:
KieSession ksession = new KieHelper(PropertySpecificOption.ALWAYS).addContent(drl, ResourceType.DRL).build().newKieSession();
ksession.addEventListener(new DebugAgendaEventListener());
System.out.println(drl);
ReteDumper.dumpRete(ksession);
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
Person mario = new Person("Mario", 40);
Person mark = new Person("Mark", 37);
FactHandle fh_mario = ksession.insert(mario);
ksession.insert(mark);
int x = ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("t0", list.get(0));
}
use of org.drools.core.event.DebugAgendaEventListener in project drools by kiegroup.
the class PropertyReactivityBlockerTest method testUpdateRewrittenWithCorrectBitMaskAndCorrectClass.
@Test()
public void testUpdateRewrittenWithCorrectBitMaskAndCorrectClass() {
String drl = "import " + Cell.class.getCanonicalName() + ";\n" + "import " + Neighbor.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R when\n" + " Neighbor( $n : neighbor ) \n" + "then\n" + " modify( $n ) {\n" + " setValue( $n.getValue() + 1 )\n" + " }\n" + "end\n" + "rule C when\n" + " $c: Cell( value > 0 ) \n" + "then\n" + " list.add(\"C\"); \n" + "end\n";
/* The RHS was wrongly rewritten as:
{ org.kie.api.runtime.rule.FactHandle $n__Handle2__ = drools.getFactHandle($n);
$n.setValue( $n.getValue() + 1 );
drools.update( $n__Handle2__, org.drools.core.util.bitmask.EmptyBitMask.get(), org.drools.compiler.Neighbor.class ); }
instead of:
{ org.kie.api.runtime.rule.FactHandle $n__Handle2__ = drools.getFactHandle($n);
$n.setValue( $n.getValue() + 1 );
drools.update( $n__Handle2__, new org.drools.core.util.bitmask.LongBitMask(16L), org.drools.compiler.Cell.class ); }
*/
// making the default explicit:
KieSession ksession = new KieHelper(PropertySpecificOption.ALWAYS).addContent(drl, ResourceType.DRL).build().newKieSession();
System.out.println(drl);
ReteDumper.dumpRete(ksession);
ksession.addEventListener(new DebugAgendaEventListener());
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
Cell c0 = new Cell(0);
Cell c1 = new Cell(0);
Neighbor n = new Neighbor(c0, c1);
System.out.println("c0: " + c0);
System.out.println("c1: " + c1);
System.out.println("n:" + n);
ksession.insert(c0);
ksession.insert(c1);
ksession.insert(n);
int x = ksession.fireAllRules();
System.out.println("from outside:");
System.out.println("c0: " + c0);
System.out.println("c1: " + c1);
System.out.println("n:" + n);
assertEquals(1, list.size());
assertEquals("C", list.get(0));
}
use of org.drools.core.event.DebugAgendaEventListener in project duangframework by tcrct.
the class KieSessionHolder method kieSession.
public KieSession kieSession() {
if (ToolsKit.isEmpty(kieContainer)) {
init();
}
KieSession session = kieContainer.newKieSession();
session.addEventListener(new DebugRuleRuntimeEventListener());
session.addEventListener(new DebugProcessEventListener());
session.addEventListener(new DebugAgendaEventListener());
return session;
}
use of org.drools.core.event.DebugAgendaEventListener in project drools by kiegroup.
the class PropertyReactivityBlockerTest method testAbis_NotWorking.
@Test()
public void testAbis_NotWorking() {
// DROOLS-644
String drl = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R when\n" + " $p1 : Person( name == \"Mario\" ) \n" + " $p2 : Person( age > $p1.age ) \n" + "then\n" + " list.add(\"t0\");\n" + "end\n" + "rule Z when\n" + " $p1 : Person( name == \"Mario\" ) \n" + "then\n" + " modify($p1) { setAge(35); } \n" + "end\n";
// making the default explicit:
Map<String, String> kieModuleConfigurationProperties = new HashMap<>();
kieModuleConfigurationProperties.put("drools.propertySpecific", "ALWAYS");
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, kieModuleConfigurationProperties, drl);
final KieSession ksession = kbase.newKieSession();
ksession.addEventListener(new DebugAgendaEventListener());
System.out.println(drl);
ReteDumper.dumpRete(ksession);
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
Person mario = new Person("Mario", 40);
Person mark = new Person("Mark", 37);
FactHandle fh_mario = ksession.insert(mario);
ksession.insert(mark);
int x = ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("t0", list.get(0));
}
Aggregations