use of org.drools.core.reteoo.LeftInputAdapterNode 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 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 in project drools by kiegroup.
the class PassiveQueryTest method testPassiveQueryUsingSegmentPropagator.
@Test
public void testPassiveQueryUsingSegmentPropagator() throws Exception {
String str = "global java.util.List list\n" + "query Q (Integer i)\n" + " String( this == i.toString() )\n" + "end\n" + "rule R1a @Propagation(IMMEDIATE) when\n" + " $i : Integer()\n" + " ?Q( $i; )\n" + "then\n" + " list.add( \"R1a\" );\n" + "end\n" + "rule R1b @Propagation(IMMEDIATE) when\n" + " $i : Integer()\n" + " ?Q( $i; )\n" + " Long( intValue == $i )\n" + "then\n" + " list.add( \"R1b\" );\n" + "end\n" + "rule R2 when\n" + " $i : Integer()\n" + " ?Q( $i; )\n" + "then\n" + " list.add( \"R2\" );\n" + "end\n";
KieBase kbase = new KieHelper().addContent(str, ResourceType.DRL).build();
KieSession ksession = kbase.newKieSession();
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert(1L);
FactHandle fh = ksession.insert(1);
ksession.insert("1");
Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
LeftInputAdapterNode lia = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
if (Integer.class == otn.getObjectType().getValueType().getClassType()) {
lia = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
break;
}
}
LeftTupleSink[] sinks = lia.getSinkPropagator().getSinks();
QueryElementNode q1 = (QueryElementNode) sinks[0];
QueryElementNode q2 = (QueryElementNode) sinks[1];
InternalWorkingMemory wm = (InternalWorkingMemory) ksession;
wm.flushPropagations();
Memory memory1 = wm.getNodeMemory(q1);
assertTrue(memory1.getSegmentMemory().getStagedLeftTuples().isEmpty());
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("R2", list.get(0));
list.clear();
ksession.delete(fh);
ksession.insert(1);
ksession.fireAllRules();
assertEquals(3, list.size());
}
use of org.drools.core.reteoo.LeftInputAdapterNode in project drools by kiegroup.
the class PropertySpecificTest method testInitialFactBetaNodeWithRightInputAdapter.
@Test
public void testInitialFactBetaNodeWithRightInputAdapter() {
String rule = "package org.drools.compiler.integrationtests\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Cheese.class.getCanonicalName() + "\n" + "rule r1\n" + "when\n" + " exists(eval(1==1))\n" + "then\n" + "end\n";
KieBase kbase = loadKnowledgeBaseFromString(rule);
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode otn = getObjectTypeNode(kbase, "InitialFactImpl");
assertNotNull(otn);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
BetaNode betaNode = (BetaNode) liaNode.getSinkPropagator().getSinks()[1];
assertEquals(AllSetBitMask.get(), betaNode.getLeftDeclaredMask());
assertEquals(AllSetBitMask.get(), betaNode.getLeftInferredMask());
assertEquals(AllSetBitMask.get(), betaNode.getRightDeclaredMask());
assertEquals(AllSetBitMask.get(), betaNode.getRightInferredMask());
}
use of org.drools.core.reteoo.LeftInputAdapterNode in project drools by kiegroup.
the class PropertySpecificTest method testRtnWithConstraintsWithWatches.
@Test
public void testRtnWithConstraintsWithWatches() {
String rule1 = "A( a == 10 ) @watch(b)";
KieBase kbase = getKnowledgeBase(rule1);
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode otn = getObjectTypeNode(kbase, "A");
assertNotNull(otn);
Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();
List<String> sp = getSettableProperties(wm, otn);
AlphaNode alphaNode = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), alphaNode.getInferredMask());
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) alphaNode.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("b"), sp), rtNode.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), rtNode.getInferredMask());
}
Aggregations