Search in sources :

Example 46 with InternalWorkingMemory

use of org.drools.core.common.InternalWorkingMemory 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 47 with InternalWorkingMemory

use of org.drools.core.common.InternalWorkingMemory in project drools by kiegroup.

the class PropertySpecificTest method testRtnNoConstraintsWithWatches.

@Test
public void testRtnNoConstraintsWithWatches() {
    String rule1 = "A() @watch(a)";
    KieBase kbase = getKnowledgeBase(rule1);
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A");
    assertNotNull(otn);
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
    List<String> sp = getSettableProperties(wm, otn);
    RuleTerminalNode rtNode = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("a"), sp), rtNode.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a"), sp), rtNode.getInferredMask());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ClassObjectType(org.drools.core.base.ClassObjectType) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 48 with InternalWorkingMemory

use of org.drools.core.common.InternalWorkingMemory 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)

Example 49 with InternalWorkingMemory

use of org.drools.core.common.InternalWorkingMemory in project drools by kiegroup.

the class PropertySpecificTest method testBetaWithConstraintsWithNegativeWatches.

@Test
public void testBetaWithConstraintsWithNegativeWatches() {
    String rule1 = "$b : B( a == 15) @watch(c, !a) A( a == 10, b == $b.b ) @watch(s, !a, !b)";
    KieBase kbase = getKnowledgeBase(rule1);
    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 alphaNode = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "s"), sp), alphaNode.getInferredMask());
    BetaNode betaNode = (BetaNode) alphaNode.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("b", "s"), sp), betaNode.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("s"), sp), betaNode.getRightInferredMask());
    assertEquals(calculateNegativeMask(classType, list("!a", "!b"), sp), betaNode.getRightNegativeMask());
    otn = getObjectTypeNode(kbase, "B");
    alphaNode = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode.getInferredMask());
    assertEquals(calculatePositiveMask(classType, list("b", "c"), sp), betaNode.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("b", "c"), sp), betaNode.getLeftInferredMask());
    assertEquals(calculateNegativeMask(classType, list("!a"), sp), betaNode.getLeftNegativeMask());
}
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 50 with InternalWorkingMemory

use of org.drools.core.common.InternalWorkingMemory in project drools by kiegroup.

the class PropertySpecificTest method testBetaWithWatchAfterBeta.

@Test
public void testBetaWithWatchAfterBeta() {
    String rule1 = "$b : B(a == 15) @watch(k) C() A(i == $b.j) @watch(b, c)";
    KieBase kbase = getKnowledgeBase(rule1);
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode otnA = getObjectTypeNode(kbase, "A");
    Class classType = ((ClassObjectType) otnA.getObjectType()).getClassType();
    ObjectTypeNode otnC = getObjectTypeNode(kbase, "C");
    List<String> sp = getSettableProperties(wm, otnA);
    BetaNode betaNodeA = (BetaNode) otnA.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("i", "b", "c"), sp), betaNodeA.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("i", "b", "c"), sp), betaNodeA.getRightInferredMask());
    assertEquals(AllSetBitMask.get(), betaNodeA.getLeftDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNodeA.getLeftInferredMask());
    BetaNode betaNodeC = (BetaNode) otnC.getObjectSinkPropagator().getSinks()[0];
    assertEquals(EmptyBitMask.get(), betaNodeC.getRightDeclaredMask());
    assertEquals(EmptyBitMask.get(), betaNodeC.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("j", "k"), sp), betaNodeC.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "j", "k"), sp), betaNodeC.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) Test(org.junit.Test)

Aggregations

InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)285 Test (org.junit.Test)217 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)140 KieBase (org.kie.api.KieBase)129 ArrayList (java.util.ArrayList)96 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)91 List (java.util.List)76 SegmentMemory (org.drools.core.reteoo.SegmentMemory)74 KieSession (org.kie.api.runtime.KieSession)71 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)69 JoinNode (org.drools.core.reteoo.JoinNode)62 BetaMemory (org.drools.core.reteoo.BetaMemory)57 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)48 PathMemory (org.drools.core.reteoo.PathMemory)48 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)45 BetaNode (org.drools.core.reteoo.BetaNode)44 FactHandle (org.kie.api.runtime.rule.FactHandle)44 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)35 AlphaNode (org.drools.core.reteoo.AlphaNode)35 ClassObjectType (org.drools.core.base.ClassObjectType)30