use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class PropertyChangeListenerTest method test1.
@Test
public void test1() {
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, this.entryPoint, new ClassObjectType(State.class), buildContext);
objectTypeNode.attach(buildContext);
final MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink(sink);
final State a = new State("go");
ksession.insert(a, true);
ksession.fireAllRules();
assertEquals(1, sink.getAsserted().size());
a.setState("stop");
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ReteTest method testNotShadowed.
@Test
@Ignore
public void testNotShadowed() {
Properties properties = new Properties();
properties.setProperty("drools.shadowProxyExcludes", "org.drools.core.test.model.Cheese");
RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
InternalKnowledgeBase kBase = (InternalKnowledgeBase) RuleBaseFactory.newRuleBase(conf);
buildContext = new BuildContext(kBase, Collections.emptyList());
final StatefulKnowledgeSessionImpl ksession = new StatefulKnowledgeSessionImpl(1L, kBase);
// Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
final Rete rete = kBase.getRete();
final EntryPointNode entryPoint = new EntryPointNode(0, rete, buildContext);
entryPoint.attach(buildContext);
final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, entryPoint, new ClassObjectType(Cheese.class), buildContext);
objectTypeNode.attach(buildContext);
final MockObjectSink sink1 = new MockObjectSink();
objectTypeNode.addObjectSink(sink1);
// There are no String ObjectTypeNodes, make sure its not propagated
final Cheese cheese = new Cheese("brie", 15);
final DefaultFactHandle h1 = new DefaultFactHandle(1, cheese);
rete.assertObject(h1, pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null), ksession);
ksession.fireAllRules();
final Object[] results = (Object[]) sink1.getAsserted().get(0);
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ReteTest method testAssertObject.
/**
* Test asserts correctly propagate
*
* @throws Exception
*/
@Test
public void testAssertObject() throws Exception {
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
// Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
final Rete rete = kBase.getRete();
final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, this.entryPoint, new ClassObjectType(List.class), buildContext);
objectTypeNode.attach(buildContext);
final MockObjectSink sink1 = new MockObjectSink();
objectTypeNode.addObjectSink(sink1);
// There are no String ObjectTypeNodes, make sure its not propagated
final String string = "String";
final DefaultFactHandle h1 = new DefaultFactHandle(1, string);
rete.assertObject(h1, pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null), ksession);
assertLength(0, sink1.getAsserted());
// There is a List ObjectTypeNode, make sure it was propagated
final List list = new ArrayList();
final DefaultFactHandle h2 = new DefaultFactHandle(1, list);
rete.assertObject(h2, pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null), ksession);
ksession.fireAllRules();
final List asserted = sink1.getAsserted();
assertLength(1, asserted);
final Object[] results = (Object[]) asserted.get(0);
assertSame(list, ((DefaultFactHandle) results[0]).getObject());
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class RuleUnlinkingTest method testRuleSegmentsAllLinkedTestMasks.
@Test
public void testRuleSegmentsAllLinkedTestMasks() {
setUp(JOIN_NODE);
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase);
PathMemory rs = wm.getNodeMemory(rtn1);
assertFalse(rs.isRuleLinked());
assertEquals(1, rs.getAllLinkedMaskTest());
rs = wm.getNodeMemory(rtn2);
assertFalse(rs.isRuleLinked());
assertEquals(3, rs.getAllLinkedMaskTest());
rs = wm.getNodeMemory(rtn3);
assertFalse(rs.isRuleLinked());
assertEquals(7, rs.getAllLinkedMaskTest());
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class RuleUnlinkingTest method testSegmentNodeReferencesToSegments.
@Test
public void testSegmentNodeReferencesToSegments() {
setUp(JOIN_NODE);
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase);
BetaMemory bm = null;
List<PathMemory> list;
PathMemory rtn1Rs = wm.getNodeMemory(rtn1);
PathMemory rtn2Rs = wm.getNodeMemory(rtn2);
PathMemory rtn3Rs = wm.getNodeMemory(rtn3);
// n1
bm = createSegmentMemory(n1, wm);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(1, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(3, list.size());
assertTrue(list.contains(rtn1Rs));
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n2
bm = createSegmentMemory(n2, wm);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(1, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(3, list.size());
assertTrue(list.contains(rtn1Rs));
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n3
bm = createSegmentMemory(n3, wm);
assertEquals(8, bm.getNodePosMaskBit());
assertEquals(15, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(1, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(3, list.size());
assertTrue(list.contains(rtn1Rs));
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n4
bm = createSegmentMemory(n4, wm);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(3, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(2, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(2, list.size());
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n5
bm = createSegmentMemory(n5, wm);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(3, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(2, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(2, list.size());
assertTrue(list.contains(rtn2Rs));
assertTrue(list.contains(rtn3Rs));
// n6
bm = createSegmentMemory(n6, wm);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(7, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(4, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(1, list.size());
assertTrue(list.contains(rtn3Rs));
// n7
bm = createSegmentMemory(n7, wm);
assertEquals(2, bm.getNodePosMaskBit());
assertEquals(7, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(4, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(1, list.size());
assertTrue(list.contains(rtn3Rs));
// n8
bm = createSegmentMemory(n8, wm);
assertEquals(4, bm.getNodePosMaskBit());
assertEquals(7, bm.getSegmentMemory().getAllLinkedMaskTest());
assertEquals(4, bm.getSegmentMemory().getSegmentPosMaskBit());
list = bm.getSegmentMemory().getPathMemories();
assertEquals(1, list.size());
assertTrue(list.contains(rtn3Rs));
}
Aggregations