use of org.drools.core.reteoo.LeftInputAdapterNode in project drools by kiegroup.
the class PropertySpecificTest method testRtnWithConstraintsNoWatches.
@Test
public void testRtnWithConstraintsNoWatches() {
String rule1 = "A( a == 10 )";
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"), sp), alphaNode.getInferredMask());
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) alphaNode.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
// rtn declares nothing
assertEquals(EmptyBitMask.get(), rtNode.getDeclaredMask());
// rtn infers from alpha
assertEquals(calculatePositiveMask(classType, list("a"), sp), rtNode.getInferredMask());
}
use of org.drools.core.reteoo.LeftInputAdapterNode in project drools by kiegroup.
the class PropertySpecificTest method testRTNodeNoConstraintsNoPropertySpecific.
@Test
public void testRTNodeNoConstraintsNoPropertySpecific() {
String rule = "package org.drools.compiler.integrationtests\n" + "import " + Person.class.getCanonicalName() + "\n" + "rule r1\n" + "when\n" + " Person()\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper(PropertySpecificOption.ALLOWED).addContent(rule, ResourceType.DRL).build();
ObjectTypeNode otn = getObjectTypeNode(kbase, "Person");
assertNotNull(otn);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
assertEquals(AllSetBitMask.get(), rtNode.getDeclaredMask());
assertEquals(AllSetBitMask.get(), rtNode.getInferredMask());
}
use of org.drools.core.reteoo.LeftInputAdapterNode in project drools by kiegroup.
the class PropertySpecificTest method testRtnNoConstraintsNoWatches.
@Test
public void testRtnNoConstraintsNoWatches() {
String rule1 = "A()";
KieBase kbase = getKnowledgeBase(rule1);
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode otn = getObjectTypeNode(kbase, "A");
assertNotNull(otn);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
assertEquals(EmptyBitMask.get(), rtNode.getDeclaredMask());
assertEquals(EmptyBitMask.get(), rtNode.getInferredMask());
}
use of org.drools.core.reteoo.LeftInputAdapterNode in project drools by kiegroup.
the class MemoryLeakTest method testStagedLeftTupleLeak.
@Test
public void testStagedLeftTupleLeak() throws Exception {
// BZ-1058874
String str = "rule R1 when\n" + " String( this == \"this\" )\n" + " String( this == \"that\" )\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper().addContent(str, ResourceType.DRL).build();
KieSession ksession = kbase.newKieSession();
ksession.fireAllRules();
for (int i = 0; i < 10; i++) {
FactHandle fh = ksession.insert("this");
ksession.fireAllRules();
ksession.delete(fh);
ksession.fireAllRules();
}
Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
LeftInputAdapterNode liaNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
if (String.class == otn.getObjectType().getValueType().getClassType()) {
AlphaNode alphaNode = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
liaNode = (LeftInputAdapterNode) alphaNode.getObjectSinkPropagator().getSinks()[0];
break;
}
}
assertNotNull(liaNode);
InternalWorkingMemory wm = (InternalWorkingMemory) ksession;
LeftInputAdapterNode.LiaNodeMemory memory = (LeftInputAdapterNode.LiaNodeMemory) wm.getNodeMemory(liaNode);
TupleSets<LeftTuple> stagedLeftTuples = memory.getSegmentMemory().getStagedLeftTuples();
assertNull(stagedLeftTuples.getDeleteFirst());
assertNull(stagedLeftTuples.getInsertFirst());
}
use of org.drools.core.reteoo.LeftInputAdapterNode in project drools by kiegroup.
the class LeftTupleIterator method getFirstLeftTuple.
public LeftTuple getFirstLeftTuple(LeftTupleSource source, LeftTupleSink sink, InternalWorkingMemory wm) {
if (source instanceof AccumulateNode) {
AccumulateMemory accmem = (AccumulateMemory) wm.getNodeMemory((MemoryFactory) source);
BetaMemory memory = accmem.getBetaMemory();
FastIterator localIt = memory.getLeftTupleMemory().fullFastIterator();
Tuple leftTuple = BetaNode.getFirstTuple(memory.getLeftTupleMemory(), localIt);
if (leftTuple != null) {
AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
return accctx.getResultLeftTuple();
}
return null;
}
if (source instanceof JoinNode || source instanceof NotNode || source instanceof FromNode || source instanceof AccumulateNode) {
BetaMemory memory;
FastIterator localIt;
if (source instanceof FromNode) {
memory = ((FromMemory) wm.getNodeMemory((MemoryFactory) source)).getBetaMemory();
} else if (source instanceof AccumulateNode) {
memory = ((AccumulateMemory) wm.getNodeMemory((MemoryFactory) source)).getBetaMemory();
} else {
memory = (BetaMemory) wm.getNodeMemory((MemoryFactory) source);
}
localIt = memory.getLeftTupleMemory().fullFastIterator();
Tuple leftTuple = BetaNode.getFirstTuple(memory.getLeftTupleMemory(), localIt);
while (leftTuple != null) {
for (LeftTuple childleftTuple = leftTuple.getFirstChild(); childleftTuple != null; childleftTuple = childleftTuple.getHandleNext()) {
if (childleftTuple.getTupleSink() == sink) {
return childleftTuple;
}
}
leftTuple = (LeftTuple) localIt.next(leftTuple);
}
}
if (source instanceof ExistsNode) {
BetaMemory memory = (BetaMemory) wm.getNodeMemory((MemoryFactory) source);
FastIterator localIt = memory.getRightTupleMemory().fullFastIterator();
RightTuple rightTuple = (RightTuple) BetaNode.getFirstTuple(memory.getRightTupleMemory(), localIt);
while (rightTuple != null) {
if (rightTuple.getBlocked() != null) {
for (LeftTuple leftTuple = rightTuple.getBlocked(); leftTuple != null; leftTuple = leftTuple.getBlockedNext()) {
for (LeftTuple childleftTuple = leftTuple.getFirstChild(); childleftTuple != null; childleftTuple = childleftTuple.getHandleNext()) {
if (childleftTuple.getTupleSink() == sink) {
return childleftTuple;
}
}
}
}
rightTuple = (RightTuple) localIt.next(rightTuple);
}
} else if (source instanceof LeftInputAdapterNode) {
ObjectSource os = ((LeftInputAdapterNode) source).getParentObjectSource();
while (!(os instanceof ObjectTypeNode)) {
os = os.getParentObjectSource();
}
ObjectTypeNode otn = (ObjectTypeNode) os;
otnIterator = wm.getNodeMemory(otn).iterator();
while (otnIterator.hasNext()) {
InternalFactHandle handle = otnIterator.next();
LeftTuple leftTuple = handle.findFirstLeftTuple(lt -> lt.getTupleSink() == sink);
if (leftTuple != null) {
return leftTuple;
}
}
} else if (source instanceof EvalConditionNode || source instanceof QueryElementNode) {
LeftTuple parentLeftTuple = getFirstLeftTuple(source.getLeftTupleSource(), (LeftTupleSink) source, wm);
while (parentLeftTuple != null) {
for (LeftTuple leftTuple = parentLeftTuple.getFirstChild(); leftTuple != null; leftTuple = leftTuple.getHandleNext()) {
if (leftTuple.getTupleSink() == sink) {
return leftTuple;
}
}
parentLeftTuple = getNextLeftTuple(source.getLeftTupleSource(), (LeftTupleSink) source, parentLeftTuple, wm);
}
}
return null;
}
Aggregations