Search in sources :

Example 1 with TruthMaintenanceSystemFactoryImpl

use of org.drools.tms.TruthMaintenanceSystemFactoryImpl in project drools by kiegroup.

the class MemoryLeakTest method testStagedTupleLeak.

@Test
public void testStagedTupleLeak() throws Exception {
    // BZ-1056599
    String str = "rule R1 when\n" + "    $i : Integer()\n" + "then\n" + "    insertLogical( $i.toString() );\n" + "end\n" + "\n" + "rule R2 when\n" + "    $i : Integer()\n" + "then\n" + "    delete( $i );\n" + "end\n" + "\n" + "rule R3 when\n" + "    $l : Long()\n" + "    $s : String( this == $l.toString() )\n" + "then\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    TruthMaintenanceSystemFactoryImpl tms = (TruthMaintenanceSystemFactoryImpl) TruthMaintenanceSystemFactory.get();
    tms.clearEntryPointsMap();
    for (int i = 0; i < 10; i++) {
        ksession.insert(i);
        ksession.fireAllRules();
    }
    Rete rete = ((RuleBase) kbase).getRete();
    JoinNode joinNode = null;
    for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
        if (String.class == otn.getObjectType().getValueType().getClassType()) {
            joinNode = (JoinNode) otn.getObjectSinkPropagator().getSinks()[0];
            break;
        }
    }
    assertNotNull(joinNode);
    InternalWorkingMemory wm = (InternalWorkingMemory) ksession;
    BetaMemory memory = (BetaMemory) wm.getNodeMemory(joinNode);
    TupleSets<RightTuple> stagedRightTuples = memory.getStagedRightTuples();
    assertNull(stagedRightTuples.getDeleteFirst());
    assertNull(stagedRightTuples.getInsertFirst());
    // DROOLS-6809
    assertEquals(1, tms.getEntryPointsMapSize());
    ksession.dispose();
    assertEquals(0, tms.getEntryPointsMapSize());
}
Also used : TruthMaintenanceSystemFactoryImpl(org.drools.tms.TruthMaintenanceSystemFactoryImpl) Rete(org.drools.core.reteoo.Rete) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) BetaMemory(org.drools.core.reteoo.BetaMemory) RightTuple(org.drools.core.reteoo.RightTuple) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) RuleBase(org.drools.core.impl.RuleBase) Test(org.junit.Test)

Aggregations

InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 RuleBase (org.drools.core.impl.RuleBase)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1 JoinNode (org.drools.core.reteoo.JoinNode)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 Rete (org.drools.core.reteoo.Rete)1 RightTuple (org.drools.core.reteoo.RightTuple)1 TruthMaintenanceSystemFactoryImpl (org.drools.tms.TruthMaintenanceSystemFactoryImpl)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1