use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class CleanupLogCommandWithProcessTest 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 SLATrackingCommandTest method testSLATrackingOnUserTaskSLAMet.
@Test
public void testSLATrackingOnUserTaskSLAMet() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithSLAOnTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("SLATimerMode", "false").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("UserTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
JPAAuditLogService logService = new JPAAuditLogService(emf);
assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_PENDING);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_PENDING);
runtime.getTaskService().start(tasks.get(0).getId(), "john");
runtime.getTaskService().complete(tasks.get(0).getId(), "john", null);
assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_MET);
}
use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class SLATrackingCommandTest method testSLATrackingOnProcessInstance.
@Test
public void testSLATrackingOnProcessInstance() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithSLA.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("SLATimerMode", "false").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("UserTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
JPAAuditLogService logService = new JPAAuditLogService(emf);
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
// wait for due date of SLA to pass
Thread.sleep(3000);
countDownListener.reset(1);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_VIOLATED);
}
use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class BasicExecutorBaseTest method defaultRequestRetryTest.
@Test(timeout = 10000)
public void defaultRequestRetryTest() throws InterruptedException {
CountDownAsyncJobListener countDownListener = configureListener(4);
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", ctxCMD);
countDownListener.waitTillCompleted();
List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(1, inErrorRequests.size());
RequestInfo failedJob = inErrorRequests.get(0);
assertEquals(4, failedJob.getExecutions());
List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
logger.info("Errors: {}", errors);
// Three retries means 4 executions in total 1(regular) + 3(retries)
assertEquals(4, errors.size());
}
use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class BasicExecutorBaseTest method cleanupLogExecutionTest.
@Test(timeout = 10000)
public void cleanupLogExecutionTest() throws InterruptedException {
CountDownAsyncJobListener countDownListener = configureListener(3);
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.ReoccurringPrintOutCommand", ctxCMD);
countDownListener.waitTillCompleted();
List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(0, inErrorRequests.size());
List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
assertEquals(1, queuedRequests.size());
List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
assertEquals(3, executedRequests.size());
executorService.cancelRequest(requestId + 3);
List<RequestInfo> canceled = executorService.getCancelledRequests(new QueryContext());
ExecutorJPAAuditService auditService = new ExecutorJPAAuditService(emf);
int resultCount = auditService.requestInfoLogDeleteBuilder().date(canceled.get(0).getTime()).status(STATUS.ERROR).build().execute();
assertEquals(0, resultCount);
resultCount = auditService.errorInfoLogDeleteBuilder().date(canceled.get(0).getTime()).build().execute();
assertEquals(0, resultCount);
ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
ctxCMD.setData("SingleRun", "true");
ctxCMD.setData("EmfName", "org.jbpm.executor");
ctxCMD.setData("SkipProcessLog", "true");
ctxCMD.setData("SkipTaskLog", "true");
executorService.scheduleRequest("org.jbpm.executor.commands.LogCleanupCommand", ctxCMD);
countDownListener.reset(1);
countDownListener.waitTillCompleted();
inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(0, inErrorRequests.size());
queuedRequests = executorService.getQueuedRequests(new QueryContext());
assertEquals(0, queuedRequests.size());
executedRequests = executorService.getCompletedRequests(new QueryContext());
assertEquals(1, executedRequests.size());
}
Aggregations