Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Dec 12, 2024
1 parent d43f2d5 commit 6f5b24a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ public void removeRule(TerminalNode tn, Collection<InternalWorkingMemory> wms, I
}
}

Set<SegmentMemoryPair> smemsToNotify = new HashSet<>();

if (exclBranchRoots.isEmpty()) {
LeftTupleNode lian = tn.getPathNodes()[0];
processLeftTuples(lian, false, tn, wms);
Expand All @@ -163,7 +161,7 @@ public void removeRule(TerminalNode tn, Collection<InternalWorkingMemory> wms, I

// Process existing branches from the split points
Set<Integer> visited = new HashSet<>();
exclBranchRoots.forEach(pair -> Remove.processMerges(pair.parent, tn, kBase, wms, visited, smemsToNotify));
exclBranchRoots.forEach(pair -> Remove.processMerges(pair.parent, tn, kBase, wms, visited));
}

for (InternalWorkingMemory wm : wms) {
Expand All @@ -174,8 +172,6 @@ public void removeRule(TerminalNode tn, Collection<InternalWorkingMemory> wms, I
pmem.getRuleAgendaItem().dequeue();
}
}

smemsToNotify.forEach(pair -> pair.sm.notifyRuleLinkSegment(pair.wm));
}

public static void notifyImpactedSegments(SegmentMemory smem, InternalWorkingMemory wm, Set<SegmentMemoryPair> segmentsToNotify) {
Expand Down Expand Up @@ -736,8 +732,7 @@ private static void removeExistingPaths(List<Pair> exclBranchRoots, TerminalNode
}
}


private static void processMerges(LeftTupleNode splitNode, TerminalNode tn, InternalRuleBase kBase, Collection<InternalWorkingMemory> wms, Set<Integer> visited, Set<SegmentMemoryPair> smemsToNotify) {
private static void processMerges(LeftTupleNode splitNode, TerminalNode tn, InternalRuleBase kBase, Collection<InternalWorkingMemory> wms, Set<Integer> visited) {
// it's possible for a rule to have multiple exclBranches, pointing to the same parent. So need to ensure it's processed once.
if ( !visited.add(splitNode.getId())) {
return;
Expand Down Expand Up @@ -766,10 +761,7 @@ private static void processMerges(LeftTupleNode splitNode, TerminalNode tn, Inte
}

SegmentPrototype proto2 = kBase.getSegmentPrototype(ltn);

mergeSegments(proto1, proto2, kBase, wms);

notifyImpactedSegments(wms, proto1, smemsToNotify);
}
}

Expand Down Expand Up @@ -1443,17 +1435,6 @@ private static void updatePaths(SegmentPrototype proto, Collection<InternalWorki
}
}

private static void notifyImpactedSegments(Collection<InternalWorkingMemory> wms, SegmentPrototype proto1, Set<SegmentMemoryPair> smemsToNotify) {
// any impacted segments must be notified for potential linking
for (InternalWorkingMemory wm : wms) {
Memory mem1 = wm.getNodeMemories().peekNodeMemory(proto1.getRootNode());
if (mem1 != null && mem1.getSegmentMemory() != null) {
// there was a split segment, both need notifying.
notifyImpactedSegments(mem1.getSegmentMemory(), wm, smemsToNotify);
}
}
}

private static void setNodeTypes(SegmentPrototype proto, LeftTupleNode[] protoNodes) {
int nodeTypesInSegment = 0;
for ( LeftTupleNode node : protoNodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.junit.jupiter.api.Disabled;

@Disabled("It gets stuck. See issue #6190")
public class AddRemoveGenerated2RulesNotNotTest extends AbstractAddRemoveGenerated2RulesTest {

public static Stream<ConstraintsPair> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.junit.jupiter.api.Disabled;

@Disabled("It gets stuck. See issue #6190")
public class AddRemoveGenerated2RulesNotTest extends AbstractAddRemoveGenerated2RulesTest {

public static Stream<ConstraintsPair> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,36 @@ public void testInsertFactsFireRulesRemoveRulesReinsertRulesRevertedRules() {

AddRemoveTestCases.insertFactsFireRulesRemoveRulesReinsertRules1(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, 1, 2);
}

@Test
@Timeout(40000)
public void testInsertFactsRemoveRulesFireRulesRemoveRules() {
String rule1 = """
package com.rules;
global java.util.List list
rule R1
when
exists(Integer())
not(Double() and Double())
Integer() not(Double() and Double())
then
list.add('R1');
end
""";

String rule2 = """
package com.rules;
global java.util.List list
rule R2
when
exists(Integer())
not(Double() and Double())
exists(Integer())
then
list.add('R2');
end
""";

AddRemoveTestCases.insertFactsRemoveRulesFireRulesRemoveRules2(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, 1);
}
}

0 comments on commit 6f5b24a

Please sign in to comment.