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;
}
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);
}
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);
}
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
}
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);
}
}
}
Aggregations