Search in sources :

Example 11 with BetaNode

use of org.drools.core.reteoo.BetaNode in project drools by kiegroup.

the class PropertySpecificTest method testSharedAlphanodeWithBetaNodeConstraintsNoPropertySpecific.

@Test
public void testSharedAlphanodeWithBetaNodeConstraintsNoPropertySpecific() {
    String rule = "package org.drools.compiler.integrationtests\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Cheese.class.getCanonicalName() + "\n" + "rule r1\n" + "when\n" + "   Person()\n" + "   Cheese( type == 'brie', price == 1.5 )\n" + "then\n" + "end\n" + "rule r2\n" + "when\n" + "   Person()\n" + "   Cheese( type == 'brie', price == 2.5 )\n" + "then\n" + "end\n";
    KieBase kbase = new KieHelper(PropertySpecificOption.ALLOWED).addContent(rule, ResourceType.DRL).build();
    ObjectTypeNode otn = getObjectTypeNode(kbase, "Cheese");
    assertNotNull(otn);
    AlphaNode alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals(AllSetBitMask.get(), alphaNode1.getDeclaredMask());
    assertEquals(AllSetBitMask.get(), alphaNode1.getInferredMask());
    // first share
    AlphaNode alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals(AllSetBitMask.get(), alphaNode1_1.getDeclaredMask());
    assertEquals(AllSetBitMask.get(), alphaNode1_1.getInferredMask());
    BetaNode betaNode1 = (BetaNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals(AllSetBitMask.get(), betaNode1.getRightDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNode1.getRightInferredMask());
    // second share
    AlphaNode alphaNode1_2 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals(AllSetBitMask.get(), alphaNode1_2.getDeclaredMask());
    assertEquals(AllSetBitMask.get(), alphaNode1_2.getInferredMask());
    BetaNode betaNode2 = (BetaNode) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals(AllSetBitMask.get(), betaNode2.getRightDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNode2.getRightInferredMask());
}
Also used : BetaNode(org.drools.core.reteoo.BetaNode) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) KieHelper(org.kie.internal.utils.KieHelper) Person(org.drools.compiler.Person) AlphaNode(org.drools.core.reteoo.AlphaNode) Test(org.junit.Test)

Example 12 with BetaNode

use of org.drools.core.reteoo.BetaNode in project drools by kiegroup.

the class PropertySpecificTest method testComplexBetaSharedAlphaWithWatchesRemoveR2.

@Test
public void testComplexBetaSharedAlphaWithWatchesRemoveR2() {
    String rule1 = "$b : B( b == 15) @watch(i) A( a == 10, b == 15 ) @watch(c)";
    String rule2 = "$b : B( b == 15) @watch(j) A( a == 10, i == 20 ) @watch(s)";
    String rule3 = "$b : B( c == 15) @watch(k) A( a == 10, i == 20, b == 10 ) @watch(j)";
    KieBase kbase = getKnowledgeBase(rule1, rule2, rule3);
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    kbase.removeRule("org.drools.compiler.integrationtests", "r1");
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A");
    assertNotNull(otn);
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();
    List<String> sp = getSettableProperties(wm, otn);
    AlphaNode alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c", "i", "j"), sp), alphaNode1.getInferredMask());
    // first split
    AlphaNode alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask());
    BetaNode betaNode1 = (BetaNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("c"), sp), betaNode1.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), betaNode1.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("i"), sp), betaNode1.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("b", "i"), sp), betaNode1.getLeftInferredMask());
    // fist share, second alpha
    AlphaNode alphaNode1_2 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals(calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), alphaNode1_2.getInferredMask());
    AlphaNode alphaNode1_3 = (AlphaNode) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_3.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), alphaNode1_3.getInferredMask());
    BetaNode betaNode2 = (BetaNode) alphaNode1_3.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("j"), sp), betaNode2.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), betaNode2.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("k"), sp), betaNode2.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("c", "k"), sp), betaNode2.getLeftInferredMask());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) BetaNode(org.drools.core.reteoo.BetaNode) ClassObjectType(org.drools.core.base.ClassObjectType) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) AlphaNode(org.drools.core.reteoo.AlphaNode) Test(org.junit.Test)

Example 13 with BetaNode

use of org.drools.core.reteoo.BetaNode in project drools by kiegroup.

the class PropertySpecificTest method testPersonFactBetaNodeWithRightInputAdapter.

@Test
public void testPersonFactBetaNodeWithRightInputAdapter() {
    String rule = "package org.drools.compiler.integrationtests\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Cheese.class.getCanonicalName() + "\n" + "rule r1\n" + "when\n" + "   Person()\n" + "   exists(eval(1==1))\n" + "then\n" + "end\n";
    // assumption is this test was intended to be for the case
    // property reactivity is NOT enabled by default.
    KieBase kbase = new KieHelper(PropertySpecificOption.ALLOWED).addContent(rule, ResourceType.DRL).build();
    ObjectTypeNode otn = getObjectTypeNode(kbase, "Person");
    assertNotNull(otn);
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNode = (BetaNode) liaNode.getSinkPropagator().getSinks()[1];
    assertEquals(AllSetBitMask.get(), betaNode.getLeftDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNode.getLeftInferredMask());
    assertEquals(AllSetBitMask.get(), betaNode.getRightDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNode.getRightInferredMask());
}
Also used : BetaNode(org.drools.core.reteoo.BetaNode) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) KieHelper(org.kie.internal.utils.KieHelper) Person(org.drools.compiler.Person) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) Test(org.junit.Test)

Example 14 with BetaNode

use of org.drools.core.reteoo.BetaNode in project drools by kiegroup.

the class PropertySpecificTest method testComplexBetaSharedAlphaWithWatches.

@Test
public void testComplexBetaSharedAlphaWithWatches() {
    String rule1 = "$b : B( b == 15) @watch(i) A( a == 10, b == 15 ) @watch(c)";
    String rule2 = "$b : B( b == 15) @watch(j) A( a == 10, i == 20 ) @watch(s)";
    String rule3 = "$b : B( c == 15) @watch(k) A( a == 10, i == 20, b == 10 ) @watch(j)";
    KieBase kbase = getKnowledgeBase(rule1, rule2, rule3);
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A");
    assertNotNull(otn);
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();
    List<String> sp = getSettableProperties(wm, otn);
    AlphaNode alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c", "s", "i", "j"), sp), alphaNode1.getInferredMask());
    // first share
    AlphaNode alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask());
    BetaNode betaNode1 = (BetaNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("c"), sp), betaNode1.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), betaNode1.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("i"), sp), betaNode1.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("b", "i"), sp), betaNode1.getLeftInferredMask());
    // second share
    AlphaNode alphaNode1_2 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals(calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "i", "s", "j"), sp), alphaNode1_2.getInferredMask());
    BetaNode betaNode2 = (BetaNode) alphaNode1_2.getObjectSinkPropagator().getSinks()[1];
    assertEquals(calculatePositiveMask(classType, list("s"), sp), betaNode2.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "i", "s"), sp), betaNode2.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("j"), sp), betaNode2.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("b", "j"), sp), betaNode2.getLeftInferredMask());
    // third share
    AlphaNode alphaNode1_4 = (AlphaNode) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_4.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "i", "j"), sp), alphaNode1_4.getInferredMask());
    BetaNode betaNode3 = (BetaNode) alphaNode1_4.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("j"), sp), betaNode3.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), betaNode3.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("k"), sp), betaNode3.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("c", "k"), sp), betaNode3.getLeftInferredMask());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) BetaNode(org.drools.core.reteoo.BetaNode) ClassObjectType(org.drools.core.base.ClassObjectType) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) AlphaNode(org.drools.core.reteoo.AlphaNode) Test(org.junit.Test)

Example 15 with BetaNode

use of org.drools.core.reteoo.BetaNode in project drools by kiegroup.

the class PropertySpecificTest method testBetaNoConstraintsNoWatches.

@Test
public void testBetaNoConstraintsNoWatches() {
    String rule1 = "B() A()";
    KieBase kbase = getKnowledgeBase(rule1);
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A");
    assertNotNull(otn);
    BetaNode betaNode = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals(EmptyBitMask.get(), betaNode.getRightDeclaredMask());
    assertEquals(EmptyBitMask.get(), betaNode.getRightInferredMask());
    assertEquals(EmptyBitMask.get(), betaNode.getLeftDeclaredMask());
    assertEquals(EmptyBitMask.get(), betaNode.getLeftInferredMask());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) BetaNode(org.drools.core.reteoo.BetaNode) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) Test(org.junit.Test)

Aggregations

BetaNode (org.drools.core.reteoo.BetaNode)38 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)26 Test (org.junit.Test)25 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)23 KieBase (org.kie.api.KieBase)23 ClassObjectType (org.drools.core.base.ClassObjectType)17 AlphaNode (org.drools.core.reteoo.AlphaNode)13 BetaMemory (org.drools.core.reteoo.BetaMemory)11 RightInputAdapterNode (org.drools.core.reteoo.RightInputAdapterNode)7 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)6 KieHelper (org.kie.internal.utils.KieHelper)6 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)5 LeftTuple (org.drools.core.reteoo.LeftTuple)5 RightTuple (org.drools.core.reteoo.RightTuple)5 Person (org.drools.compiler.Person)4 InternalFactHandle (org.drools.core.common.InternalFactHandle)4 Memory (org.drools.core.common.Memory)4 ArrayList (java.util.ArrayList)3 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)3