use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class RuleTerminalNodeVisitor method doVisit.
@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
RuleTerminalNode rtn = (RuleTerminalNode) node;
RuleImpl rule = rtn.getRule();
// first thing, associate all nodes belonging to this rule
for (NetworkNode snode : nodeStack) {
info.assign(snode, rule);
}
final DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo(node);
ni.setMemoryEnabled(false);
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class LinkingTest method testNotNodeMasksWithoutConstraints.
@Test
public void testNotNodeMasksWithoutConstraints() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "import " + F.class.getCanonicalName() + "\n";
str += "import " + G.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
str += "rule rule1 when \n";
str += " A() \n";
str += " not( B( ) ) \n";
str += " C() \n";
str += "then \n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
ObjectTypeNode node = getObjectTypeNode(kbase, A.class);
InternalWorkingMemory wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getObjectSinkPropagator().getSinks()[0];
assertEquals(1, liaNode.getSinkPropagator().size());
wm.insert(new A());
wm.flushPropagations();
NotNode notNode = (NotNode) liaNode.getSinkPropagator().getSinks()[0];
JoinNode cNode = (JoinNode) notNode.getSinkPropagator().getSinks()[0];
RuleTerminalNode rtn = (RuleTerminalNode) cNode.getSinkPropagator().getSinks()[0];
PathMemory pmem = (PathMemory) wm.getNodeMemory(rtn);
assertEquals(1, pmem.getSegmentMemories().length);
assertEquals(1, pmem.getAllLinkedMaskTest());
SegmentMemory sm = pmem.getSegmentMemories()[0];
assertEquals(7, sm.getAllLinkedMaskTest());
assertEquals(3, sm.getLinkedNodeMask());
assertFalse(sm.isSegmentLinked());
assertFalse(pmem.isRuleLinked());
wm.insert(new C());
wm.flushPropagations();
assertEquals(7, sm.getLinkedNodeMask());
assertTrue(sm.isSegmentLinked());
assertTrue(pmem.isRuleLinked());
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class LinkingTest method testNotNodeMasksWithConstraints.
@Test
public void testNotNodeMasksWithConstraints() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "import " + F.class.getCanonicalName() + "\n";
str += "import " + G.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
str += "rule rule1 when \n";
str += " $a : A() \n";
str += " not( B( value == $a.value ) ) \n";
str += " C() \n";
str += "then \n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
ObjectTypeNode node = getObjectTypeNode(kbase, A.class);
InternalWorkingMemory wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getObjectSinkPropagator().getSinks()[0];
assertEquals(1, liaNode.getSinkPropagator().size());
wm.insert(new A());
wm.flushPropagations();
NotNode notNode = (NotNode) liaNode.getSinkPropagator().getSinks()[0];
JoinNode cNode = (JoinNode) notNode.getSinkPropagator().getSinks()[0];
RuleTerminalNode rtn = (RuleTerminalNode) cNode.getSinkPropagator().getSinks()[0];
PathMemory pmem = (PathMemory) wm.getNodeMemory(rtn);
assertEquals(1, pmem.getSegmentMemories().length);
assertEquals(1, pmem.getAllLinkedMaskTest());
SegmentMemory sm = pmem.getSegmentMemories()[0];
assertEquals(5, sm.getAllLinkedMaskTest());
assertEquals(3, sm.getLinkedNodeMask());
assertFalse(sm.isSegmentLinked());
assertFalse(pmem.isRuleLinked());
wm.insert(new C());
wm.flushPropagations();
// only 5 is needed to link, the 'not' turns on but it has no unfleunce either way
assertEquals(7, sm.getLinkedNodeMask());
assertTrue(sm.isSegmentLinked());
assertTrue(pmem.isRuleLinked());
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class LinkingTest method testNonReactiveSubNetworkOwnSegmentMasks.
@Test
public void testNonReactiveSubNetworkOwnSegmentMasks() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "import " + F.class.getCanonicalName() + "\n";
str += "import " + G.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
str += "rule rule1 when \n";
str += " A() \n";
str += " exists( B() and C() ) \n";
str += " exists( eval(1==1) ) \n";
str += " D() \n";
str += "then \n";
str += "end \n";
str += "rule rule2 when \n";
str += " A() \n";
str += " exists( B() and C() ) \n";
str += " exists( eval(1==1) ) \n";
str += " E() \n";
str += "then \n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
ObjectTypeNode node = getObjectTypeNode(kbase, A.class);
InternalWorkingMemory wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getObjectSinkPropagator().getSinks()[0];
assertEquals(2, liaNode.getSinkPropagator().size());
JoinNode bNode = (JoinNode) liaNode.getSinkPropagator().getSinks()[0];
JoinNode cNode = (JoinNode) bNode.getSinkPropagator().getSinks()[0];
ExistsNode exists1n = (ExistsNode) liaNode.getSinkPropagator().getSinks()[1];
EvalConditionNode evalNode = (EvalConditionNode) exists1n.getSinkPropagator().getSinks()[0];
ExistsNode exists2n = (ExistsNode) exists1n.getSinkPropagator().getSinks()[1];
JoinNode dNode = (JoinNode) exists2n.getSinkPropagator().getSinks()[0];
RuleTerminalNode rtn = (RuleTerminalNode) dNode.getSinkPropagator().getSinks()[0];
wm.insert(new A());
PathMemory pmem = (PathMemory) wm.getNodeMemory(rtn);
assertEquals(4, pmem.getSegmentMemories().length);
// the exists eval segment does not need to be linked in
assertEquals(11, pmem.getAllLinkedMaskTest());
RightInputAdapterNode.RiaNodeMemory riaMem = (RightInputAdapterNode.RiaNodeMemory) wm.getNodeMemory((MemoryFactory) exists1n.getRightInput());
// second segment must be linked in
assertEquals(2, riaMem.getRiaPathMemory().getAllLinkedMaskTest());
wm.insert(new B());
wm.insert(new C());
assertEquals(2, riaMem.getRiaPathMemory().getSegmentMemories().length);
riaMem = (RightInputAdapterNode.RiaNodeMemory) wm.getNodeMemory((MemoryFactory) exists2n.getRightInput());
// no segments to be linked in
assertEquals(0, riaMem.getRiaPathMemory().getAllLinkedMaskTest());
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class LinkingTest method testNonReactiveSubNetworkInShareMasks.
@Test
public void testNonReactiveSubNetworkInShareMasks() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "import " + F.class.getCanonicalName() + "\n";
str += "import " + G.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
str += "rule rule1 when \n";
str += " A() \n";
str += " exists( B() and C() ) \n";
str += " exists( eval(1==1) ) \n";
str += " D() \n";
str += "then \n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
ObjectTypeNode node = getObjectTypeNode(kbase, A.class);
InternalWorkingMemory wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getObjectSinkPropagator().getSinks()[0];
assertEquals(2, liaNode.getSinkPropagator().size());
JoinNode bNode = (JoinNode) liaNode.getSinkPropagator().getSinks()[0];
JoinNode cNode = (JoinNode) bNode.getSinkPropagator().getSinks()[0];
ExistsNode exists1n = (ExistsNode) liaNode.getSinkPropagator().getSinks()[1];
EvalConditionNode evalNode = (EvalConditionNode) exists1n.getSinkPropagator().getSinks()[0];
ExistsNode exists2n = (ExistsNode) exists1n.getSinkPropagator().getSinks()[1];
JoinNode dNode = (JoinNode) exists2n.getSinkPropagator().getSinks()[0];
RuleTerminalNode rtn = (RuleTerminalNode) dNode.getSinkPropagator().getSinks()[0];
wm.insert(new A());
PathMemory pmem = (PathMemory) wm.getNodeMemory(rtn);
assertEquals(3, pmem.getSegmentMemories().length);
// D is in the exists segment
assertEquals(7, pmem.getAllLinkedMaskTest());
BetaMemory bm = (BetaMemory) wm.getNodeMemory(dNode);
// check lazy initialization
assertNull(bm.getSegmentMemory());
wm.insert(new D());
wm.flushPropagations();
// only D can be linked in
assertEquals(2, bm.getSegmentMemory().getAllLinkedMaskTest());
}
Aggregations