Search in sources :

Example 11 with CountDownAsyncJobListener

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

the class LogCleanupCommandTest method deleteAllLogsOlderThanTomorrowDifferentProcess.

@Test(timeout = 10000)
public void deleteAllLogsOlderThanTomorrowDifferentProcess() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    deleteAllLogsOlderThan(getTomorrow(), HELLO_WORLD_ID, ANOTHER_PROCESS, countDownListener);
    Assertions.assertThat(getProcessLogSize(HELLO_WORLD_ID)).isPositive();
    Assertions.assertThat(getNodeInstanceLogSize(HELLO_WORLD_ID)).isPositive();
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) Test(org.junit.Test)

Example 12 with CountDownAsyncJobListener

use of org.jbpm.test.listener.CountDownAsyncJobListener 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 13 with CountDownAsyncJobListener

use of org.jbpm.test.listener.CountDownAsyncJobListener 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)13 CountDownAsyncJobListener (org.jbpm.test.listener.CountDownAsyncJobListener)13 Test (org.junit.Test)13 KieSession (org.kie.api.runtime.KieSession)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 HashMap (java.util.HashMap)6 QueryContext (org.kie.api.runtime.query.QueryContext)5 AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)4 Ignore (org.junit.Ignore)4 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)4 BZ (qa.tools.ikeeper.annotation.BZ)4 UserTransaction (javax.transaction.UserTransaction)2 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)1 ErrorInfo (org.kie.api.executor.ErrorInfo)1 TaskService (org.kie.api.task.TaskService)1