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());
}
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());
}
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());
}
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;
}
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"));
}
Aggregations