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