Search in sources :

Example 16 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerDuplicatedRegister.

@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerDuplicatedRegister() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("async", new AsyncWorkItemHandler(executorService, "org.jbpm.executor.commands.PrintOutCommand"));
            return handlers;
        }

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    countDownListener.waitTillCompleted();
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    manager.close();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 17 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerWthSecurityManager.

@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerWthSecurityManager() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("async", new AsyncWorkItemHandler(executorService, "org.jbpm.executor.commands.PrintOutCommand"));
            return handlers;
        }

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
    assertNotNull(manager);
    final AtomicBoolean active = new AtomicBoolean(false);
    ((InternalRuntimeManager) manager).setSecurityManager(new org.kie.internal.runtime.manager.SecurityManager() {

        @Override
        public void checkPermission() throws SecurityException {
            if (active.get() && !AsyncExecutionMarker.isAsync()) {
                throw new SecurityException("Only async allowed");
            }
        }
    });
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    manager.disposeRuntimeEngine(runtime);
    // activate security manager to enforce checks for async only
    active.set(true);
    countDownListener.waitTillCompleted();
    // reset the security manager again...
    active.set(false);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    manager.disposeRuntimeEngine(runtime);
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 18 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class CountDownListenerFactory method get.

public static DefaultCountDownProcessEventListener get(String id, String nodeName, int threads) {
    if (listeners.containsKey(id)) {
        return listeners.get(id);
    }
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener(nodeName, threads);
    listeners.put(id, listener);
    return listener;
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)

Example 19 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class IntermediateEventTest method testIntermediateCatchEventTimerCycleCron.

@Test(timeout = 10000)
public void testIntermediateCatchEventTimerCycleCron() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    assertProcessInstanceActive(processInstance);
    ksession.abortProcessInstance(processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 20 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class IntermediateEventTest method testEventBasedSplit2.

@Test(timeout = 10000)
public void testEventBasedSplit2() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
    KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit2.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ksession.addEventListener(countDownListener);
    // Yes
    ProcessInstance processInstance = ksession.startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(countDownListener);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ksession.signalEvent("Yes", "YesValue", processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(countDownListener);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(countDownListener);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    // Timer
    processInstance = ksession.startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    countDownListener.waitTillCompleted();
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(countDownListener);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)132 Test (org.junit.Test)127 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)101 KieSession (org.kie.api.runtime.KieSession)66 KieBase (org.kie.api.KieBase)61 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)58 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)46 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)42 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)42 HashMap (java.util.HashMap)40 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)39 ArrayList (java.util.ArrayList)35 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)30 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)28 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)26 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)23 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)20 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)19 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)19 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)18