Search in sources :

Example 1 with AsyncWorkItemHandler

use of org.jbpm.executor.impl.wih.AsyncWorkItemHandler in project jbpm by kiegroup.

the class AsyncHandlerProducer method getWorkItemHandlers.

@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(String identifier, Map<String, Object> params) {
    Map<String, WorkItemHandler> handlers = new HashMap<String, WorkItemHandler>();
    ExecutorService executorService = (ExecutorService) params.get("executorService");
    if (executorService != null) {
        handlers.put("async", new AsyncWorkItemHandler(executorService, PrintOutCommand.class.getName()));
    }
    return handlers;
}
Also used : AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) HashMap(java.util.HashMap) ExecutorService(org.kie.api.executor.ExecutorService) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler)

Example 2 with AsyncWorkItemHandler

use of org.jbpm.executor.impl.wih.AsyncWorkItemHandler in project jbpm by kiegroup.

the class ExecutorLogCleanTest method deleteInfoLogsByStatus.

@Test
public void deleteInfoLogsByStatus() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    KieSession kieSession = createKSession(ASYNC_DATA_EXEC);
    WorkItemManager wim = kieSession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("command", "org.jbpm.test.jobexec.UserCommand");
    ProcessInstance pi = kieSession.startProcess(ASYNC_DATA_EXEC_ID, pm);
    // Wait for the job to complete
    countDownListener.waitTillCompleted();
    // Assert completion of the job
    Assertions.assertThat(getExecutorService().getCompletedRequests(new QueryContext())).hasSize(1);
    // Delete a record
    int resultCount = auditService.requestInfoLogDeleteBuilder().status(STATUS.DONE).build().execute();
    Assertions.assertThat(resultCount).isEqualTo(1);
    // Assert remaining records
    Assertions.assertThat(getExecutorService().getCompletedRequests(new QueryContext())).hasSize(0);
}
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)

Example 3 with AsyncWorkItemHandler

use of org.jbpm.executor.impl.wih.AsyncWorkItemHandler in project jbpm by kiegroup.

the class ExecutorLogCleanTest method deleteErrorLogsByDate.

@Test
@BZ("1188702")
public void deleteErrorLogsByDate() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(2);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    KieSession ksession = createKSession(ASYNC_DATA_EXEC);
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("command", "org.jbpm.test.jobexec.UserFailingCommand");
    ProcessInstance pi = ksession.startProcess(ASYNC_DATA_EXEC_ID, pm);
    // Wait for the all retries to fail
    countDownListener.waitTillCompleted();
    // Assert completion of the job
    List<ErrorInfo> errorList = getExecutorService().getAllErrors(new QueryContext());
    Assertions.assertThat(errorList).hasSize(2);
    // Delete a record
    int resultCount = auditService.errorInfoLogDeleteBuilder().date(errorList.get(0).getTime()).build().execute();
    Assertions.assertThat(resultCount).isEqualTo(1);
    // Assert remaining records
    Assertions.assertThat(getExecutorService().getAllErrors(new QueryContext())).hasSize(1);
    // Abort running process instance
    ksession.abortProcessInstance(pi.getId());
}
Also used : ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) HashMap(java.util.HashMap) ErrorInfo(org.kie.api.executor.ErrorInfo) QueryContext(org.kie.api.runtime.query.QueryContext) CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 4 with AsyncWorkItemHandler

use of org.jbpm.executor.impl.wih.AsyncWorkItemHandler in project jbpm by kiegroup.

the class AsyncTaskCallbackTest method testTaskCallback.

@Test(timeout = 30000)
public void testTaskCallback() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Continue", 1);
    addProcessEventListener(countDownListener);
    KieSession ksession = createKSession(ASYNC_EXECUTOR_CALLBACK, ASYNC_DATA_EXECUTOR);
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("_command", CALLBACK_COMMAND);
    ProcessInstance pi = ksession.startProcess(ASYNC_EXECUTOR_CALLBACK_ID, pm);
    // Wait for the job to be picked up and processed. The job will send
    // the 'Continue' signal on OK or Fail. We expect OK.
    countDownListener.waitTillCompleted();
    ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
    assertNull(processInstance);
    // Make sure the user registered callback was executed (a.k.a the "continue" signal was received by the process)
    assertNodeTriggered(pi.getId(), "Process async", "Continue");
    assertProcessInstanceCompleted(pi.getId());
    // Make sure the job was processed by the job executor (a.k.a the _user property was set)
    List<VariableInstanceLog> varLogList = auditLogService.findVariableInstances(pi.getId(), "_user");
    assertEquals(1, varLogList.size());
    VariableInstanceLog userVarLog = varLogList.get(0);
    assertEquals("[Name=john after command execution, age=25]", userVarLog.getValue());
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 5 with AsyncWorkItemHandler

use of org.jbpm.executor.impl.wih.AsyncWorkItemHandler in project jbpm by kiegroup.

the class AsyncTaskTransactionTest method registerAsyncHandler.

private KieSession registerAsyncHandler(KieSession ksession) {
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    return ksession;
}
Also used : AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) WorkItemManager(org.kie.api.runtime.process.WorkItemManager)

Aggregations

AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)10 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 KieSession (org.kie.api.runtime.KieSession)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)7 QueryContext (org.kie.api.runtime.query.QueryContext)6 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)5 CountDownAsyncJobListener (org.jbpm.test.listener.CountDownAsyncJobListener)4 BZ (qa.tools.ikeeper.annotation.BZ)4 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)3 ExecutorService (org.kie.api.executor.ExecutorService)2 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AsynchronousJobEvent (org.jbpm.executor.AsynchronousJobEvent)1 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)1 VariableInstanceLog (org.jbpm.process.audit.VariableInstanceLog)1 TrackingProcessEventListener (org.jbpm.test.listener.TrackingProcessEventListener)1 ErrorInfo (org.kie.api.executor.ErrorInfo)1