Search in sources :

Example 16 with StatefulKnowledgeSessionImpl

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());
}
Also used : StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) BetaMemory(org.drools.core.reteoo.BetaMemory) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Test(org.junit.Test)

Example 17 with StatefulKnowledgeSessionImpl

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());
}
Also used : StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with StatefulKnowledgeSessionImpl

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());
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) FactHandle(org.kie.api.runtime.rule.FactHandle) EqualityKey(org.drools.core.common.EqualityKey) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with StatefulKnowledgeSessionImpl

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"));
}
Also used : HashMap(java.util.HashMap) StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) GlobalResolver(org.drools.core.spi.GlobalResolver) MapGlobalResolver(org.drools.core.base.MapGlobalResolver) MapGlobalResolver(org.drools.core.base.MapGlobalResolver) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Test(org.junit.Test)

Example 20 with StatefulKnowledgeSessionImpl

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());
}
Also used : StatefulKnowledgeSessionImpl(org.drools.kiesession.session.StatefulKnowledgeSessionImpl) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Test(org.junit.Test)

Aggregations

StatefulKnowledgeSessionImpl (org.drools.kiesession.session.StatefulKnowledgeSessionImpl)66 Test (org.junit.Test)57 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)34 ArrayList (java.util.ArrayList)15 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)15 KieBase (org.kie.api.KieBase)15 ClassObjectType (org.drools.core.base.ClassObjectType)14 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)14 BetaMemory (org.drools.core.reteoo.BetaMemory)14 List (java.util.List)13 InternalFactHandle (org.drools.core.common.InternalFactHandle)13 KieSession (org.kie.api.runtime.KieSession)12 FactHandle (org.kie.api.runtime.rule.FactHandle)11 MockObjectSink (org.drools.core.reteoo.MockObjectSink)10 BuildContext (org.drools.core.reteoo.builder.BuildContext)10 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)8 HashMap (java.util.HashMap)7 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)7 PathMemory (org.drools.core.reteoo.PathMemory)7 Rete (org.drools.core.reteoo.Rete)7