use of org.drools.mvel.compiler.CheeseEqual in project drools by kiegroup.
the class StatefulSessionTest method testGetFactHandleIdentityBehavior.
@Test
public void testGetFactHandleIdentityBehavior() throws Exception {
KieBaseTestConfiguration identityConfig = TestParametersUtil.getIdentityInstanceOf(kieBaseTestConfiguration);
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", identityConfig);
KieSession ksession = kbase.newKieSession();
final CheeseEqual cheese = new CheeseEqual("stilton", 10);
ksession.insert(cheese);
final FactHandle fh1 = ksession.getFactHandle(new Cheese("stilton", 10));
assertNull(fh1);
final FactHandle fh2 = ksession.getFactHandle(cheese);
assertNotNull(fh2);
}
use of org.drools.mvel.compiler.CheeseEqual in project drools by kiegroup.
the class TruthMaintenanceTest method testLogicalInsertionsUpdateEqual.
@Test(timeout = 10000)
@Ignore("Currently cannot support updates")
public // @Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation")
void testLogicalInsertionsUpdateEqual() throws Exception {
// calling update on a justified FH, states it
KieBase kbase = loadKnowledgeBase("test_LogicalInsertionsUpdateEqual.drl");
KieSession ksession = kbase.newKieSession();
try {
final Person p = new Person("person");
p.setAge(2);
FactHandle h = ksession.insert(p);
assertEquals(1, ksession.getObjects().size());
ksession.fireAllRules();
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
assertEquals(2, ksession.getObjects().size());
Collection l = ksession.getObjects(new ClassObjectFilter(CheeseEqual.class));
assertEquals(1, l.size());
assertEquals(3, ((CheeseEqual) l.iterator().next()).getPrice());
h = getFactHandle(h, ksession);
ksession.delete(h);
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
Collection list = ksession.getObjects();
// CheeseEqual was updated, making it stated, so it wouldn't have been logically deleted
assertEquals(1, list.size());
assertEquals(new CheeseEqual("person", 3), list.iterator().next());
FactHandle fh = ksession.getFactHandle(list.iterator().next());
ksession.delete(fh);
list = ksession.getObjects();
assertEquals(0, list.size());
TruthMaintenanceSystem tms = TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem((ReteEvaluator) ksession);
final java.lang.reflect.Field field = tms.getClass().getDeclaredField("equalityKeyMap");
field.setAccessible(true);
final ObjectHashMap m = (ObjectHashMap) field.get(tms);
field.setAccessible(false);
assertEquals("assertMap should be empty", 0, m.size());
} finally {
ksession.dispose();
}
}
use of org.drools.mvel.compiler.CheeseEqual in project drools by kiegroup.
the class TruthMaintenanceTest method testLogicalInsertionsAccumulatorPattern.
@Test(timeout = 10000)
public void testLogicalInsertionsAccumulatorPattern() throws Exception {
// JBRULES-449
KieBase kbase = loadKnowledgeBase("test_LogicalInsertionsAccumulatorPattern.drl");
KieSession ksession = kbase.newKieSession();
try {
ksession.setGlobal("ga", "a");
ksession.setGlobal("gb", "b");
ksession.setGlobal("gs", new Short((short) 3));
ksession.fireAllRules();
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
FactHandle h = ksession.insert(new Integer(6));
assertEquals(1, ksession.getObjects().size());
ksession.fireAllRules();
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
assertEquals("There should be 2 CheeseEqual in Working Memory, 1 justified, 1 stated", 2, ksession.getObjects(new ClassObjectFilter(CheeseEqual.class)).size());
assertEquals(6, ksession.getObjects().size());
h = getFactHandle(h, ksession);
ksession.delete(h);
ksession.fireAllRules();
for (Object o : ksession.getObjects()) {
System.out.println(o);
}
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
assertEquals(0, ksession.getObjects(new ClassObjectFilter(CheeseEqual.class)).size());
assertEquals(0, ksession.getObjects(new ClassObjectFilter(Short.class)).size());
assertEquals(0, ksession.getObjects().size());
} finally {
ksession.dispose();
}
}
use of org.drools.mvel.compiler.CheeseEqual in project drools by kiegroup.
the class TruthMaintenanceTest method testLogicalInsertionsWithModify.
@Test(timeout = 10000)
public // @Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation")
void testLogicalInsertionsWithModify() throws Exception {
KieBase kbase = loadKnowledgeBase("test_LogicalInsertionsWithUpdate.drl");
KieSession ksession = kbase.newKieSession();
try {
final Person p = new Person("person");
p.setAge(2);
FactHandle h = ksession.insert(p);
assertEquals(1, ksession.getObjects().size());
ksession.fireAllRules();
ksession = getSerialisedStatefulKnowledgeSession(ksession, false);
assertEquals(2, ksession.getObjects().size());
Collection l = ksession.getObjects(new ClassObjectFilter(CheeseEqual.class));
assertEquals(1, l.size());
assertEquals(2, ((CheeseEqual) l.iterator().next()).getPrice());
h = getFactHandle(h, ksession);
ksession.delete(h);
ksession = getSerialisedStatefulKnowledgeSession(ksession, false);
assertEquals(0, ksession.getObjects().size());
TruthMaintenanceSystem tms = TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem((ReteEvaluator) ksession);
final java.lang.reflect.Field field = tms.getClass().getDeclaredField("equalityKeyMap");
field.setAccessible(true);
final ObjectHashMap m = (ObjectHashMap) field.get(tms);
field.setAccessible(false);
assertEquals("assertMap should be empty", 0, m.size());
} finally {
ksession.dispose();
}
}
use of org.drools.mvel.compiler.CheeseEqual in project drools by kiegroup.
the class StatefulSessionTest method testGetFactHandleEqualityBehavior.
@Test
public void testGetFactHandleEqualityBehavior() throws Exception {
KieBaseTestConfiguration equalityConfig = TestParametersUtil.getEqualityInstanceOf(kieBaseTestConfiguration);
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", equalityConfig);
KieSession ksession = kbase.newKieSession();
final CheeseEqual cheese = new CheeseEqual("stilton", 10);
ksession.insert(cheese);
final FactHandle fh = ksession.getFactHandle(new CheeseEqual("stilton", 10));
assertNotNull(fh);
}
Aggregations