Search in sources :

Example 1 with DebugAgendaEventListener

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));
}
Also used : DebugAgendaEventListener(org.drools.core.event.DebugAgendaEventListener) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) Neighbor(org.drools.mvel.compiler.Neighbor) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Cell(org.drools.mvel.compiler.Cell) Test(org.junit.Test)

Example 2 with DebugAgendaEventListener

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));
}
Also used : DebugAgendaEventListener(org.drools.core.event.DebugAgendaEventListener) FactHandle(org.kie.api.runtime.rule.FactHandle) ArrayList(java.util.ArrayList) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 3 with DebugAgendaEventListener

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));
}
Also used : DebugAgendaEventListener(org.drools.core.event.DebugAgendaEventListener) Neighbor(org.drools.compiler.Neighbor) ArrayList(java.util.ArrayList) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Cell(org.drools.compiler.Cell) Test(org.junit.Test)

Example 4 with DebugAgendaEventListener

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;
}
Also used : DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) DebugAgendaEventListener(org.drools.core.event.DebugAgendaEventListener) DebugRuleRuntimeEventListener(org.drools.core.event.DebugRuleRuntimeEventListener) KieSession(org.kie.api.runtime.KieSession)

Example 5 with DebugAgendaEventListener

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));
}
Also used : DebugAgendaEventListener(org.drools.core.event.DebugAgendaEventListener) HashMap(java.util.HashMap) FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Aggregations

DebugAgendaEventListener (org.drools.core.event.DebugAgendaEventListener)6 KieSession (org.kie.api.runtime.KieSession)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 KieBase (org.kie.api.KieBase)3 HashMap (java.util.HashMap)2 FactHandle (org.kie.api.runtime.rule.FactHandle)2 KieHelper (org.kie.internal.utils.KieHelper)2 Cell (org.drools.compiler.Cell)1 Neighbor (org.drools.compiler.Neighbor)1 Person (org.drools.compiler.Person)1 DebugProcessEventListener (org.drools.core.event.DebugProcessEventListener)1 DebugRuleRuntimeEventListener (org.drools.core.event.DebugRuleRuntimeEventListener)1 Cell (org.drools.mvel.compiler.Cell)1 Neighbor (org.drools.mvel.compiler.Neighbor)1 Person (org.drools.mvel.compiler.Person)1 Person (org.drools.testcoverage.common.model.Person)1