use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.
the class NodeSegmentUnlinkingTest method testAllLinkedInWithJoinNodesOnly.
@Test
public void testAllLinkedInWithJoinNodesOnly() {
setUp(JOIN_NODE);
// make sure it created JoinNodes
assertEquals(JoinNode.class, n3.getClass());
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert("test1");
n3.assertObject(f1, context, ksession);
BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n3);
assertFalse(bm.getSegmentMemory().isSegmentLinked());
n4.assertObject(f1, context, ksession);
assertFalse(bm.getSegmentMemory().isSegmentLinked());
n5.assertObject(f1, context, ksession);
assertFalse(bm.getSegmentMemory().isSegmentLinked());
n6.assertObject(f1, context, ksession);
// only after all 4 nodes are populated, is the segment linked in
assertTrue(bm.getSegmentMemory().isSegmentLinked());
}
use of org.drools.kiesession.rulebase.InternalKnowledgeBase 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.rulebase.InternalKnowledgeBase 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.rulebase.InternalKnowledgeBase 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.rulebase.InternalKnowledgeBase in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testDifferentEntryPointsOnSameFact.
@Test
public void testDifferentEntryPointsOnSameFact() {
// JBRULES-2971
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
Rete rete = kBase.getRete();
NodeFactory nFacotry = new PhreakNodeFactory();
EntryPointNode epn = nFacotry.buildEntryPointNode(kBase.getReteooBuilder().getNodeIdsGenerator().getNextId(), RuleBasePartitionId.MAIN_PARTITION, kBase.getConfiguration().isMultithreadEvaluation(), rete, new EntryPointId("xxx"));
kBase.getRete().addObjectSink(epn);
KieSession ksession = kBase.newKieSession();
FactHandle f1 = ksession.insert("f1");
EntryPoint ep = ksession.getEntryPoint("xxx");
try {
ep.update(f1, "s1");
fail("Should throw an exception");
} catch (IllegalArgumentException e) {
}
try {
ep.retract(f1);
fail("Should throw an exception");
} catch (IllegalArgumentException e) {
}
ksession.update(f1, "s1");
assertNotNull(ksession.getObject(f1));
ksession.retract(f1);
ksession.retract(f1);
assertNull(ksession.getObject(f1));
}
Aggregations