use of org.drools.core.common.InternalWorkingMemory in project jbpm by kiegroup.
the class ProcessTimerTest method testOnEntryTimerWorkItemExecuted.
@Test
public void testOnEntryTimerWorkItemExecuted() throws Exception {
Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <globals>\n" + " <global identifier=\"myList\" type=\"java.util.List\" />\n" + " </globals>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <workItem id=\"2\" name=\"Work\" >\n" + " <timers>\n" + " <timer id=\"1\" delay=\"300\" >\n" + " <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" + " </timer>\n" + " </timers>\n" + " <work name=\"Human Task\" >\n" + " </work>\n" + " </workItem>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>");
builder.addRuleFlow(source);
KieSession session = createKieSession(builder.getPackages());
List<String> myList = new ArrayList<String>();
session.setGlobal("myList", myList);
session.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.drools.timer");
assertEquals(0, myList.size());
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(1, ((InternalProcessRuntime) ((InternalWorkingMemory) session).getProcessRuntime()).getTimerManager().getTimers().size());
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// do nothing
}
assertEquals(1, myList.size());
session.dispose();
}
use of org.drools.core.common.InternalWorkingMemory in project drools by kiegroup.
the class SegmentCreationTest method testSinglePattern.
@Test
public void testSinglePattern() throws Exception {
KieBase kbase = buildKnowledgeBase(" A() \n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtn = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
wm.insert(new LinkingTest.A());
wm.flushPropagations();
// LiaNode and Rule are in same segment
LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
SegmentMemory smem = liaMem.getSegmentMemory();
assertNull(smem);
}
use of org.drools.core.common.InternalWorkingMemory in project drools by kiegroup.
the class SegmentCreationTest method testSubnetworkNoSharing.
@Test
public void testSubnetworkNoSharing() throws Exception {
KieBase kbase = buildKnowledgeBase(" A() not ( B() and C() ) \n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
JoinNode bNode = (JoinNode) liaNode.getSinkPropagator().getSinks()[0];
JoinNode cNode = (JoinNode) bNode.getSinkPropagator().getSinks()[0];
RightInputAdapterNode riaNode = (RightInputAdapterNode) cNode.getSinkPropagator().getSinks()[0];
NotNode notNode = (NotNode) liaNode.getSinkPropagator().getSinks()[1];
RuleTerminalNode rtn1 = (RuleTerminalNode) notNode.getSinkPropagator().getSinks()[0];
wm.insert(new LinkingTest.A());
wm.insert(new LinkingTest.B());
wm.insert(new LinkingTest.C());
wm.flushPropagations();
// LiaNode is in it's own segment
LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
SegmentMemory smem = liaMem.getSegmentMemory();
assertEquals(liaNode, smem.getRootNode());
assertEquals(liaNode, smem.getTipNode());
assertNull(smem.getNext());
smem = smem.getFirst();
// it's nested inside of smem, so lookup from wm
SegmentMemory bSmem = wm.getNodeMemory(bNode).getSegmentMemory();
assertEquals(smem, bSmem);
assertEquals(bNode, bSmem.getRootNode());
assertEquals(riaNode, bSmem.getTipNode());
BetaMemory bm = (BetaMemory) wm.getNodeMemory(notNode);
assertEquals(bm.getSegmentMemory(), smem.getNext());
// check subnetwork ref was made
assertEquals(bSmem, bm.getRiaRuleMemory().getSegmentMemory());
}
use of org.drools.core.common.InternalWorkingMemory in project drools by kiegroup.
the class SegmentCreationTest method testSingleEmptyLhs.
@Test
public void testSingleEmptyLhs() throws Exception {
KieBase kbase = buildKnowledgeBase(" ");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode aotn = getObjectTypeNode(kbase, InitialFactImpl.class);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
RuleTerminalNode rtn = (RuleTerminalNode) liaNode.getSinkPropagator().getSinks()[0];
wm.insert(new LinkingTest.A());
wm.flushPropagations();
// LiaNode and Rule are in same segment
LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
SegmentMemory smem = liaMem.getSegmentMemory();
assertEquals(liaNode, smem.getRootNode());
assertEquals(rtn, smem.getTipNode());
assertNull(smem.getNext());
assertNull(smem.getFirst());
}
use of org.drools.core.common.InternalWorkingMemory in project drools by kiegroup.
the class SegmentCreationTest method testSingleSharedPattern.
@Test
public void testSingleSharedPattern() throws Exception {
KieBase kbase = buildKnowledgeBase(" A() B()\n", " A() B()\n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
JoinNode beta = (JoinNode) liaNode.getSinkPropagator().getSinks()[0];
RuleTerminalNode rtn1 = (RuleTerminalNode) beta.getSinkPropagator().getSinks()[0];
RuleTerminalNode rtn2 = (RuleTerminalNode) beta.getSinkPropagator().getSinks()[1];
wm.insert(new LinkingTest.A());
wm.insert(new LinkingTest.B());
wm.fireAllRules();
// LiaNode is in it's own segment
LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
SegmentMemory smem = liaMem.getSegmentMemory();
assertEquals(liaNode, smem.getRootNode());
assertEquals(beta, smem.getTipNode());
// each RTN is in it's own segment
SegmentMemory rtnSmem1 = smem.getFirst();
assertEquals(rtn1, rtnSmem1.getRootNode());
assertEquals(rtn1, rtnSmem1.getTipNode());
SegmentMemory rtnSmem2 = rtnSmem1.getNext();
assertEquals(rtn2, rtnSmem2.getRootNode());
assertEquals(rtn2, rtnSmem2.getTipNode());
}
Aggregations