Search in sources :

Example 6 with CountDownAsyncJobListener

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

the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerRecordExecutionError.

@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerRecordExecutionError() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    ((ExecutorServiceImpl) executorService).setRetries(0);
    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.ThrowExceptionCommand"));
            return handlers;
        }
    }).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());
    assertNotNull(processInstance);
    List<RequestInfo> errorJobs = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, errorJobs.size());
    RequestInfo errorJob = errorJobs.get(0);
    assertEquals(errorJob.getProcessInstanceId().longValue(), processInstance.getId());
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    assertNotNull("ErrorManager is null", errorManager);
    ExecutionErrorStorage errorStorage = errorManager.getStorage();
    assertNotNull("ErrorStorage is null", errorStorage);
    List<ExecutionError> errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    ExecutionError error = errors.get(0);
    assertNotNull(error);
    assertEquals("Job", error.getType());
    assertEquals(errorJob.getId(), error.getJobId());
    assertEquals("ScriptTask", error.getProcessId());
    assertEquals("", error.getActivityName());
    assertEquals(manager.getIdentifier(), error.getDeploymentId());
    assertNotNull(error.getError());
    assertNotNull(error.getErrorMessage());
    assertNotNull(error.getActivityId());
    assertNotNull(error.getProcessInstanceId());
    assertNull(error.getAcknowledgedAt());
    assertNull(error.getAcknowledgedBy());
    assertFalse(error.isAcknowledged());
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 7 with CountDownAsyncJobListener

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

the class CleanupExecutionErrorCommandWithProcessTest method testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod.

@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    RuntimeEnvironment environment = configureEnvironment();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    ExecutionErrorStorage errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    long processInstanceId = processInstance.getId();
    countDownListener.waitTillCompleted();
    List<ExecutionError> errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    // advance time 1 second
    Thread.sleep(1000);
    // delete errors which happened 1s or more ago
    scheduleLogCleanup(null, "1s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    System.out.println("Aborting process instance " + processInstance.getId());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    // should not delete any errors as the process instance is still active
    errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    runtime.getKieSession().abortProcessInstance(processInstance.getId());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    // delete errors which happened 5s or more ago
    scheduleLogCleanup(null, "5s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    // should not delete any errors as we wanted to delete errors from 5s ago
    errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    // delete errors which happened 1s or more ago
    scheduleLogCleanup(null, "0s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    errors = errorStorage.list(0, 10);
    assertEquals(0, errors.size());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest)

Example 8 with CountDownAsyncJobListener

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

the class CleanupExecutionErrorCommandWithProcessTest method testRunProcessWithAsyncHandlerDeleteUsingOlderThan.

@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingOlderThan() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    RuntimeEnvironment environment = configureEnvironment();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    ExecutionErrorStorage errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    Date startDate = new Date();
    ProcessInstance processInstance = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    long processInstanceId = processInstance.getId();
    countDownListener.waitTillCompleted();
    List<ExecutionError> errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    scheduleLogCleanup(startDate, null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd", manager.getIdentifier());
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    System.out.println("Aborting process instance " + processInstance.getId());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    // should not delete any errors as the process instance is still active
    errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    runtime.getKieSession().abortProcessInstance(processInstance.getId());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    Thread.sleep(1000);
    scheduleLogCleanup(new Date(), null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    errors = errorStorage.list(0, 10);
    assertEquals(0, errors.size());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Date(java.util.Date) Test(org.junit.Test) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest)

Example 9 with CountDownAsyncJobListener

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

the class CleanupExecutionErrorCommandWithProcessTest method configureListener.

protected CountDownAsyncJobListener configureListener(int threads) {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(threads);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    return countDownListener;
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl)

Example 10 with CountDownAsyncJobListener

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

the class CleanupLogCommandWithProcessTest method testRunProcessWithAsyncHandlerDontDeleteActive.

@Test
public void testRunProcessWithAsyncHandlerDontDeleteActive() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).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 DoNothingWorkItemHandler());
            return handlers;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    assertEquals(0, getProcessLogSize("ScriptTask"));
    assertEquals(0, getNodeInstanceLogSize("ScriptTask"));
    assertEquals(0, getTaskLogSize("ScriptTask"));
    assertEquals(0, getVariableLogSize("ScriptTask"));
    Date startDate = new Date();
    ProcessInstance processInstance = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(1, getProcessLogSize("ScriptTask"));
    assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
    assertEquals(0, getTaskLogSize("ScriptTask"));
    assertEquals(0, getVariableLogSize("ScriptTask"));
    scheduleLogCleanup(false, true, false, startDate, "ScriptTask", "yyyy-MM-dd", manager.getIdentifier());
    countDownListener.waitTillCompleted();
    System.out.println("Aborting process instance " + processInstance.getId());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    assertEquals(1, getProcessLogSize("ScriptTask"));
    assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
    assertEquals(0, getTaskLogSize("ScriptTask"));
    assertEquals(0, getVariableLogSize("ScriptTask"));
    runtime.getKieSession().abortProcessInstance(processInstance.getId());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    assertEquals(1, getProcessLogSize("ScriptTask"));
    assertEquals(6, getNodeInstanceLogSize("ScriptTask"));
    assertEquals(0, getTaskLogSize("ScriptTask"));
    assertEquals(0, getVariableLogSize("ScriptTask"));
    // and start another one to keep it active while cleanup happens
    processInstance = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(2, getProcessLogSize("ScriptTask"));
    assertEquals(11, getNodeInstanceLogSize("ScriptTask"));
    assertEquals(0, getTaskLogSize("ScriptTask"));
    assertEquals(0, getVariableLogSize("ScriptTask"));
    Thread.sleep(1000);
    scheduleLogCleanup(false, false, false, new Date(), "ScriptTask", "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    assertEquals(1, getProcessLogSize("ScriptTask"));
    assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
    assertEquals(0, getTaskLogSize("ScriptTask"));
    assertEquals(0, getVariableLogSize("ScriptTask"));
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Date(java.util.Date) Test(org.junit.Test) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest)

Aggregations

CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)50 Test (org.junit.Test)43 QueryContext (org.kie.api.runtime.query.QueryContext)27 CommandContext (org.kie.api.executor.CommandContext)25 RequestInfo (org.kie.api.executor.RequestInfo)25 KieSession (org.kie.api.runtime.KieSession)20 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)20 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)19 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)19 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)19 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)17 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 HashMap (java.util.HashMap)8 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)7 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)7 TaskSummary (org.kie.api.task.model.TaskSummary)7 ExecutionError (org.kie.internal.runtime.error.ExecutionError)7 ExecutionErrorStorage (org.kie.internal.runtime.error.ExecutionErrorStorage)7 ErrorInfo (org.kie.api.executor.ErrorInfo)6 Date (java.util.Date)5