Search in sources :

Example 1 with MockActivation

use of org.drools.core.test.model.MockActivation in project drools by kiegroup.

the class LazyTMSEnablingTest method shouldEnableTMSForSpecificType.

@Test
public void shouldEnableTMSForSpecificType() throws Exception {
    final String stringFact1 = "toto";
    final String stringFact2 = "toto";
    final String anotherString = "tata";
    final Integer intFact1 = 99;
    final Integer intFact2 = 99;
    final Double doubleFact = 77.8;
    ObjectTypeConf stringTypeConf = ksession.getObjectTypeConfigurationRegistry().getObjectTypeConf(ksession.getEntryPoint(), stringFact1);
    ObjectTypeConf intTypeConf = ksession.getObjectTypeConfigurationRegistry().getObjectTypeConf(ksession.getEntryPoint(), intFact1);
    ksession.insert(stringFact1);
    ksession.insert(anotherString);
    ksession.insert(intFact1);
    ksession.insert(doubleFact);
    for (ObjectTypeConf conf : ksession.getObjectTypeConfigurationRegistry().values()) {
        assertFalse("TMS shouldn't be enabled for any type, since no logical insert was done.", conf.isTMSEnabled());
    }
    ksession.getTruthMaintenanceSystem().insert(stringFact2, null, null, new MockActivation());
    assertTrue("Should have enabled TMS for Strings.", stringTypeConf.isTMSEnabled());
    assertFalse("Shouldn't have enabled TMS for Integers.", intTypeConf.isTMSEnabled());
    ksession.getTruthMaintenanceSystem().insert(intFact2, null, null, new MockActivation());
    assertTrue("Now it should have enabled TMS for Integers!.", intTypeConf.isTMSEnabled());
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) MockActivation(org.drools.core.test.model.MockActivation) Test(org.junit.Test)

Example 2 with MockActivation

use of org.drools.core.test.model.MockActivation in project drools by kiegroup.

the class ReteooWorkingMemoryTest method testBasicWorkingMemoryActions.

/*
     * @see JBRULES-356
     */
@Test
@Ignore
public void testBasicWorkingMemoryActions() {
    InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
    final TruthMaintenanceSystem tms = ((NamedEntryPoint) ksession.getWorkingMemoryEntryPoint(EntryPointId.DEFAULT.getEntryPointId())).getTruthMaintenanceSystem();
    final String string = "test";
    FactHandle fd = ksession.insert(string);
    FactHandle fz = ksession.getTruthMaintenanceSystem().insert(string, null, null, new MockActivation());
    assertEquals(1, tms.getEqualityKeyMap().size());
    EqualityKey key = tms.get(string);
    assertSame(fz, key.getFactHandle());
    assertEquals(2, key.size());
    ksession.update(fd, string);
    assertEquals(1, tms.getEqualityKeyMap().size());
    key = tms.get(string);
    assertSame(fz, key.getFactHandle());
    assertEquals(2, key.size());
    ksession.retract(fd);
    assertEquals(1, tms.getEqualityKeyMap().size());
    key = tms.get(string);
    fd = ksession.insert(string);
    assertEquals(1, tms.getEqualityKeyMap().size());
    assertEquals(1, tms.getEqualityKeyMap().size());
    key = tms.get(string);
    assertSame(fd, key.getFactHandle());
    assertEquals(1, key.size());
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) FactHandle(org.kie.api.runtime.rule.FactHandle) EqualityKey(org.drools.core.common.EqualityKey) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) MockActivation(org.drools.core.test.model.MockActivation) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with MockActivation

use of org.drools.core.test.model.MockActivation in project drools by kiegroup.

the class LazyTMSEnablingTest method shouldLazilyAdd.

@Test
public void shouldLazilyAdd() throws Exception {
    final String fact1 = "logical";
    ksession.insert(fact1);
    assertEquals("Shouldn't have anything, since no logical insert was performed.", 0, tms.getEqualityKeyMap().size());
    final String fact2 = "logical";
    ksession.getTruthMaintenanceSystem().insert(fact2, null, null, new MockActivation());
    assertEquals("Now that a logical insert was done, it should have an element.", 1, tms.getEqualityKeyMap().size());
    // Make sure the internals are fine.
    ObjectTypeConf typeConf = ksession.getObjectTypeConfigurationRegistry().getObjectTypeConf(ksession.getEntryPoint(), fact1);
    assertTrue("Should have enabled TMS", typeConf.isTMSEnabled());
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) MockActivation(org.drools.core.test.model.MockActivation) Test(org.junit.Test)

Aggregations

MockActivation (org.drools.core.test.model.MockActivation)3 Test (org.junit.Test)3 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)2 EqualityKey (org.drools.core.common.EqualityKey)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 TruthMaintenanceSystem (org.drools.core.common.TruthMaintenanceSystem)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)1 Ignore (org.junit.Ignore)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1