Search in sources :

Example 56 with LiaNodeMemory

use of org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory in project drools by kiegroup.

the class SegmentCreationTest method testBranchCESingleSegment.

@Test
public void testBranchCESingleSegment() throws Exception {
    KieBase kbase = buildKnowledgeBase("   $a : A() \n" + "   if ( $a != null ) do[t1] \n" + "   B() \n");
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class);
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
    ConditionalBranchNode cen1Node = (ConditionalBranchNode) liaNode.getSinkPropagator().getSinks()[0];
    JoinNode bNode = (JoinNode) cen1Node.getSinkPropagator().getSinks()[0];
    RuleTerminalNode rtn1 = (RuleTerminalNode) bNode.getSinkPropagator().getSinks()[0];
    FactHandle bFh = wm.insert(new LinkingTest.B());
    wm.flushPropagations();
    LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
    SegmentMemory smem = liaMem.getSegmentMemory();
    assertEquals(1, smem.getAllLinkedMaskTest());
    // B links, but it will not trigger mask
    assertEquals(4, smem.getLinkedNodeMask());
    assertFalse(smem.isSegmentLinked());
    PathMemory pmem = (PathMemory) wm.getNodeMemory(rtn1);
    assertEquals(1, pmem.getAllLinkedMaskTest());
    assertEquals(0, pmem.getLinkedSegmentMask());
    assertFalse(pmem.isRuleLinked());
    wm.insert(new LinkingTest.A());
    wm.flushPropagations();
    // A links in segment
    assertEquals(5, smem.getLinkedNodeMask());
    assertTrue(smem.isSegmentLinked());
    assertEquals(1, pmem.getLinkedSegmentMask());
    assertTrue(pmem.isRuleLinked());
    // retract B does not unlink the rule
    wm.delete(bFh);
    wm.flushPropagations();
    assertEquals(1, pmem.getLinkedSegmentMask());
    assertTrue(pmem.isRuleLinked());
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) FactHandle(org.kie.api.runtime.rule.FactHandle) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ConditionalBranchNode(org.drools.core.reteoo.ConditionalBranchNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) KieBase(org.kie.api.KieBase) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) PathMemory(org.drools.core.reteoo.PathMemory) Test(org.junit.Test)

Aggregations

LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)56 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)50 Test (org.junit.Test)46 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)42 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)42 SegmentMemory (org.drools.core.reteoo.SegmentMemory)36 JoinNode (org.drools.core.reteoo.JoinNode)29 ArrayList (java.util.ArrayList)22 BetaMemory (org.drools.core.reteoo.BetaMemory)22 List (java.util.List)21 KieBase (org.kie.api.KieBase)21 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)20 Match (org.kie.api.runtime.rule.Match)16 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)15 FactHandle (org.kie.api.runtime.rule.FactHandle)10 NotNode (org.drools.core.reteoo.NotNode)9 InternalFactHandle (org.drools.core.common.InternalFactHandle)8 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)8 Arrays.asList (java.util.Arrays.asList)7 RightInputAdapterNode (org.drools.core.reteoo.RightInputAdapterNode)7