use of org.drools.core.reteoo.Rete in project drools by kiegroup.
the class Misc2Test method testFromEPDontRequireLeftInput.
@Test
public void testFromEPDontRequireLeftInput() {
// DROOLS-1014
String drl = "rule R when\n" + " $s1 : String() from entry-point \"xxx\"\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper().addContent(drl, ResourceType.DRL).build();
Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
LeftInputAdapterNode liaNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
Class<?> otnType = ((ClassObjectType) otn.getObjectType()).getClassType();
if (String.class == otnType) {
assertEquals(1, otn.getObjectSinkPropagator().size());
} else if (InitialFact.class.isAssignableFrom(otnType)) {
assertEquals(0, otn.getObjectSinkPropagator().size());
} else {
fail("There shouldn't be other OTNs");
}
}
}
use of org.drools.core.reteoo.Rete in project drools by kiegroup.
the class NodePositionInPathTest method test.
@Test
public void test() {
String drl = "rule R1 when\n" + " Integer()\n" + " exists( Integer() and Integer() )\n" + " String()\n" + "then\n" + "end\n" + "rule R2 when\n" + " Integer()\n" + " exists( Integer() and String() )\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper().addContent(drl, ResourceType.DRL).build();
ReteDumper.dumpRete(((InternalKnowledgeBase) kbase));
Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
LeftInputAdapterNode liaNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
Class<?> otnType = ((ClassObjectType) otn.getObjectType()).getClassType();
if (Integer.class == otnType) {
liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
}
}
assertEquals(0, liaNode.getPositionInPath());
LeftTupleSink[] liaSinks = liaNode.getSinkPropagator().getSinks();
BetaNode join1 = (BetaNode) liaSinks[0];
assertEquals(1, join1.getPositionInPath());
ExistsNode ex1 = (ExistsNode) liaSinks[1];
assertEquals(1, ex1.getPositionInPath());
BetaNode join2 = (BetaNode) ex1.getSinkPropagator().getSinks()[0];
assertEquals(2, join2.getPositionInPath());
RuleTerminalNode rtn1 = (RuleTerminalNode) join2.getSinkPropagator().getSinks()[0];
assertEquals(3, rtn1.getPositionInPath());
ExistsNode ex2 = (ExistsNode) liaSinks[2];
assertEquals(1, ex2.getPositionInPath());
RuleTerminalNode rtn2 = (RuleTerminalNode) ex2.getSinkPropagator().getSinks()[0];
assertEquals(2, rtn2.getPositionInPath());
BetaNode join3 = (BetaNode) join1.getSinkPropagator().getSinks()[0];
assertEquals(2, join3.getPositionInPath());
RightInputAdapterNode ria1 = (RightInputAdapterNode) join3.getSinkPropagator().getSinks()[0];
assertEquals(3, ria1.getPositionInPath());
BetaNode join4 = (BetaNode) join1.getSinkPropagator().getSinks()[1];
assertEquals(2, join4.getPositionInPath());
RightInputAdapterNode ria2 = (RightInputAdapterNode) join4.getSinkPropagator().getSinks()[0];
assertEquals(3, ria2.getPositionInPath());
LeftTupleNode[] rtn1PathNodes = rtn1.getPathNodes();
assertEquals(4, rtn1PathNodes.length);
checkNodePosition(rtn1PathNodes, liaNode);
checkNodePosition(rtn1PathNodes, ex1);
checkNodePosition(rtn1PathNodes, join2);
checkNodePosition(rtn1PathNodes, rtn1);
LeftTupleNode[] rtn2PathNodes = rtn2.getPathNodes();
assertEquals(3, rtn2PathNodes.length);
checkNodePosition(rtn2PathNodes, liaNode);
checkNodePosition(rtn2PathNodes, ex2);
checkNodePosition(rtn2PathNodes, rtn2);
LeftTupleNode[] ria1PathNodes = ria1.getPathNodes();
assertEquals(4, ria1PathNodes.length);
checkNodePosition(ria1PathNodes, liaNode);
checkNodePosition(ria1PathNodes, join1);
checkNodePosition(ria1PathNodes, join3);
checkNodePosition(ria1PathNodes, ria1);
LeftTupleNode[] ria2PathNodes = ria2.getPathNodes();
assertEquals(4, ria2PathNodes.length);
checkNodePosition(ria2PathNodes, liaNode);
checkNodePosition(ria2PathNodes, join1);
checkNodePosition(ria2PathNodes, join4);
checkNodePosition(ria2PathNodes, ria2);
}
use of org.drools.core.reteoo.Rete in project drools by kiegroup.
the class NodesPartitioningTest method checkDrl.
private void checkDrl(String drl) {
InternalKnowledgeBase kbase = (InternalKnowledgeBase) new KieHelper().addContent(drl, ResourceType.DRL).build(MultithreadEvaluationOption.YES);
Rete rete = kbase.getRete();
for (EntryPointNode entryPointNode : rete.getEntryPointNodes().values()) {
traverse(entryPointNode);
}
}
use of org.drools.core.reteoo.Rete in project drools by kiegroup.
the class MemoryLeakTest method testStagedTupleLeak.
@Test
public void testStagedTupleLeak() throws Exception {
// BZ-1056599
String str = "rule R1 when\n" + " $i : Integer()\n" + "then\n" + " insertLogical( $i.toString() );\n" + "end\n" + "\n" + "rule R2 when\n" + " $i : Integer()\n" + "then\n" + " delete( $i );\n" + "end\n" + "\n" + "rule R3 when\n" + " $l : Long()\n" + " $s : String( this == $l.toString() )\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper().addContent(str, ResourceType.DRL).build();
KieSession ksession = kbase.newKieSession();
for (int i = 0; i < 10; i++) {
ksession.insert(i);
ksession.fireAllRules();
}
Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
JoinNode joinNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
if (String.class == otn.getObjectType().getValueType().getClassType()) {
joinNode = (JoinNode) otn.getObjectSinkPropagator().getSinks()[0];
break;
}
}
assertNotNull(joinNode);
InternalWorkingMemory wm = (InternalWorkingMemory) ksession;
BetaMemory memory = (BetaMemory) wm.getNodeMemory(joinNode);
TupleSets<RightTuple> stagedRightTuples = memory.getStagedRightTuples();
assertNull(stagedRightTuples.getDeleteFirst());
assertNull(stagedRightTuples.getInsertFirst());
}
use of org.drools.core.reteoo.Rete in project drools by kiegroup.
the class KnowledgeBaseImpl method setupRete.
protected void setupRete() {
this.rete = new Rete(this);
this.reteooBuilder = new ReteooBuilder(this);
NodeFactory nodeFactory = CoreComponentFactory.get().getNodeFactoryService();
// always add the default entry point
EntryPointNode epn = nodeFactory.buildEntryPointNode(this.reteooBuilder.getNodeIdsGenerator().getNextId(), RuleBasePartitionId.MAIN_PARTITION, this.getConfiguration().isMultithreadEvaluation(), this.rete, EntryPointId.DEFAULT);
epn.attach();
BuildContext context = new BuildContext(this, Collections.emptyList());
context.setCurrentEntryPoint(epn.getEntryPoint());
context.setTupleMemoryEnabled(true);
context.setObjectTypeNodeMemoryEnabled(true);
context.setPartitionId(RuleBasePartitionId.MAIN_PARTITION);
ObjectTypeNode otn = nodeFactory.buildObjectTypeNode(this.reteooBuilder.getNodeIdsGenerator().getNextId(), epn, ClassObjectType.InitialFact_ObjectType, context);
otn.attach(context);
}
Aggregations