use of org.drools.core.common.NodeMemories in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeNodeMemories.
private static void writeNodeMemories(MarshallerWriteContext context, ProtobufMessages.RuleData.Builder _ksb) throws IOException {
InternalWorkingMemory wm = context.wm;
NodeMemories memories = wm.getNodeMemories();
// so we iterate over all of them and process only those that require it
for (BaseNode baseNode : context.sinks.values()) {
Memory memory = memories.peekNodeMemory(baseNode);
if (memory != null) {
ProtobufMessages.NodeMemory _node = null;
switch(memory.getNodeType()) {
case NodeTypeEnums.AccumulateNode:
{
_node = writeAccumulateNodeMemory(baseNode.getId(), memory);
break;
}
case NodeTypeEnums.RightInputAdaterNode:
{
_node = writeRIANodeMemory(baseNode.getId(), baseNode, memories);
break;
}
case NodeTypeEnums.FromNode:
case NodeTypeEnums.ReactiveFromNode:
{
_node = writeFromNodeMemory(baseNode.getId(), memory);
break;
}
case NodeTypeEnums.QueryElementNode:
{
_node = writeQueryElementNodeMemory(baseNode.getId(), memory, wm);
break;
}
}
if (_node != null) {
// not all node memories require serialization
_ksb.addNodeMemory(_node);
}
}
}
}
use of org.drools.core.common.NodeMemories in project drools by kiegroup.
the class Misc2Test method testBetaMemoryLeakOnSegmentUnlinking.
@Test
@Ignore
public void testBetaMemoryLeakOnSegmentUnlinking() {
// DROOLS-915
String drl = "rule R1 when\n" + " $a : Integer(this == 1)\n" + " $b : String()\n" + " $c : Integer(this == 2)\n" + " $d : Integer(this == 3)\n" + "then \n" + "end\n" + "rule R2 when\n" + " $a : Integer(this == 1)\n" + " $b : String()\n" + "then \n" + "end\n";
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
FactHandle fh1 = ksession.insert(1);
FactHandle fh2 = ksession.insert(2);
FactHandle fh3 = ksession.insert(3);
FactHandle fhtest = ksession.insert("test");
ksession.fireAllRules();
ksession.delete(fh3);
ksession.fireAllRules();
ksession.delete(fh1);
ksession.delete(fh2);
ksession.delete(fhtest);
ksession.fireAllRules();
NodeMemories nodeMemories = ((InternalWorkingMemory) ksession).getNodeMemories();
for (int i = 0; i < nodeMemories.length(); i++) {
Memory memory = nodeMemories.peekNodeMemory(i);
if (memory != null && memory.getSegmentMemory() != null) {
SegmentMemory segmentMemory = memory.getSegmentMemory();
System.out.println(memory);
LeftTuple deleteFirst = memory.getSegmentMemory().getStagedLeftTuples().getDeleteFirst();
System.out.println(deleteFirst);
assertNull(deleteFirst);
}
}
}
use of org.drools.core.common.NodeMemories in project drools by kiegroup.
the class RemoveRuleTest method testPopulatedSingleRuleNoSharing.
@Test
public void testPopulatedSingleRuleNoSharing() throws Exception {
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
wm.insert(new A(1));
wm.insert(new B(1));
wm.insert(new C(1));
wm.insert(new C(2));
wm.insert(new X(1));
wm.insert(new E(1));
wm.fireAllRules();
kbase.addPackages(buildKnowledgePackage("r1", " A() B() C(object == 2) X() E()\n"));
List list = new ArrayList();
wm.setGlobal("list", list);
ObjectTypeNode aotn = getObjectTypeNode(kbase, A.class);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
LiaNodeMemory lm = (LiaNodeMemory) wm.getNodeMemory(liaNode);
SegmentMemory sm = lm.getSegmentMemory();
assertNotNull(sm.getStagedLeftTuples().getInsertFirst());
wm.fireAllRules();
BetaMemory bMem = (BetaMemory) sm.getNodeMemories().get(1);
assertEquals(1, bMem.getLeftTupleMemory().size());
assertEquals(1, bMem.getRightTupleMemory().size());
BetaMemory eMem = (BetaMemory) sm.getNodeMemories().get(4);
assertEquals(1, eMem.getLeftTupleMemory().size());
assertEquals(1, eMem.getRightTupleMemory().size());
NodeMemories nms = wm.getNodeMemories();
assertEquals(12, countNodeMemories(nms));
assertNull(sm.getStagedLeftTuples().getInsertFirst());
assertEquals(1, list.size());
assertEquals("r1", ((Match) list.get(0)).getRule().getName());
kbase.removeRule("org.kie", "r1");
// still has OTN
assertEquals(6, countNodeMemories(nms));
}
use of org.drools.core.common.NodeMemories in project drools by kiegroup.
the class BetaMemoryLeakOnDeleteTest method testBetaMemoryLeakOnFactDelete.
@Test
public void testBetaMemoryLeakOnFactDelete() {
final String drl = "rule R1 when\n" + " $a : Integer(this == 1)\n" + " $b : String()\n" + " $c : Integer(this == 2)\n" + "then \n" + "end\n" + "rule R2 when\n" + " $a : Integer(this == 1)\n" + " $b : String()\n" + "then \n" + "end\n";
final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
final FactHandle fh1 = ksession.insert(1);
final FactHandle fh2 = ksession.insert("test");
ksession.fireAllRules();
ksession.delete(fh1);
ksession.delete(fh2);
ksession.fireAllRules();
final NodeMemories nodeMemories = ((InternalWorkingMemory) ksession).getNodeMemories();
for (int i = 0; i < nodeMemories.length(); i++) {
final Memory memory = nodeMemories.peekNodeMemory(i);
if (memory != null && memory.getSegmentMemory() != null) {
final LeftTuple deleteFirst = memory.getSegmentMemory().getStagedLeftTuples().getDeleteFirst();
assertThat(deleteFirst).isNull();
}
}
}
use of org.drools.core.common.NodeMemories in project drools by kiegroup.
the class MemoryLeakTest method testBetaMemoryLeakOnFactDelete.
@Test
public void testBetaMemoryLeakOnFactDelete() {
// DROOLS-913
String drl = "rule R1 when\n" + " $a : Integer(this == 1)\n" + " $b : String()\n" + " $c : Integer(this == 2)\n" + "then \n" + "end\n" + "rule R2 when\n" + " $a : Integer(this == 1)\n" + " $b : String()\n" + " $c : Integer(this == 3)\n" + "then \n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
FactHandle fh1 = ksession.insert(1);
FactHandle fh2 = ksession.insert(3);
FactHandle fh3 = ksession.insert("test");
ksession.fireAllRules();
ksession.delete(fh1);
ksession.delete(fh2);
ksession.delete(fh3);
ksession.fireAllRules();
NodeMemories nodeMemories = ((InternalWorkingMemory) ksession).getNodeMemories();
for (int i = 0; i < nodeMemories.length(); i++) {
Memory memory = nodeMemories.peekNodeMemory(i);
if (memory != null && memory.getSegmentMemory() != null) {
SegmentMemory segmentMemory = memory.getSegmentMemory();
System.out.println(memory);
LeftTuple deleteFirst = memory.getSegmentMemory().getStagedLeftTuples().getDeleteFirst();
if (segmentMemory.getRootNode() instanceof JoinNode) {
BetaMemory bm = (BetaMemory) segmentMemory.getNodeMemories().getFirst();
assertEquals(0, bm.getLeftTupleMemory().size());
}
System.out.println(deleteFirst);
assertNull(deleteFirst);
}
}
}
Aggregations