Search in sources :

Example 21 with LiaNodeMemory

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

the class SegmentCreationTest method testSingleSharedEmptyLhs.

@Test
public void testSingleSharedEmptyLhs() throws Exception {
    KieBase kbase = buildKnowledgeBase(" ", " ");
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode aotn = getObjectTypeNode(kbase, InitialFactImpl.class);
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
    RuleTerminalNode rtn1 = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
    RuleTerminalNode rtn2 = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[1];
    wm.insert(new LinkingTest.A());
    wm.flushPropagations();
    // LiaNode  is in it's own segment
    LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
    SegmentMemory smem = liaMem.getSegmentMemory();
    assertEquals(liaNode, smem.getRootNode());
    assertEquals(liaNode, smem.getTipNode());
    // each RTN is in it's own segment
    SegmentMemory rtnSmem1 = smem.getFirst();
    assertEquals(rtn1, rtnSmem1.getRootNode());
    assertEquals(rtn1, rtnSmem1.getTipNode());
    SegmentMemory rtnSmem2 = rtnSmem1.getNext();
    assertEquals(rtn2, rtnSmem2.getRootNode());
    assertEquals(rtn2, rtnSmem2.getTipNode());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 22 with LiaNodeMemory

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

the class SegmentCreationTest method testSingleSharedPattern.

@Test
public void testSingleSharedPattern() throws Exception {
    KieBase kbase = buildKnowledgeBase("   A() \n", "   A() \n");
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class);
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
    RuleTerminalNode rtn1 = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
    RuleTerminalNode rtn2 = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[1];
    wm.insert(new LinkingTest.A());
    wm.flushPropagations();
    // LiaNode  is in it's own segment
    LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
    SegmentMemory smem = liaMem.getSegmentMemory();
    assertEquals(liaNode, smem.getRootNode());
    assertEquals(liaNode, smem.getTipNode());
    // each RTN is in it's own segment
    SegmentMemory rtnSmem1 = smem.getFirst();
    assertEquals(rtn1, rtnSmem1.getRootNode());
    assertEquals(rtn1, rtnSmem1.getTipNode());
    SegmentMemory rtnSmem2 = rtnSmem1.getNext();
    assertEquals(rtn2, rtnSmem2.getRootNode());
    assertEquals(rtn2, rtnSmem2.getTipNode());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 23 with LiaNodeMemory

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

the class SegmentCreationTest method testSinglePattern.

@Test
public void testSinglePattern() throws Exception {
    KieBase kbase = buildKnowledgeBase("   A() \n");
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class);
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
    RuleTerminalNode rtn = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
    wm.insert(new LinkingTest.A());
    wm.flushPropagations();
    // LiaNode and Rule are in same segment
    LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
    SegmentMemory smem = liaMem.getSegmentMemory();
    assertEquals(liaNode, smem.getRootNode());
    assertEquals(rtn, smem.getTipNode());
    assertNull(smem.getNext());
    assertNull(smem.getFirst());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 24 with LiaNodeMemory

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

the class PhreakQueryNode method doLeftDeletes.

public void doLeftDeletes(QueryElementNodeMemory qmem, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
    for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        InternalFactHandle fh = (InternalFactHandle) leftTuple.getContextObject();
        DroolsQuery dquery = (DroolsQuery) fh.getObject();
        if (dquery.isOpen()) {
            LeftInputAdapterNode lian = (LeftInputAdapterNode) qmem.getQuerySegmentMemory().getRootNode();
            LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
            // there is only one, all other LTs are peers
            LeftTuple childLeftTuple = fh.getFirstLeftTuple();
            LeftInputAdapterNode.doDeleteObject(childLeftTuple, childLeftTuple.getPropagationContext(), qmem.getQuerySegmentMemory(), wm, lian, false, lm);
        } else {
            LeftTuple childLeftTuple = leftTuple.getFirstChild();
            while (childLeftTuple != null) {
                LeftTuple nextChild = childLeftTuple.getHandleNext();
                RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
                childLeftTuple = nextChild;
            }
        }
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle) LeftTuple(org.drools.core.reteoo.LeftTuple) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) DroolsQuery(org.drools.core.base.DroolsQuery) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 25 with LiaNodeMemory

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

the class AddRuleTest method testPopulatedSingleRuleNoSharingWithSubnetworkAtStart.

@Test
public void testPopulatedSingleRuleNoSharingWithSubnetworkAtStart() throws Exception {
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
    wm.insert(new A(1));
    wm.insert(new A(2));
    wm.insert(new D(1));
    wm.insert(new E(1));
    wm.insert(new C(2));
    wm.fireAllRules();
    kbase.addPackages(buildKnowledgePackage("r1", "   A() not( B() and C() ) D() E()\n"));
    List list = new ArrayList();
    wm.setGlobal("list", list);
    ObjectTypeNode aotn = getObjectTypeNode(kbase, A.class);
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
    LiaNodeMemory lm = (LiaNodeMemory) wm.getNodeMemory(liaNode);
    SegmentMemory sm = lm.getSegmentMemory();
    assertNull(sm.getStagedLeftTuples().getInsertFirst());
    SegmentMemory subSm = sm.getFirst();
    SegmentMemory mainSm = subSm.getNext();
    assertNotNull(subSm.getStagedLeftTuples().getInsertFirst());
    assertNotNull(subSm.getStagedLeftTuples().getInsertFirst().getStagedNext());
    assertNull(subSm.getStagedLeftTuples().getInsertFirst().getStagedNext().getStagedNext());
    assertNotNull(mainSm.getStagedLeftTuples().getInsertFirst());
    assertNotNull(mainSm.getStagedLeftTuples().getInsertFirst().getStagedNext());
    assertNull(mainSm.getStagedLeftTuples().getInsertFirst().getStagedNext().getStagedNext());
    wm.fireAllRules();
    assertNull(subSm.getStagedLeftTuples().getInsertFirst());
    assertNull(mainSm.getStagedLeftTuples().getInsertFirst());
    assertEquals(2, list.size());
    assertEquals("r1", ((Match) list.get(0)).getRule().getName());
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) ArrayList(java.util.ArrayList) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) Match(org.kie.api.runtime.rule.Match) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) Test(org.junit.Test)

Aggregations

LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)29 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)26 Test (org.junit.Test)24 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)22 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)22 SegmentMemory (org.drools.core.reteoo.SegmentMemory)19 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)15 JoinNode (org.drools.core.reteoo.JoinNode)15 ArrayList (java.util.ArrayList)11 List (java.util.List)11 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)11 BetaMemory (org.drools.core.reteoo.BetaMemory)10 KieBase (org.kie.api.KieBase)9 Match (org.kie.api.runtime.rule.Match)8 NotNode (org.drools.core.reteoo.NotNode)5 FactHandle (org.kie.api.runtime.rule.FactHandle)5 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)5 Arrays.asList (java.util.Arrays.asList)4 InternalFactHandle (org.drools.core.common.InternalFactHandle)4 RightInputAdapterNode (org.drools.core.reteoo.RightInputAdapterNode)4