Search in sources :

Example 6 with CountDownAsyncJobListener

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

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

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

the class AsyncTaskTransactionTest method testJobCommitInAsyncExec.

@Test(timeout = 10000)
public void testJobCommitInAsyncExec() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    KieSession ksession = registerAsyncHandler(createKSession(ASYNC_EXECUTOR_2, ASYNC_DATA_EXECUTOR));
    ProcessInstance pi;
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        Map<String, Object> pm = new HashMap<String, Object>();
        pm.put("_command", USER_COMMAND);
        pi = ksession.startProcess(ASYNC_EXECUTOR_2_ID, pm);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    assertProcessInstanceCompleted(pi.getId());
    countDownListener.waitTillCompleted();
    Assertions.assertThat(getExecutorService().getCompletedRequests(new QueryContext())).hasSize(1);
}
Also used : UserTransaction(javax.transaction.UserTransaction) CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Example 9 with CountDownAsyncJobListener

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

the class AsyncTaskTransactionTest method testJobCommit.

@Test(timeout = 10000)
public void testJobCommit() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
    KieSession ksession = registerAsyncHandler(createKSession(ASYNC_DATA_EXECUTOR));
    ProcessInstance pi;
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        Map<String, Object> pm = new HashMap<String, Object>();
        pm.put("command", USER_COMMAND);
        pm.put("delayAsync", "2s");
        pi = ksession.startProcess(ASYNC_DATA_EXECUTOR_ID, pm);
        // the JobExecutor will act on the job only after commit
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    countDownListener.waitTillCompleted();
    ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
    assertNull(processInstance);
    assertProcessInstanceCompleted(pi.getId());
}
Also used : UserTransaction(javax.transaction.UserTransaction) CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 10 with CountDownAsyncJobListener

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

the class LogCleanupCommandTest method skipTaskLog.

@Ignore
@Test(timeout = 10000)
public void skipTaskLog() throws Exception {
    KieSession kieSession = null;
    List<ProcessInstance> processInstanceList = null;
    try {
        CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
        ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
        // Generate data
        kieSession = createKSession(LOG_CLEANUP);
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("assigneeName", "krisv");
        processInstanceList = startProcess(kieSession, LOG_CLEANUP_ID, paramMap, 1);
        TaskService taskService = getRuntimeEngine().getTaskService();
        List<Long> taskIdList = taskService.getTasksByProcessInstanceId(processInstanceList.get(0).getId());
        taskService.start(taskIdList.get(0), "krisv");
        taskService.complete(taskIdList.get(0), "krisv", null);
        // Verify presence of data
        Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isPositive();
        Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isEqualTo(3);
        // Schedule cleanup job
        scheduleLogCleanup(false, true, false, getTomorrow(), null, LOG_CLEANUP_ID);
        countDownListener.waitTillCompleted();
        // Verify absence of data
        Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isZero();
        Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isZero();
        Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isZero();
    } finally {
        if (processInstanceList != null) {
            abortProcess(kieSession, processInstanceList);
        }
    }
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) TaskService(org.kie.api.task.TaskService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Ignore(org.junit.Ignore) 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