use of org.drools.core.impl.InternalKnowledgeBase in project drools by kiegroup.
the class RemoveRuleTest method testPopulatedMultipleSharesRemoveFirst.
@Test
public void testPopulatedMultipleSharesRemoveFirst() throws Exception {
InternalKnowledgeBase kbase1 = buildKnowledgeBase("r1", " A(1;) A(2;) B(1;) B(2;) C(1;) D() E()\n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase1.newKieSession());
List list = new ArrayList();
wm.setGlobal("list", list);
InternalFactHandle fh1 = (InternalFactHandle) wm.insert(new A(1));
InternalFactHandle fh2 = (InternalFactHandle) wm.insert(new A(2));
InternalFactHandle fh3 = (InternalFactHandle) wm.insert(new A(2));
InternalFactHandle fh4 = (InternalFactHandle) wm.insert(new A(3));
InternalFactHandle fh5 = (InternalFactHandle) wm.insert(new B(1));
InternalFactHandle fh6 = (InternalFactHandle) wm.insert(new B(2));
InternalFactHandle fh7 = (InternalFactHandle) wm.insert(new C(1));
InternalFactHandle fh8 = (InternalFactHandle) wm.insert(new C(2));
InternalFactHandle fh9 = (InternalFactHandle) wm.insert(new D(1));
InternalFactHandle fh10 = (InternalFactHandle) wm.insert(new E(1));
wm.fireAllRules();
assertEquals(2, list.size());
kbase1.addPackages(buildKnowledgePackage("r2", " A(1;) A(2;) B(1;) B(2;) C(2;) D() E()\n"));
kbase1.addPackages(buildKnowledgePackage("r3", " A(1;) A(3;) B(1;) B(2;) C(2;) D() E()\n"));
wm.fireAllRules();
assertEquals(5, list.size());
kbase1.removeRule("org.kie", "r1");
list.clear();
wm.update(fh1, fh1.getObject());
wm.update(fh2, fh2.getObject());
wm.update(fh3, fh3.getObject());
wm.update(fh4, fh4.getObject());
wm.update(fh5, fh5.getObject());
wm.update(fh6, fh6.getObject());
wm.update(fh7, fh7.getObject());
wm.update(fh8, fh8.getObject());
wm.update(fh9, fh9.getObject());
wm.update(fh10, fh10.getObject());
wm.fireAllRules();
assertEquals(3, list.size());
}
use of org.drools.core.impl.InternalKnowledgeBase in project drools by kiegroup.
the class RemoveRuleTest method testPathMemorySizeAfterSegmentMergeNonInitialized.
@Test
public void testPathMemorySizeAfterSegmentMergeNonInitialized() throws Exception {
InternalKnowledgeBase kbase1 = buildKnowledgeBase("r1", " A(1;) B(1;)\n");
kbase1.addPackages(buildKnowledgePackage("r2", " A(1;)\n"));
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase1.newKieSession());
RuleTerminalNode rtn1 = getRtn("org.kie.r1", kbase1);
RuleTerminalNode rtn2 = getRtn("org.kie.r2", kbase1);
assertEquals(2, wm.getNodeMemory(rtn1).getSegmentMemories().length);
assertEquals(2, wm.getNodeMemory(rtn2).getSegmentMemories().length);
kbase1.removeRule("org.kie", "r2");
assertEquals(1, wm.getNodeMemory(rtn1).getSegmentMemories().length);
}
use of org.drools.core.impl.InternalKnowledgeBase in project drools by kiegroup.
the class RemoveRuleTest method testPopulatedSharedLiaNodeNoBeta.
@Test
public void testPopulatedSharedLiaNodeNoBeta() throws Exception {
InternalKnowledgeBase kbase1 = buildKnowledgeBase("r1", " A()\n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase1.newKieSession());
List list = new ArrayList();
wm.setGlobal("list", list);
A a1 = new A(1);
InternalFactHandle fh1 = (InternalFactHandle) wm.insert(a1);
A a2 = new A(2);
InternalFactHandle fh2 = (InternalFactHandle) wm.insert(a2);
wm.fireAllRules();
assertEquals(2, list.size());
kbase1.addPackages(buildKnowledgePackage("r2", " a : A()\n"));
wm.fireAllRules();
assertEquals(4, list.size());
kbase1.removeRule("org.kie", "r1");
kbase1.removeRule("org.kie", "r2");
list.clear();
assertNull(fh1.getFirstLeftTuple());
assertNull(fh2.getFirstLeftTuple());
wm.update(fh1, a1);
wm.update(fh2, a2);
wm.fireAllRules();
assertEquals(0, list.size());
}
use of org.drools.core.impl.InternalKnowledgeBase in project drools by kiegroup.
the class RemoveRuleTest method testSplitTwoBeforeCreatedSegment.
@Test
public void testSplitTwoBeforeCreatedSegment() throws Exception {
InternalKnowledgeBase kbase1 = buildKnowledgeBase("r1", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) D(1;) D(2;) E(1;) E(2;)\n");
kbase1.addPackages(buildKnowledgePackage("r2", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) D(1;) D(2;) E(1;) E(2;)\n"));
kbase1.addPackages(buildKnowledgePackage("r3", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) D(1;) D(2;)\n"));
kbase1.addPackages(buildKnowledgePackage("r4", " A(1;) A(2;) B(1;) B(2;) C(1;) C(2;) \n"));
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase1.newKieSession());
List list = new ArrayList();
wm.setGlobal("list", list);
wm.insert(new E(1));
wm.insert(new E(2));
wm.flushPropagations();
RuleTerminalNode rtn1 = getRtn("org.kie.r1", kbase1);
RuleTerminalNode rtn2 = getRtn("org.kie.r2", kbase1);
RuleTerminalNode rtn3 = getRtn("org.kie.r3", kbase1);
RuleTerminalNode rtn4 = getRtn("org.kie.r4", kbase1);
PathMemory pm1 = (PathMemory) wm.getNodeMemory(rtn1);
SegmentMemory[] smems = pm1.getSegmentMemories();
assertEquals(4, smems.length);
assertNull(smems[0]);
assertNull(smems[1]);
assertNull(smems[3]);
SegmentMemory sm = smems[2];
assertEquals(2, sm.getPos());
assertEquals(4, sm.getSegmentPosMaskBit());
assertEquals(4, pm1.getLinkedSegmentMask());
kbase1.addPackages(buildKnowledgePackage("r5", " A(1;) A(2;) B(1;) B(2;) \n"));
smems = pm1.getSegmentMemories();
assertEquals(5, smems.length);
assertNull(smems[0]);
assertNull(smems[1]);
assertNull(smems[2]);
sm = smems[3];
assertEquals(3, sm.getPos());
assertEquals(8, sm.getSegmentPosMaskBit());
assertEquals(8, pm1.getLinkedSegmentMask());
RuleTerminalNode rtn5 = getRtn("org.kie.r5", kbase1);
PathMemory pm5 = (PathMemory) wm.getNodeMemory(rtn5);
smems = pm5.getSegmentMemories();
assertEquals(2, smems.length);
assertNull(smems[0]);
assertNull(smems[1]);
}
use of org.drools.core.impl.InternalKnowledgeBase in project drools by kiegroup.
the class RemoveRuleTest method testPopulatedRuleMidwayShare.
@Test
public void testPopulatedRuleMidwayShare() throws Exception {
InternalKnowledgeBase kbase1 = buildKnowledgeBase("r1", " A() B() C(1;) D() E()\n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase1.newKieSession());
List list = new ArrayList();
wm.setGlobal("list", list);
wm.insert(new A(1));
wm.insert(new A(2));
wm.insert(new A(3));
wm.insert(new B(1));
wm.insert(new C(1));
wm.insert(new C(2));
wm.insert(new D(1));
wm.insert(new E(1));
wm.fireAllRules();
assertEquals(7, countNodeMemories(wm.getNodeMemories()));
kbase1.addPackages(buildKnowledgePackage("r2", " a : A() B() C(2;) D() E()\n"));
wm.fireAllRules();
ObjectTypeNode aotn = getObjectTypeNode(kbase1, A.class);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
JoinNode bNode = (JoinNode) liaNode.getSinkPropagator().getFirstLeftTupleSink();
JoinNode c1Node = (JoinNode) bNode.getSinkPropagator().getFirstLeftTupleSink();
JoinNode c2Node = (JoinNode) bNode.getSinkPropagator().getLastLeftTupleSink();
LiaNodeMemory lm = (LiaNodeMemory) wm.getNodeMemory(liaNode);
SegmentMemory sm = lm.getSegmentMemory();
BetaMemory c1Mem = (BetaMemory) wm.getNodeMemory(c1Node);
assertSame(sm.getFirst(), c1Mem.getSegmentMemory());
assertEquals(3, c1Mem.getLeftTupleMemory().size());
assertEquals(1, c1Mem.getRightTupleMemory().size());
BetaMemory c2Mem = (BetaMemory) wm.getNodeMemory(c2Node);
SegmentMemory c2Smem = sm.getFirst().getNext();
assertSame(c2Smem, c2Mem.getSegmentMemory());
assertEquals(3, c2Mem.getLeftTupleMemory().size());
assertEquals(1, c2Mem.getRightTupleMemory().size());
assertEquals(6, list.size());
kbase1.removeRule("org.kie", "r2");
assertEquals(10, countNodeMemories(wm.getNodeMemories()));
assertNull(sm.getFirst());
// c1SMem repoints back to original Smem
assertSame(sm, c1Mem.getSegmentMemory());
wm.insert(new A(1));
wm.fireAllRules();
assertEquals("r1", ((Match) list.get(6)).getRule().getName());
// only one more added, as second rule as removed
assertEquals(7, list.size());
}
Aggregations