use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class RuleUnlinkingTest method testRuleSegmentsAllLinkedTestMasks.
@Test
public void testRuleSegmentsAllLinkedTestMasks() {
setUp(JOIN_NODE);
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase);
PathMemory rs = (PathMemory) wm.getNodeMemory(rtn1);
assertFalse(rs.isRuleLinked());
assertEquals(1, rs.getAllLinkedMaskTest());
rs = (PathMemory) wm.getNodeMemory(rtn2);
assertFalse(rs.isRuleLinked());
assertEquals(3, rs.getAllLinkedMaskTest());
rs = (PathMemory) wm.getNodeMemory(rtn3);
assertFalse(rs.isRuleLinked());
assertEquals(7, rs.getAllLinkedMaskTest());
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class RuleUnlinkingTest method testRuleSegmentLinking.
@Test
public void testRuleSegmentLinking() {
setUp(JOIN_NODE);
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase);
BetaMemory bm = null;
List<PathMemory> list;
PathMemory rtn1Rs = (PathMemory) wm.getNodeMemory(rtn1);
PathMemory rtn2Rs = (PathMemory) wm.getNodeMemory(rtn2);
PathMemory rtn3Rs = (PathMemory) wm.getNodeMemory(rtn3);
DefaultFactHandle f1 = (DefaultFactHandle) wm.insert("test1");
SegmentUtilities.createSegmentMemory(liaNode, wm);
liaNode.assertObject(f1, context, wm);
n1.assertObject(f1, context, wm);
n3.assertObject(f1, context, wm);
n4.assertObject(f1, context, wm);
n8.assertObject(f1, context, wm);
assertFalse(rtn1Rs.isRuleLinked());
assertFalse(rtn2Rs.isRuleLinked());
assertFalse(rtn3Rs.isRuleLinked());
// Link in Rule1
bm = (BetaMemory) wm.getNodeMemory(n2);
assertFalse(bm.getSegmentMemory().isSegmentLinked());
DefaultFactHandle f2 = (DefaultFactHandle) wm.insert("test2");
n2.assertObject(f2, context, wm);
assertTrue(bm.getSegmentMemory().isSegmentLinked());
assertTrue(rtn1Rs.isRuleLinked());
assertFalse(rtn2Rs.isRuleLinked());
assertFalse(rtn3Rs.isRuleLinked());
// Link in Rule2
bm = (BetaMemory) wm.getNodeMemory(n5);
assertFalse(bm.getSegmentMemory().isSegmentLinked());
n5.assertObject(f1, context, wm);
assertTrue(bm.getSegmentMemory().isSegmentLinked());
assertTrue(rtn1Rs.isRuleLinked());
assertTrue(rtn2Rs.isRuleLinked());
assertFalse(rtn3Rs.isRuleLinked());
// Link in Rule3
n6.assertObject(f1, context, wm);
n7.assertObject(f1, context, wm);
assertTrue(bm.getSegmentMemory().isSegmentLinked());
assertTrue(rtn1Rs.isRuleLinked());
assertTrue(rtn2Rs.isRuleLinked());
assertTrue(rtn3Rs.isRuleLinked());
// retract n2, should unlink all rules
n2.retractRightTuple(f2.getFirstRightTuple(), context, wm);
assertFalse(rtn1Rs.isRuleLinked());
assertFalse(rtn2Rs.isRuleLinked());
assertFalse(rtn3Rs.isRuleLinked());
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class RuleUnlinkingWithSegmentMemoryTest method testRuleSegmentsAllLinkedTestMasks.
@Test
public void testRuleSegmentsAllLinkedTestMasks() {
setUp(JOIN_NODE);
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase);
PathMemory rs = (PathMemory) wm.getNodeMemory(rtn1);
assertFalse(rs.isRuleLinked());
assertEquals(1, rs.getAllLinkedMaskTest());
rs = (PathMemory) wm.getNodeMemory(rtn2);
assertFalse(rs.isRuleLinked());
assertEquals(3, rs.getAllLinkedMaskTest());
rs = (PathMemory) wm.getNodeMemory(rtn3);
assertFalse(rs.isRuleLinked());
assertEquals(7, rs.getAllLinkedMaskTest());
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class RuleUnlinkingWithSegmentMemoryTest method testSegmentNodeReferencesToSegments.
@Test
public void testSegmentNodeReferencesToSegments() {
setUp(JOIN_NODE);
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase);
BetaMemory bm = null;
List<PathMemory> list;
PathMemory rtn1Rs = (PathMemory) wm.getNodeMemory(rtn1);
PathMemory rtn2Rs = (PathMemory) wm.getNodeMemory(rtn2);
PathMemory rtn3Rs = (PathMemory) wm.getNodeMemory(rtn3);
// lian
SegmentUtilities.createSegmentMemory(lian, wm);
LeftInputAdapterNode.LiaNodeMemory lmem = (LeftInputAdapterNode.LiaNodeMemory) wm.getNodeMemory(lian);
assertEquals(1, lmem.getNodePosMaskBit());
// n1
SegmentUtilities.createSegmentMemory(n1, wm);
bm = (BetaMemory) wm.getNodeMemory(n1);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(1, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(3, list.size());
assertTrue(list.contains(rtn1Rs));
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n2
bm = (BetaMemory) wm.getNodeMemory(n2);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(1, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(3, list.size());
assertTrue(list.contains(rtn1Rs));
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n3
bm = (BetaMemory) wm.getNodeMemory(n3);
assertEquals(8, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(1, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(3, list.size());
assertTrue(list.contains(rtn1Rs));
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n4
SegmentUtilities.createSegmentMemory(n4, wm);
bm = (BetaMemory) wm.getNodeMemory(n4);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(3, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(2, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(2, list.size());
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n5
bm = (BetaMemory) wm.getNodeMemory(n5);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(3, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(2, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(2, list.size());
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n6
SegmentUtilities.createSegmentMemory(n6, wm);
bm = (BetaMemory) wm.getNodeMemory(n6);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(7, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(4, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(1, list.size());
assertTrue(list.contains(rtn3Rs));
// n7
bm = (BetaMemory) wm.getNodeMemory(n7);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(7, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(4, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(1, list.size());
assertTrue(list.contains(rtn3Rs));
// n8
bm = (BetaMemory) wm.getNodeMemory(n8);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(7, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(4, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(1, list.size());
assertTrue(list.contains(rtn3Rs));
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class FieldConstraintTest method testLiteralConstraint.
/**
* <pre>
*
* ( Cheese (type "cheddar") )
*
* </pre>
*
* This is currently the same as using a ReturnValueConstraint just that it
* doesn't need any requiredDeclarations
*/
@Test
public void testLiteralConstraint() {
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final ClassFieldReader extractor = store.getReader(Cheese.class, "type");
final MvelConstraint constraint = new MvelConstraintTestUtil("type == \"cheddar\"", FieldFactory.getInstance().getFieldValue("cheddar"), extractor);
final Cheese cheddar = new Cheese("cheddar", 5);
final InternalFactHandle cheddarHandle = (InternalFactHandle) ksession.insert(cheddar);
// check constraint
assertTrue(constraint.isAllowed(cheddarHandle, ksession));
final Cheese stilton = new Cheese("stilton", 5);
final InternalFactHandle stiltonHandle = (InternalFactHandle) ksession.insert(stilton);
// check constraint
assertFalse(constraint.isAllowed(stiltonHandle, ksession));
}
Aggregations