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());
}
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());
}
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());
}
Aggregations