use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ScenarioRunner4JUnit method resetKieSession.
private void resetKieSession(final KieSession kieSession) {
final StatefulKnowledgeSessionImpl statefulKnowledgeSession = (StatefulKnowledgeSessionImpl) kieSession;
statefulKnowledgeSession.reset();
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class TruthMaintenanceTest method testLogicalInsertionsNot.
@Test(timeout = 10000)
public // @Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation")
void testLogicalInsertionsNot() throws Exception {
KieBase kbase = loadKnowledgeBase("test_LogicalInsertionsNot.drl");
KieSession ksession = kbase.newKieSession();
final Person a = new Person("a");
final Cheese cheese = new Cheese("brie", 1);
ksession.setGlobal("cheese", cheese);
ksession.fireAllRules();
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
Collection list = ksession.getObjects();
assertEquals("i was not asserted by not a => i.", 1, list.size());
assertEquals("i was not asserted by not a => i.", cheese, list.iterator().next());
FactHandle h = ksession.insert(a);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
// no need to fire rules, assertion alone removes justification for i,
// so it should be deleted.
// workingMemory.fireAllRules();
ksession.fireAllRules();
list = ksession.getObjects();
assertEquals("a was not asserted or i not deleted.", 1, list.size());
assertEquals("a was asserted.", a, list.iterator().next());
assertFalse("i was not rectracted.", list.contains(cheese));
// no rules should fire, but nevertheless...
// workingMemory.fireAllRules();
assertEquals("agenda should be empty.", 0, ((InternalAgenda) ((StatefulKnowledgeSessionImpl) ksession).getAgenda()).agendaSize());
h = getFactHandle(h, ksession);
ksession.retract(h);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.fireAllRules();
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
list = ksession.getObjects();
assertEquals("i was not asserted by not a => i.", 1, list.size());
assertEquals("i was not asserted by not a => i.", cheese, list.iterator().next());
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class FactHandleMarshallingTest method createWorkingMemory.
private StatefulKnowledgeSessionImpl createWorkingMemory(InternalKnowledgeBase kBase) {
// WorkingMemoryEntryPoint
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
SessionConfiguration sessionConf = ((SessionConfiguration) ksconf);
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase, true, sessionConf, EnvironmentFactory.newEnvironment());
return wm;
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class SegmentMemoryPrototypeTest method testSessionCache.
@Test
public void testSessionCache() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(DRL.getBytes()), ResourceType.DRL);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kbase.newKieSession();
checkKieSession(ksession);
ksession.dispose();
ksession.reset();
checkKieSession(ksession);
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class TruthMaintenanceTest method testLogicalThenStatedShadowSingleOccurance.
@Test(timeout = 10000)
public void testLogicalThenStatedShadowSingleOccurance() {
String droolsSource = "package org.drools.tms.test; \n" + "global java.util.List list; \n" + "rule Justify \n" + "when \n" + " String( this == 'go1' ) " + "then \n" + " insertLogical( 'f1' ); \n" + "end \n" + "rule StillHere \n" + "when \n" + " String( this == 'go2' ) " + " s : String( this == 'f1' ) " + "then \n" + " list.add( s ); \n" + "end \n" + "";
KieBaseConfiguration kieConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kieConf.setOption(EqualityBehaviorOption.IDENTITY);
KieBase kbase = loadKnowledgeBaseFromString(kieConf, droolsSource);
KieSession session = kbase.newKieSession();
List list = new ArrayList();
session.setGlobal("list", list);
session.insert("go1");
session.fireAllRules();
TruthMaintenanceSystem tms = ((StatefulKnowledgeSessionImpl) session).getTruthMaintenanceSystem();
InternalFactHandle jfh1 = tms.get("f1").getLogicalFactHandle();
assertEquals(EqualityKey.JUSTIFIED, jfh1.getEqualityKey().getStatus());
InternalFactHandle fh1 = (InternalFactHandle) session.insert("f1");
InternalFactHandle fh2 = (InternalFactHandle) session.insert("f2");
session.insert("go2");
session.fireAllRules();
assertEquals(EqualityKey.STATED, fh1.getEqualityKey().getStatus());
assertSame(fh1.getEqualityKey(), jfh1.getEqualityKey());
assertNotSame(fh1, jfh1);
EqualityKey key = jfh1.getEqualityKey();
assertSame(fh1.getEqualityKey(), key);
assertNotSame(fh1, jfh1);
assertEquals(2, key.size());
assertSame(jfh1, key.getLogicalFactHandle());
// Make sure f1 only occurs once
assertEquals(1, list.size());
assertEquals("f1", list.get(0));
}
Aggregations