use of org.drools.core.reteoo.AlphaNode in project drools by kiegroup.
the class SegmentUtilities method getQueryLiaNode.
private static LeftInputAdapterNode getQueryLiaNode(String queryName, ObjectTypeNode queryOtn) {
for (ObjectSink sink : queryOtn.getObjectSinkPropagator().getSinks()) {
AlphaNode alphaNode = (AlphaNode) sink;
QueryNameConstraint nameConstraint = (QueryNameConstraint) alphaNode.getConstraint();
if (queryName.equals(nameConstraint.getQueryName())) {
return (LeftInputAdapterNode) alphaNode.getObjectSinkPropagator().getSinks()[0];
}
}
throw new RuntimeException("Unable to find query '" + queryName + "'");
}
use of org.drools.core.reteoo.AlphaNode in project drools by kiegroup.
the class PropertySpecificTest method testRtnSharedAlphaWithWatches.
@Test
public void testRtnSharedAlphaWithWatches() {
String rule1 = "A( a == 10, b == 15 ) @watch(c, !a)";
String rule2 = "A( a == 10, i == 20 ) @watch(s, !i)";
KieBase kbase = getKnowledgeBase(rule1, rule2);
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 alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b", "c", "s", "i"), sp), alphaNode1.getInferredMask());
// first share
AlphaNode alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask());
LeftInputAdapterNode liaNode1 = (LeftInputAdapterNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode1 = (RuleTerminalNode) liaNode1.getSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("c"), sp), rtNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("b", "c"), sp), rtNode1.getInferredMask());
assertEquals(calculateNegativeMask(classType, list("!a"), sp), rtNode1.getNegativeMask());
// second share
AlphaNode alphaNode1_2 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[1];
assertEquals(calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i", "s"), sp), alphaNode1_2.getInferredMask());
LeftInputAdapterNode liaNode2 = (LeftInputAdapterNode) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode2 = (RuleTerminalNode) liaNode2.getSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("s"), sp), rtNode2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "s"), sp), rtNode2.getInferredMask());
assertEquals(calculateNegativeMask(classType, list("!i"), sp), rtNode2.getNegativeMask());
// test rule removal
kbase.removeRule("org.drools.compiler.integrationtests", "r0");
assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i", "s"), sp), alphaNode1.getInferredMask());
assertEquals(calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i", "s"), sp), alphaNode1_2.getInferredMask());
assertEquals(calculatePositiveMask(classType, list("s"), sp), rtNode2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "s"), sp), rtNode2.getInferredMask());
assertEquals(calculateNegativeMask(classType, list("!i"), sp), rtNode2.getNegativeMask());
// have to rebuild to remove r1
kbase = getKnowledgeBase(rule1, rule2);
kbase.removeRule("org.drools.compiler.integrationtests", "r1");
otn = getObjectTypeNode(kbase, "A");
alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1.getInferredMask());
alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask());
liaNode1 = (LeftInputAdapterNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
rtNode1 = (RuleTerminalNode) liaNode1.getSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("c"), sp), rtNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("b", "c"), sp), rtNode1.getInferredMask());
assertEquals(calculateNegativeMask(classType, list("!a"), sp), rtNode1.getNegativeMask());
}
use of org.drools.core.reteoo.AlphaNode in project drools by kiegroup.
the class PropertySpecificTest method testRTNodeWithConstraintsNoPropertySpecific.
@Test
public void testRTNodeWithConstraintsNoPropertySpecific() {
String rule = "package org.drools.compiler.integrationtests\n" + "import " + Person.class.getCanonicalName() + "\n" + "rule r1\n" + "when\n" + " Person( name == 'bobba')\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper(PropertySpecificOption.ALLOWED).addContent(rule, ResourceType.DRL).build();
ObjectTypeNode otn = getObjectTypeNode(kbase, "Person");
assertNotNull(otn);
AlphaNode alphaNode = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
assertEquals(AllSetBitMask.get(), alphaNode.getDeclaredMask());
assertEquals(AllSetBitMask.get(), alphaNode.getInferredMask());
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) alphaNode.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.AlphaNode in project drools by kiegroup.
the class PropertySpecificTest method testSharedAlphanodeWithBetaNodeConstraintsNoPropertySpecific.
@Test
public void testSharedAlphanodeWithBetaNodeConstraintsNoPropertySpecific() {
String rule = "package org.drools.compiler.integrationtests\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Cheese.class.getCanonicalName() + "\n" + "rule r1\n" + "when\n" + " Person()\n" + " Cheese( type == 'brie', price == 1.5 )\n" + "then\n" + "end\n" + "rule r2\n" + "when\n" + " Person()\n" + " Cheese( type == 'brie', price == 2.5 )\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper(PropertySpecificOption.ALLOWED).addContent(rule, ResourceType.DRL).build();
ObjectTypeNode otn = getObjectTypeNode(kbase, "Cheese");
assertNotNull(otn);
AlphaNode alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
assertEquals(AllSetBitMask.get(), alphaNode1.getDeclaredMask());
assertEquals(AllSetBitMask.get(), alphaNode1.getInferredMask());
// first share
AlphaNode alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
assertEquals(AllSetBitMask.get(), alphaNode1_1.getDeclaredMask());
assertEquals(AllSetBitMask.get(), alphaNode1_1.getInferredMask());
BetaNode betaNode1 = (BetaNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
assertEquals(AllSetBitMask.get(), betaNode1.getRightDeclaredMask());
assertEquals(AllSetBitMask.get(), betaNode1.getRightInferredMask());
// second share
AlphaNode alphaNode1_2 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[1];
assertEquals(AllSetBitMask.get(), alphaNode1_2.getDeclaredMask());
assertEquals(AllSetBitMask.get(), alphaNode1_2.getInferredMask());
BetaNode betaNode2 = (BetaNode) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
assertEquals(AllSetBitMask.get(), betaNode2.getRightDeclaredMask());
assertEquals(AllSetBitMask.get(), betaNode2.getRightInferredMask());
}
use of org.drools.core.reteoo.AlphaNode in project drools by kiegroup.
the class PropertySpecificTest method testRtnSharedAlphaNoWatches.
@Test
public void testRtnSharedAlphaNoWatches() {
String rule1 = "A( a == 10, b == 15 )";
String rule2 = "A( a == 10, i == 20 )";
KieBase kbase = getKnowledgeBase(rule1, rule2);
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 alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b", "i"), sp), alphaNode1.getInferredMask());
// first share
AlphaNode alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), alphaNode1_1.getInferredMask());
LeftInputAdapterNode liaNode1 = (LeftInputAdapterNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode1 = (RuleTerminalNode) liaNode1.getSinkPropagator().getSinks()[0];
assertEquals(EmptyBitMask.get(), rtNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), rtNode1.getInferredMask());
// second share
AlphaNode alphaNode1_2 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[1];
assertEquals(calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i"), sp), alphaNode1_2.getInferredMask());
LeftInputAdapterNode liaNode2 = (LeftInputAdapterNode) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtNode2 = (RuleTerminalNode) liaNode2.getSinkPropagator().getSinks()[0];
assertEquals(EmptyBitMask.get(), rtNode2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i"), sp), rtNode2.getInferredMask());
// test rule removal
kbase.removeRule("org.drools.compiler.integrationtests", "r0");
assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i"), sp), alphaNode1.getInferredMask());
assertEquals(calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i"), sp), alphaNode1_2.getInferredMask());
assertEquals(EmptyBitMask.get(), rtNode2.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "i"), sp), rtNode2.getInferredMask());
// have to rebuild to remove r1
kbase = getKnowledgeBase(rule1, rule2);
kbase.removeRule("org.drools.compiler.integrationtests", "r1");
otn = getObjectTypeNode(kbase, "A");
alphaNode1 = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), alphaNode1.getInferredMask());
alphaNode1_1 = (AlphaNode) alphaNode1.getObjectSinkPropagator().getSinks()[0];
assertEquals(calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), alphaNode1_1.getInferredMask());
liaNode1 = (LeftInputAdapterNode) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
rtNode1 = (RuleTerminalNode) liaNode1.getSinkPropagator().getSinks()[0];
assertEquals(EmptyBitMask.get(), rtNode1.getDeclaredMask());
assertEquals(calculatePositiveMask(classType, list("a", "b"), sp), rtNode1.getInferredMask());
}
Aggregations