Search in sources :

Example 26 with ClassObjectType

use of org.drools.core.base.ClassObjectType 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 27 with ClassObjectType

use of org.drools.core.base.ClassObjectType 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 28 with ClassObjectType

use of org.drools.core.base.ClassObjectType 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)

Example 29 with ClassObjectType

use of org.drools.core.base.ClassObjectType in project drools by kiegroup.

the class PropertySpecificTest method testBetaWith2BetaSinks.

@Test
public void testBetaWith2BetaSinks() {
    String rule1 = "B(a == 15) @watch(b) A() @watch(i) C()";
    String rule2 = "B(a == 15) @watch(c) A() @watch(j) D()";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode otnB = getObjectTypeNode(kbase, "B");
    Class classType = ((ClassObjectType) otnB.getObjectType()).getClassType();
    List<String> sp = getSettableProperties(wm, otnB);
    AlphaNode alphaNode = (AlphaNode) otnB.getObjectSinkPropagator().getSinks()[0];
    assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode.getInferredMask());
    ObjectTypeNode otnA = getObjectTypeNode(kbase, "A");
    BetaNode betaNodeA1 = (BetaNode) otnA.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNodeA2 = (BetaNode) otnA.getObjectSinkPropagator().getSinks()[1];
    assertEquals(calculatePositiveMask(classType, list("i"), sp), betaNodeA1.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("i"), sp), betaNodeA1.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("b"), sp), betaNodeA1.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), betaNodeA1.getLeftInferredMask());
    assertEquals(calculatePositiveMask(classType, list("j"), sp), betaNodeA2.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("j"), sp), betaNodeA2.getRightInferredMask());
    assertEquals(calculatePositiveMask(classType, list("c"), sp), betaNodeA2.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "c"), sp), betaNodeA2.getLeftInferredMask());
    ObjectTypeNode otnC = getObjectTypeNode(kbase, "C");
    BetaNode betaNodeC = (BetaNode) otnC.getObjectSinkPropagator().getSinks()[0];
    assertEquals(EmptyBitMask.get(), betaNodeC.getRightDeclaredMask());
    assertEquals(EmptyBitMask.get(), betaNodeC.getRightInferredMask());
    assertEquals(AllSetBitMask.get(), betaNodeC.getLeftDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNodeC.getLeftInferredMask());
    ObjectTypeNode otnD = getObjectTypeNode(kbase, "D");
    BetaNode betaNodeD = (BetaNode) otnC.getObjectSinkPropagator().getSinks()[0];
    assertEquals(EmptyBitMask.get(), betaNodeD.getRightDeclaredMask());
    assertEquals(EmptyBitMask.get(), betaNodeD.getRightInferredMask());
    assertEquals(AllSetBitMask.get(), betaNodeD.getLeftDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNodeD.getLeftInferredMask());
    kbase.removeRule("org.drools.compiler.integrationtests", "r1");
    assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), alphaNode.getInferredMask());
}
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 30 with ClassObjectType

use of org.drools.core.base.ClassObjectType in project drools by kiegroup.

the class PropertySpecificTest method testSameBetasWith2RTNSinks.

@Test
public void testSameBetasWith2RTNSinks() {
    String rule1 = "B(a == 15) C() A()";
    String rule2 = "B(a == 15) C() A() @watch(b, c)";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    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 betaNodeC = (BetaNode) otnC.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNodeA1 = (BetaNode) otnA.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNodeA2 = (BetaNode) otnA.getObjectSinkPropagator().getSinks()[1];
    assertSame(betaNodeC.getSinkPropagator().getSinks()[0], betaNodeA1);
    assertSame(betaNodeC.getSinkPropagator().getSinks()[1], betaNodeA2);
    assertSame(betaNodeA1.getLeftTupleSource(), betaNodeC);
    assertSame(betaNodeA2.getLeftTupleSource(), betaNodeC);
    assertEquals(EmptyBitMask.get(), betaNodeC.getRightDeclaredMask());
    assertEquals(EmptyBitMask.get(), betaNodeC.getRightInferredMask());
    assertEquals(EmptyBitMask.get(), betaNodeC.getLeftDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("a"), sp), betaNodeC.getLeftInferredMask());
    assertEquals(EmptyBitMask.get(), betaNodeA1.getRightDeclaredMask());
    assertEquals(EmptyBitMask.get(), betaNodeA1.getRightInferredMask());
    assertEquals(AllSetBitMask.get(), betaNodeA1.getLeftDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNodeA1.getLeftInferredMask());
    assertEquals(calculatePositiveMask(classType, list("b", "c"), sp), betaNodeA2.getRightDeclaredMask());
    assertEquals(calculatePositiveMask(classType, list("b", "c"), sp), betaNodeA2.getRightInferredMask());
    assertEquals(AllSetBitMask.get(), betaNodeA2.getLeftDeclaredMask());
    assertEquals(AllSetBitMask.get(), betaNodeA2.getLeftInferredMask());
    kbase.removeRule("org.drools.compiler.integrationtests", "r0");
    assertEquals(1, betaNodeC.getSinkPropagator().getSinks().length);
}
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

ClassObjectType (org.drools.core.base.ClassObjectType)123 Test (org.junit.Test)76 Pattern (org.drools.core.rule.Pattern)37 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)34 KieBase (org.kie.api.KieBase)32 Declaration (org.drools.core.rule.Declaration)28 ObjectType (org.drools.core.spi.ObjectType)28 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)24 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)23 BetaNode (org.drools.core.reteoo.BetaNode)17 AlphaNode (org.drools.core.reteoo.AlphaNode)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)13 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)13 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)13 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)13 Cheese (org.drools.core.test.model.Cheese)13 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)12 InternalFactHandle (org.drools.core.common.InternalFactHandle)12