Skip to content

Commit

Permalink
Merge pull request #10 from mariofusco/d1025mf
Browse files Browse the repository at this point in the history
[DROOLS-1025] unlink RTNLeftTuples generated from removed rule
  • Loading branch information
mdproctor committed Feb 15, 2016
2 parents 9726d17 + 7612668 commit e01dca6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,62 @@ public void testRemoveWithSplitStartAfterSubnetwork3RulesAddOneAfterAnother() {
runAddRemoveTest(builder.build(), additionalGlobals);
}

@Test
public void testRemoveWithSplitStartAfterSubnetwork3RulesReaddRule() {
final String rule1 = "package " + PKG_NAME_TEST + ";" +
"global java.util.concurrent.atomic.AtomicInteger globalInt\n" +
"global java.util.List list\n" +
"rule " + RULE1_NAME + " \n" +
"when\n" +
" $s : String()\n" +
" Integer()\n" +
" exists( Integer() and Integer() )\n" +
"then\n" +
" list.add('" + RULE1_NAME + "'); \n" +
"end\n";

final String rule2 = "package " + PKG_NAME_TEST + ";" +
"global java.util.concurrent.atomic.AtomicInteger globalInt\n" +
"global java.util.List list\n" +
"rule " + RULE2_NAME + " \n" +
"when \n" +
" $s : String()\n" +
" Integer()\n" +
" exists( Integer() and Integer() )\n" +
" String()\n" +
"then \n" +
" list.add('" + RULE2_NAME + "'); \n" +
"end";

final String rule3 = "package " + PKG_NAME_TEST + ";" +
"global java.util.concurrent.atomic.AtomicInteger globalInt\n" +
"global java.util.List list\n" +
"rule " + RULE3_NAME + " \n" +
"when \n" +
" $s : String()\n" +
" Integer()\n" +
" exists( Integer() and exists(Integer() and Integer()))\n" +
" String()\n" +
"then \n" +
" list.add('" + RULE3_NAME + "'); \n" +
"end";

AddRemoveTestBuilder builder = new AddRemoveTestBuilder();
builder.addOperation(TestOperationType.CREATE_SESSION, new String[]{rule1, rule2, rule3})
.addOperation(TestOperationType.INSERT_FACTS, new Object[] {1, 2, "1"})
.addOperation(TestOperationType.REMOVE_RULES, new String[]{RULE2_NAME})
.addOperation(TestOperationType.FIRE_RULES)
.addOperation(TestOperationType.CHECK_RESULTS, new String[]{RULE1_NAME, RULE3_NAME})
.addOperation(TestOperationType.ADD_RULES, new String[]{rule2})
.addOperation(TestOperationType.FIRE_RULES)
.addOperation(TestOperationType.CHECK_RESULTS, new String[]{RULE1_NAME, RULE2_NAME, RULE3_NAME});

final Map<String, Object> additionalGlobals = new HashMap<String, Object>();
additionalGlobals.put("globalInt", new AtomicInteger(0));

runAddRemoveTest(builder.build(), additionalGlobals);
}

private void testRemoveWithSplitStartBasicTestSet(final String rule1, final String rule2,
final String rule1Name, final String rule2Name) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ public void testPopulatedSingleRuleNoSharing() throws Exception {
kbase.removeRule("org.kie", "r1");

assertEquals( 6, countNodeMemories(nms)); // still has OTN

assertEquals( 0, bMem.getLeftTupleMemory().size() );
assertEquals( 0, bMem.getRightTupleMemory().size() );

assertEquals( 0, eMem.getLeftTupleMemory().size() );
assertEquals( 0, eMem.getRightTupleMemory().size() );
}

@Test
Expand Down Expand Up @@ -204,9 +198,6 @@ public void testPopulatedRuleMidwayShare() throws Exception {

assertNull( sm.getFirst());

assertEquals( 0, c2Mem.getLeftTupleMemory().size() );
assertEquals( 0, c2Mem.getRightTupleMemory().size() );

assertSame( sm, c1Mem.getSegmentMemory()); // c1SMem repoints back to original Smem

wm.insert(new A(1));
Expand Down Expand Up @@ -270,9 +261,6 @@ public void testPopulatedRuleWithEvals() throws Exception {

assertNull( sm.getFirst());

assertEquals( 0, c2Mem.getLeftTupleMemory().size() );
assertEquals( 0, c2Mem.getRightTupleMemory().size() );

assertSame( sm, c1Mem.getSegmentMemory()); // c1SMem repoints back to original Smem

wm.insert(new A(1));
Expand Down Expand Up @@ -346,8 +334,6 @@ public void testPopulatedSharedLiaNode() throws Exception {

//SegmentMemory b2Smem = sm.getFirst().remove();
assertSame( b2Smem, b2Mem.getSegmentMemory());
assertEquals( 0, b2Mem.getLeftTupleMemory().size() );
assertEquals( 0, b2Mem.getRightTupleMemory().size() );

wm.insert(new A(1));
wm.fireAllRules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,10 @@ private static void processLeftTuples(LeftTupleNode node, InternalWorkingMemory
Iterator<InternalFactHandle> it = omem.iterator();
while (it.hasNext()) {
InternalFactHandle fh = it.next();
for (LeftTuple lt = fh.getFirstLeftTuple(); lt != null; lt = lt.getHandleNext()) {
LeftTuple lt = fh.getFirstLeftTuple();
while (lt != null) {
LeftTuple nextLt = lt.getHandleNext();

// Each lt is for a different lian, skip any lian not associated with the rule. Need to use lt parent (souce) not child to check the lian.
if (lt.getTupleSource().isAssociatedWith(rule)) {
SegmentMemory childSmem = sm;
Expand All @@ -808,7 +811,16 @@ private static void processLeftTuples(LeftTupleNode node, InternalWorkingMemory
childSmem = sm.getFirst();
}
visitChild(lt, childSmem, insert, wm, rule);

if (lt.getHandlePrevious() != null) {
lt.getHandlePrevious().setHandleNext( nextLt );
}
if (nextLt != null) {
nextLt.setHandlePrevious( lt.getHandlePrevious() );
}
}

lt = nextLt;
}
}
}
Expand Down

0 comments on commit e01dca6

Please sign in to comment.