use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class SLATrackingCommandTest 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 testSLATrackingOnUserTask.
@Test
public void testSLATrackingOnUserTask() 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);
// wait for due date of SLA to pass
Thread.sleep(3000);
countDownListener.reset(1);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
runtime.getTaskService().start(tasks.get(0).getId(), "john");
runtime.getTaskService().complete(tasks.get(0).getId(), "john", null);
assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_VIOLATED);
}
use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class SLATrackingCommandTest method testSLATrackingOnProcessInstanceSLAMet.
@Test
public void testSLATrackingOnProcessInstanceSLAMet() 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());
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
JPAAuditLogService logService = new JPAAuditLogService(emf);
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
runtime.getTaskService().start(tasks.get(0).getId(), "john");
runtime.getTaskService().complete(tasks.get(0).getId(), "john", null);
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_MET);
}
use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class BasicExecutorBaseTest method simpleExecutionTest.
@Test(timeout = 10000)
public void simpleExecutionTest() throws InterruptedException {
CountDownAsyncJobListener countDownListener = configureListener(1);
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD);
countDownListener.waitTillCompleted();
List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(0, inErrorRequests.size());
List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
assertEquals(0, queuedRequests.size());
List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
assertEquals(1, executedRequests.size());
assertEquals(1, executedRequests.get(0).getExecutions());
}
use of org.jbpm.executor.test.CountDownAsyncJobListener in project jbpm by kiegroup.
the class BasicExecutorBaseTest method testCustomIncrementingRequestRetrySpecialValues.
@Test(timeout = 10000)
public void testCustomIncrementingRequestRetrySpecialValues() throws InterruptedException {
CountDownAsyncJobListener countDownListener = configureListener(2);
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
ctxCMD.setData("retryDelay", "-1ms, 1m 80s");
ctxCMD.setData("retries", 2);
executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", ctxCMD);
countDownListener.waitTillCompleted();
List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
// 2 executions in total 1(regular) + 1(retry)
assertEquals(2, errors.size());
long firstError = errors.get(0).getTime().getTime();
long secondError = errors.get(1).getTime().getTime();
// Time difference between first and second shouldn't be bigger than 4 seconds as executor has 3 second interval and
// should start executing second command immediately.
long diff = secondError - firstError;
assertTrue(diff < 4000);
List<RequestInfo> allRequests = executorService.getAllRequests(new QueryContext());
assertEquals(1, allRequests.size());
// Future execution is planned to be started 2 minutes and 20 seconds after last fail.
// Time difference vary because of test thread sleeping for 10 seconds.
diff = allRequests.get(0).getTime().getTime() - Calendar.getInstance().getTimeInMillis();
assertTrue(diff < 140000);
assertTrue(diff > 130000);
executorService.clearAllRequests();
}
Aggregations