Search in sources :

Example 36 with SegmentMemory

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

the class Scenario method run.

public Scenario run() {
    previousResultTuples = bm.getSegmentMemory().getFirst().getStagedLeftTuples();
    actualResultLeftTuples = new TupleSetsImpl<LeftTuple>();
    if (phreakNode == PhreakJoinNode.class) {
        new PhreakJoinNode().doNode((JoinNode) betaNode, sinkNode, bm, wm, leftTuples, actualResultLeftTuples, previousResultTuples);
    } else if (phreakNode == PhreakNotNode.class) {
        new PhreakNotNode().doNode((NotNode) betaNode, sinkNode, bm, wm, leftTuples, actualResultLeftTuples, previousResultTuples);
    } else if (phreakNode == PhreakExistsNode.class) {
        new PhreakExistsNode().doNode((ExistsNode) betaNode, sinkNode, bm, wm, leftTuples, actualResultLeftTuples, previousResultTuples);
    }
    if (expectedResultBuilder != null) {
        assertEquals(expectedResultBuilder.get(), actualResultLeftTuples, expectedResultBuilder.isTestStagedInsert(), expectedResultBuilder.isTestStagedDelete(), expectedResultBuilder.isTestStagedUpdate());
    }
    if (!preStagedBuilders.isEmpty()) {
        for (StagedBuilder stagedBuilder : preStagedBuilders) {
            TupleSets<LeftTuple> expected = stagedBuilder.get();
            TupleSets<LeftTuple> actual = stagedBuilder.getSegmentMemory().getStagedLeftTuples();
            assertEquals(expected, actual, stagedBuilder.isTestStagedInsert(), stagedBuilder.isTestStagedDelete(), stagedBuilder.isTestStagedUpdate());
        }
    }
    SegmentMemory smem = bm.getSegmentMemory();
    SegmentPropagator.propagate(smem, actualResultLeftTuples, wm);
    if (testLeftMemory) {
        equalsLeftMemory(leftMemory);
    }
    if (testRightMemory) {
        equalsRightMemory(rightMemory);
    }
    if (!postStagedBuilders.isEmpty()) {
        for (StagedBuilder stagedBuilder : postStagedBuilders) {
            TupleSets<LeftTuple> expected = stagedBuilder.get();
            TupleSets<LeftTuple> actual = stagedBuilder.getSegmentMemory().getStagedLeftTuples();
            assertEquals(expected, actual, stagedBuilder.isTestStagedInsert(), stagedBuilder.isTestStagedDelete(), stagedBuilder.isTestStagedUpdate());
        }
    }
    return this;
}
Also used : PhreakNotNode(org.drools.core.phreak.PhreakNotNode) NotNode(org.drools.core.reteoo.NotNode) PhreakNotNode(org.drools.core.phreak.PhreakNotNode) SegmentMemory(org.drools.core.reteoo.SegmentMemory) PhreakExistsNode(org.drools.core.phreak.PhreakExistsNode) PhreakJoinNode(org.drools.core.phreak.PhreakJoinNode) LeftTuple(org.drools.core.reteoo.LeftTuple)

Example 37 with SegmentMemory

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

the class ScenarioTest method setupJoinNode.

public void setupJoinNode() {
    buildContext = createContext();
    joinNode = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).setLeftType(A.class).setBinding("object", "$object").setRightType(B.class).setConstraint("object", "!=", "$object").build();
    sinkNode = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode);
    wm = ((StatefulKnowledgeSessionImpl) buildContext.getKnowledgeBase().newKieSession());
    bm = (BetaMemory) wm.getNodeMemory(joinNode);
    bm0 = (BetaMemory) wm.getNodeMemory(sinkNode);
    smem = new SegmentMemory(joinNode);
    bm.setSegmentMemory(smem);
    smem0 = new SegmentMemory(sinkNode);
    bm0.setSegmentMemory(smem0);
    smem.add(smem0);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl)

Example 38 with SegmentMemory

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

the class SegmentPropagationTest method setupJoinNode.

public void setupJoinNode() {
    buildContext = createContext();
    joinNode = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).setLeftType(A.class).setBinding("object", "$object").setRightType(B.class).setConstraint("object", "!=", "$object").build();
    sinkNode0 = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode0);
    sinkNode1 = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode1);
    sinkNode2 = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode2);
    wm = ((StatefulKnowledgeSessionImpl) buildContext.getKnowledgeBase().newKieSession());
    bm = (BetaMemory) wm.getNodeMemory(joinNode);
    bm0 = (BetaMemory) wm.getNodeMemory(sinkNode0);
    bm1 = (BetaMemory) wm.getNodeMemory(sinkNode1);
    bm2 = (BetaMemory) wm.getNodeMemory(sinkNode2);
    smem = new SegmentMemory(joinNode);
    bm.setSegmentMemory(smem);
    smem0 = new SegmentMemory(sinkNode0);
    bm0.setSegmentMemory(smem0);
    smem.add(smem0);
    smem1 = new SegmentMemory(sinkNode1);
    bm1.setSegmentMemory(smem1);
    smem.add(smem1);
    smem2 = new SegmentMemory(sinkNode2);
    bm2.setSegmentMemory(smem2);
    smem.add(smem2);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl)

Example 39 with SegmentMemory

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

the class SegmentPropagationTest method test1.

@Test
public void test1() {
    setupJoinNode();
    JoinNode parentNode = joinNode;
    JoinNode child1Node = new JoinNode();
    JoinNode child2Node = new JoinNode();
    JoinNode child3Node = new JoinNode();
    parentNode.addTupleSink(child1Node);
    parentNode.addTupleSink(child2Node);
    parentNode.addTupleSink(child3Node);
    SegmentMemory smem = new SegmentMemory(parentNode);
    smem.setTipNode(parentNode);
    // @formatter:off
    test().left().insert(a0, a1).right().insert(b0, b1, b2).preStaged(smem0).insert().delete().update().postStaged(smem0).insert(t(a1, b2), t(a1, b0), t(a0, b2), t(a0, b1)).delete().update().postStaged(smem1).insert(t(a0, b1), t(a0, b2), t(a1, b0), t(a1, b2)).delete().update().postStaged(smem2).insert(t(a0, b1), t(a0, b2), t(a1, b0), t(a1, b2)).delete().update().run();
    test().left().update(a0).preStaged(smem0).insert(t(a1, b2), t(a1, b0)).delete().update().postStaged(smem0).insert(t(a0, b2), t(a0, b1), t(a1, b2), t(a1, b0)).delete().update().postStaged(smem1).insert(t(a1, b0), t(a1, b2), t(a0, b1), t(a0, b2)).delete().update().postStaged(smem2).insert(t(a1, b0), t(a1, b2), t(a0, b1), t(a0, b2)).delete().update().run();
    test().right().delete(b2).preStaged(smem0).insert(t(a0, b1), t(a1, b0)).delete().update().postStaged(smem0).insert(t(a0, b1), t(a1, b0)).delete().update().postStaged(smem1).insert(t(a1, b0), t(a0, b1)).postStaged(smem2).insert(t(a1, b0), t(a0, b1)).run();
// @formatter:on
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) JoinNode(org.drools.core.reteoo.JoinNode) PhreakJoinNode(org.drools.core.phreak.PhreakJoinNode) Test(org.junit.Test)

Example 40 with SegmentMemory

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

the class Misc2Test method testBetaMemoryLeakOnSegmentUnlinking.

@Test
@Ignore
public void testBetaMemoryLeakOnSegmentUnlinking() {
    // DROOLS-915
    String drl = "rule R1 when\n" + "    $a : Integer(this == 1)\n" + "    $b : String()\n" + "    $c : Integer(this == 2)\n" + "    $d : Integer(this == 3)\n" + "then \n" + "end\n" + "rule R2 when\n" + "    $a : Integer(this == 1)\n" + "    $b : String()\n" + "then \n" + "end\n";
    KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
    FactHandle fh1 = ksession.insert(1);
    FactHandle fh2 = ksession.insert(2);
    FactHandle fh3 = ksession.insert(3);
    FactHandle fhtest = ksession.insert("test");
    ksession.fireAllRules();
    ksession.delete(fh3);
    ksession.fireAllRules();
    ksession.delete(fh1);
    ksession.delete(fh2);
    ksession.delete(fhtest);
    ksession.fireAllRules();
    NodeMemories nodeMemories = ((InternalWorkingMemory) ksession).getNodeMemories();
    for (int i = 0; i < nodeMemories.length(); i++) {
        Memory memory = nodeMemories.peekNodeMemory(i);
        if (memory != null && memory.getSegmentMemory() != null) {
            SegmentMemory segmentMemory = memory.getSegmentMemory();
            System.out.println(memory);
            LeftTuple deleteFirst = memory.getSegmentMemory().getStagedLeftTuples().getDeleteFirst();
            System.out.println(deleteFirst);
            assertNull(deleteFirst);
        }
    }
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) WorkingMemory(org.drools.core.WorkingMemory) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) Memory(org.drools.core.common.Memory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) NodeMemories(org.drools.core.common.NodeMemories) LeftTuple(org.drools.core.reteoo.LeftTuple) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SegmentMemory (org.drools.core.reteoo.SegmentMemory)67 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)43 PathMemory (org.drools.core.reteoo.PathMemory)30 Test (org.junit.Test)30 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)27 BetaMemory (org.drools.core.reteoo.BetaMemory)23 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)23 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)22 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)18 JoinNode (org.drools.core.reteoo.JoinNode)18 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)18 ArrayList (java.util.ArrayList)16 List (java.util.List)15 Memory (org.drools.core.common.Memory)14 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)12 LeftTuple (org.drools.core.reteoo.LeftTuple)12 Match (org.kie.api.runtime.rule.Match)11 RiaNodeMemory (org.drools.core.reteoo.RightInputAdapterNode.RiaNodeMemory)10 KieBase (org.kie.api.KieBase)10 Arrays.asList (java.util.Arrays.asList)9