use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class NodeSegmentUnlinkingTest method tesMultiNodeSegmentDifferentInitialisationPoints.
@Test
public void tesMultiNodeSegmentDifferentInitialisationPoints() {
setUp(JOIN_NODE);
// Initialise from n3
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
createSegmentMemory(n3, ksession);
BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n1);
assertNull(bm.getSegmentMemory());
bm = (BetaMemory) ksession.getNodeMemory(n3);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n4);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n5);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n6);
assertEquals(8, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
// Initialise from n4
kBase = KnowledgeBaseFactory.newKnowledgeBase();
ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
bm = createSegmentMemory(n4, ksession);
bm = (BetaMemory) ksession.getNodeMemory(n1);
assertNull(bm.getSegmentMemory());
bm = (BetaMemory) ksession.getNodeMemory(n3);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n4);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n5);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n6);
assertEquals(8, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
// Initialise from n5
kBase = KnowledgeBaseFactory.newKnowledgeBase();
ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
createSegmentMemory(n5, ksession);
bm = (BetaMemory) ksession.getNodeMemory(n1);
assertNull(bm.getSegmentMemory());
bm = (BetaMemory) ksession.getNodeMemory(n3);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n4);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n5);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n6);
assertEquals(8, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
// Initialise from n6
kBase = KnowledgeBaseFactory.newKnowledgeBase();
ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
createSegmentMemory(n6, ksession);
bm = (BetaMemory) ksession.getNodeMemory(n1);
assertNull(bm.getSegmentMemory());
bm = (BetaMemory) ksession.getNodeMemory(n3);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n4);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n5);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
bm = (BetaMemory) ksession.getNodeMemory(n6);
assertEquals(8, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testExecuteQueueActions.
@Test
@Ignore
public void testExecuteQueueActions() {
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final ReentrantAction action = new ReentrantAction();
ksession.addPropagation(action, true);
ksession.flushPropagations();
assertEquals(2, action.counter.get());
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testBasicWorkingMemoryActions.
/*
* @see JBRULES-356
*/
@Test
@Ignore
public void testBasicWorkingMemoryActions() {
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final TruthMaintenanceSystem tms = TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem(ksession);
final String string = "test";
FactHandle fd = ksession.insert(string);
FactHandle fz = tms.insert(string, 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.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testGlobalResolver.
@Test
public void testGlobalResolver() {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("global1", "value1");
map.put("global2", "value2");
final GlobalResolver resolver = new MapGlobalResolver(map);
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
ksession.setGlobalResolver(resolver);
assertEquals("value1", ksession.getGlobal("global1"));
assertEquals("value2", ksession.getGlobal("global2"));
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testId.
@Test
public void testId() {
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
assertEquals(0, ksession.getIdentifier());
ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
assertEquals(1, ksession.getIdentifier());
}
Aggregations