use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class AddRemoveRulesTest method testRemoveChildLeftTupleThatWasMiddle.
@Test
public void testRemoveChildLeftTupleThatWasMiddle() {
final String[] rules = getRules3Pattern();
final KieSession kieSession = TestUtil.createSession(rules);
try {
final List resultsList = new ArrayList();
kieSession.setGlobal("list", resultsList);
TestUtil.insertFacts(kieSession, 3);
kieSession.fireAllRules();
Assertions.assertThat(resultsList).containsOnly(TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, TestUtil.RULE3_NAME);
resultsList.clear();
TestUtil.removeRules(kieSession, TestUtil.RULES_PACKAGE_NAME, TestUtil.RULE2_NAME);
kieSession.fireAllRules();
final Map<String, Rule> rulesMap = rulestoMap(kieSession.getKieBase());
final InternalFactHandle fh1 = (InternalFactHandle) kieSession.getFactHandle(3);
final LeftTuple lt = fh1.getFirstLeftTuple().getFirstChild();
assertSame(lt, fh1.getFirstLeftTuple().getLastChild());
assertEquals(1, lt.getTupleSink().getAssociatedRuleSize());
assertTrue(lt.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE1_NAME)));
final LeftTuple peer = lt.getPeer();
assertEquals(1, peer.getTupleSink().getAssociatedRuleSize());
assertTrue(peer.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE3_NAME)));
} finally {
kieSession.dispose();
}
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class AddRemoveRulesTest method testRemoveChildLeftTupleThatWasFirst.
@Test
public void testRemoveChildLeftTupleThatWasFirst() {
final String[] rules = getRules3Pattern();
final KieSession kieSession = TestUtil.createSession(rules[0], rules[1]);
try {
final List resultsList = new ArrayList();
kieSession.setGlobal("list", resultsList);
TestUtil.insertFacts(kieSession, 3);
kieSession.fireAllRules();
Assertions.assertThat(resultsList).containsOnly(TestUtil.RULE1_NAME, TestUtil.RULE2_NAME);
resultsList.clear();
TestUtil.removeRules(kieSession, TestUtil.RULES_PACKAGE_NAME, TestUtil.RULE1_NAME);
kieSession.fireAllRules();
final Map<String, Rule> rulesMap = rulestoMap(kieSession.getKieBase());
final InternalFactHandle fh1 = (InternalFactHandle) kieSession.getFactHandle(3);
final LeftTuple lt = fh1.getFirstLeftTuple().getFirstChild().getFirstChild();
assertSame(lt, fh1.getFirstLeftTuple().getFirstChild().getLastChild());
assertNull(lt.getPeer());
assertEquals(1, lt.getTupleSink().getAssociatedRuleSize());
assertTrue(lt.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE2_NAME)));
} finally {
kieSession.dispose();
}
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class AddRemoveRulesTest method testRemoveChildLeftTupleThatWasLast.
@Test
public void testRemoveChildLeftTupleThatWasLast() {
final String[] rules = getRules3Pattern();
final KieSession kieSession = TestUtil.createSession(rules[0], rules[1]);
try {
final List resultsList = new ArrayList();
kieSession.setGlobal("list", resultsList);
TestUtil.insertFacts(kieSession, 3);
kieSession.fireAllRules();
Assertions.assertThat(resultsList).containsOnly(TestUtil.RULE1_NAME, TestUtil.RULE2_NAME);
resultsList.clear();
TestUtil.removeRules(kieSession, TestUtil.RULES_PACKAGE_NAME, TestUtil.RULE2_NAME);
kieSession.fireAllRules();
final Map<String, Rule> rulesMap = rulestoMap(kieSession.getKieBase());
final InternalFactHandle fh1 = (InternalFactHandle) kieSession.getFactHandle(3);
final LeftTuple lt = fh1.getFirstLeftTuple().getFirstChild().getFirstChild();
assertSame(lt, fh1.getFirstLeftTuple().getFirstChild().getLastChild());
assertNull(lt.getPeer());
assertEquals(1, lt.getTupleSink().getAssociatedRuleSize());
assertTrue(lt.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE1_NAME)));
} finally {
kieSession.dispose();
}
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class AddRemoveRulesTest method testRemoveChildLeftTupleThatWasFirstWithMultipleData.
@Test
public void testRemoveChildLeftTupleThatWasFirstWithMultipleData() {
final String[] rules = getRules3Pattern();
final KieSession kieSession = TestUtil.createSession(rules[0], rules[1]);
try {
final List resultsList = new ArrayList();
kieSession.setGlobal("list", resultsList);
TestUtil.insertFacts(kieSession, 3, 4, 5);
kieSession.fireAllRules();
Assertions.assertThat(resultsList).containsOnly(TestUtil.RULE1_NAME, TestUtil.RULE2_NAME);
resultsList.clear();
TestUtil.removeRules(kieSession, TestUtil.RULES_PACKAGE_NAME, TestUtil.RULE1_NAME);
kieSession.fireAllRules();
final Map<String, Rule> rulesMap = rulestoMap(kieSession.getKieBase());
final InternalFactHandle fh1 = (InternalFactHandle) kieSession.getFactHandle(3);
final InternalFactHandle fh2 = (InternalFactHandle) kieSession.getFactHandle(4);
final InternalFactHandle fh3 = (InternalFactHandle) kieSession.getFactHandle(5);
final LeftTuple lt1 = fh1.getFirstLeftTuple();
final LeftTuple lt1_1 = lt1.getFirstChild();
final LeftTuple lt1_2 = lt1_1.getHandleNext();
final LeftTuple lt1_3 = lt1_2.getHandleNext();
assertNotNull(lt1_1);
assertNotNull(lt1_2);
assertNotNull(lt1_3);
assertSame(lt1_3, lt1.getLastChild());
assertSame(lt1_2, lt1_3.getHandlePrevious());
assertSame(lt1_1, lt1_2.getHandlePrevious());
assertEquals(1, lt1_1.getTupleSink().getAssociatedRuleSize());
assertTrue(lt1_1.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE2_NAME)));
assertNull(lt1_1.getPeer());
assertEquals(1, lt1_2.getTupleSink().getAssociatedRuleSize());
assertTrue(lt1_2.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE2_NAME)));
assertNull(lt1_2.getPeer());
assertEquals(1, lt1_3.getTupleSink().getAssociatedRuleSize());
assertTrue(lt1_3.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE2_NAME)));
assertNull(lt1_3.getPeer());
final RightTuple rt1 = fh3.getFirstRightTuple();
final LeftTuple rt1_1 = rt1.getLastChild();
assertSame(lt1_1, rt1_1);
final LeftTuple rt1_2 = rt1_1.getRightParentPrevious();
final LeftTuple rt1_3 = rt1_2.getRightParentPrevious();
assertNotNull(rt1_1);
assertNotNull(rt1_2);
assertNotNull(rt1_3);
assertSame(rt1_2, rt1_3.getRightParentNext());
assertSame(rt1_1, rt1_2.getRightParentNext());
assertEquals(1, rt1_1.getTupleSink().getAssociatedRuleSize());
assertTrue(rt1_1.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE2_NAME)));
assertNull(rt1_1.getPeer());
assertEquals(1, rt1_2.getTupleSink().getAssociatedRuleSize());
assertTrue(rt1_2.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE2_NAME)));
assertNull(rt1_2.getPeer());
assertEquals(1, rt1_3.getTupleSink().getAssociatedRuleSize());
assertTrue(rt1_3.getTupleSink().isAssociatedWith(rulesMap.get(TestUtil.RULE2_NAME)));
assertNull(rt1_3.getPeer());
} finally {
kieSession.dispose();
}
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class BaseLeftTuplesBuilder method insert.
public T insert(Object... objects) {
this.testStagedInsert = true;
if (objects == null) {
objects = new Object[0];
}
for (int i = 0; i < objects.length; i++) {
if (!(objects[i] instanceof Pair)) {
Object o1 = objects[i];
InternalFactHandle fh1 = (InternalFactHandle) wm.getFactHandle(o1);
LeftTuple leftTuple = new LeftTupleImpl(fh1, sink, true);
leftTuples.addInsert(leftTuple);
} else {
Pair p = (Pair) objects[i];
InternalFactHandle fh1 = (InternalFactHandle) wm.getFactHandle(p.getO1());
LeftTuple leftTuple1 = new LeftTupleImpl(fh1, sink, true);
InternalFactHandle fh2 = (InternalFactHandle) wm.getFactHandle(p.getO2());
LeftTuple leftTuple2 = sink.createLeftTuple(leftTuple1, new RightTupleImpl(fh2), sink);
leftTuples.addInsert(leftTuple2);
}
}
return (T) this;
}
Aggregations