use of org.kie.api.executor.CommandContext 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.kie.api.executor.CommandContext 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();
}
use of org.kie.api.executor.CommandContext in project jbpm by kiegroup.
the class BasicExecutorBaseTest method multipleCallbackTest.
@Test(timeout = 10000)
public void multipleCallbackTest() throws InterruptedException {
CountDownAsyncJobListener countDownListener = configureListener(1);
CommandContext commandContext = new CommandContext();
commandContext.setData("businessKey", UUID.randomUUID().toString());
cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
commandContext.setData("callbacks", "org.jbpm.executor.SimpleIncrementCallback, org.jbpm.executor.test.CustomCallback");
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", commandContext);
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(3, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
}
use of org.kie.api.executor.CommandContext in project jbpm by kiegroup.
the class BasicExecutorBaseTest method testPrioritizedJobsExecutionInvalidProrities.
@Test(timeout = 10000)
public void testPrioritizedJobsExecutionInvalidProrities() throws InterruptedException {
CountDownAsyncJobListener countDownListener = configureListener(2);
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", "low priority");
ctxCMD.setData("priority", -1);
Date futureDate = new Date(System.currentTimeMillis() + EXTRA_TIME);
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", futureDate, ctxCMD);
CommandContext ctxCMD2 = new CommandContext();
ctxCMD2.setData("businessKey", "high priority");
ctxCMD2.setData("priority", 10);
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", futureDate, ctxCMD2);
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(2, executedRequests.size());
RequestInfo executedHigh = executedRequests.get(1);
assertNotNull(executedHigh);
assertEquals("high priority", executedHigh.getKey());
RequestInfo executedLow = executedRequests.get(0);
assertNotNull(executedLow);
assertEquals("low priority", executedLow.getKey());
assertTrue(executedLow.getTime().getTime() > executedHigh.getTime().getTime());
}
use of org.kie.api.executor.CommandContext in project jbpm by kiegroup.
the class BasicExecutorBaseTest method cancelRequestTest.
@Test(timeout = 10000)
public void cancelRequestTest() throws InterruptedException {
// The executor is on purpose not started to not fight against race condition
// with the request cancelations.
CommandContext ctxCMD = new CommandContext();
String businessKey = UUID.randomUUID().toString();
ctxCMD.setData("businessKey", businessKey);
Date futureDate = new Date(System.currentTimeMillis() + EXTRA_TIME);
Long requestId = executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", futureDate, ctxCMD);
List<RequestInfo> requests = executorService.getRequestsByBusinessKey(businessKey, new QueryContext());
assertNotNull(requests);
assertEquals(1, requests.size());
assertEquals(requestId, requests.get(0).getId());
// cancel the task immediately
executorService.cancelRequest(requestId);
List<RequestInfo> cancelledRequests = executorService.getCancelledRequests(new QueryContext());
assertEquals(1, cancelledRequests.size());
}
Aggregations