Search in sources :

Example 31 with ExecutorServiceImpl

use of org.jbpm.executor.impl.ExecutorServiceImpl in project jbpm by kiegroup.

the class AsyncTaskTest method testTaskComplete.

@Test(timeout = 10000)
@BZ("1121027")
public void testTaskComplete() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Process async", 1);
    CountDownAsyncJobListener countDownJobListener = new CountDownAsyncJobListener(1);
    try {
        ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownJobListener);
        addProcessEventListener(countDownListener);
        KieSession ksession = createKSession(ASYNC_DATA_EXECUTOR);
        WorkItemManager wim = ksession.getWorkItemManager();
        wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
        Map<String, Object> pm = new HashMap<String, Object>();
        pm.put("command", USER_COMMAND);
        ProcessInstance pi = ksession.startProcess(ASYNC_DATA_EXECUTOR_ID, pm);
        assertNodeTriggered(pi.getId(), "StartProcess", "Set user info", "Process async");
        // Wait for the job to complete
        countDownListener.waitTillCompleted();
        ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
        assertNull(processInstance);
        assertNodeTriggered(pi.getId(), "Output", "EndProcess");
        countDownJobListener.waitTillCompleted();
        Assertions.assertThat(getExecutorService().getCompletedRequests(new QueryContext())).hasSize(1);
        assertProcessInstanceCompleted(pi.getId());
    } finally {
        ((ExecutorServiceImpl) getExecutorService()).removeAsyncJobListener(countDownJobListener);
    }
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 32 with ExecutorServiceImpl

use of org.jbpm.executor.impl.ExecutorServiceImpl in project jbpm by kiegroup.

the class AsyncTaskTest method testTaskFail.

@Test(timeout = 10000)
public void testTaskFail() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(4);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    KieSession ksession = createKSession(ASYNC_DATA_EXECUTOR);
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("command", USER_FAILING_COMMAND);
    ProcessInstance pi = ksession.startProcess(ASYNC_DATA_EXECUTOR_ID, pm);
    assertNodeTriggered(pi.getId(), "StartProcess", "Set user info", "Process async");
    assertNodeNotTriggered(pi.getId(), "Output");
    // Wait for the 4 retries to fail
    countDownListener.waitTillCompleted();
    ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
    assertNotNull(processInstance);
    assertNodeNotTriggered(pi.getId(), "Output");
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext())).hasSize(1);
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext()).get(0).getErrorInfo()).hasSize(4);
    Assertions.assertThat(getExecutorService().getInErrorRequests(new QueryContext()).get(0).getErrorInfo().get(0).getMessage()).isEqualTo("Internal Error");
    assertProcessInstanceActive(pi.getId());
    ksession.abortProcessInstance(pi.getId());
    assertProcessInstanceAborted(pi.getId());
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Aggregations

ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)32 Test (org.junit.Test)24 KieSession (org.kie.api.runtime.KieSession)18 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)16 HashMap (java.util.HashMap)13 CountDownAsyncJobListener (org.jbpm.test.listener.CountDownAsyncJobListener)13 QueryContext (org.kie.api.runtime.query.QueryContext)12 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)8 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)8 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)8 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)6 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)6 AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)5 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)5 RequestInfo (org.kie.api.executor.RequestInfo)5 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)4 CommandContext (org.kie.api.executor.CommandContext)4 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)4 TaskSummary (org.kie.api.task.model.TaskSummary)4