Search in sources :

Example 81 with InternalWorkingMemory

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();
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 82 with InternalWorkingMemory

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);
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 83 with InternalWorkingMemory

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());
}
Also used : NotNode(org.drools.core.reteoo.NotNode) SegmentMemory(org.drools.core.reteoo.SegmentMemory) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) BetaMemory(org.drools.core.reteoo.BetaMemory) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) KieBase(org.kie.api.KieBase) RightInputAdapterNode(org.drools.core.reteoo.RightInputAdapterNode) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 84 with InternalWorkingMemory

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());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 85 with InternalWorkingMemory

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());
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) KieBase(org.kie.api.KieBase) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Aggregations

InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)285 Test (org.junit.Test)217 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)140 KieBase (org.kie.api.KieBase)129 ArrayList (java.util.ArrayList)96 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)91 List (java.util.List)76 SegmentMemory (org.drools.core.reteoo.SegmentMemory)74 KieSession (org.kie.api.runtime.KieSession)71 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)69 JoinNode (org.drools.core.reteoo.JoinNode)62 BetaMemory (org.drools.core.reteoo.BetaMemory)57 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)48 PathMemory (org.drools.core.reteoo.PathMemory)48 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)45 BetaNode (org.drools.core.reteoo.BetaNode)44 FactHandle (org.kie.api.runtime.rule.FactHandle)44 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)35 AlphaNode (org.drools.core.reteoo.AlphaNode)35 ClassObjectType (org.drools.core.base.ClassObjectType)30