use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method addAnotherCallbackTest.
@Test
public void addAnotherCallbackTest() throws InterruptedException {
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.ejb.impl.test.SimpleIncrementCallback");
executorService.scheduleRequest("org.jbpm.executor.ejb.impl.test.AddAnotherCallbackCommand", commandContext);
Thread.sleep(10000);
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(2, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
ExecutionResults results = null;
byte[] responseData = executedRequests.get(0).getResponseData();
ObjectInputStream in = null;
try {
in = new ObjectInputStream(new ByteArrayInputStream(responseData));
results = (ExecutionResults) in.readObject();
} catch (Exception e) {
logger.warn("Exception while serializing context data", e);
return;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
String result = (String) results.getData("custom");
assertNotNull(result);
assertEquals("custom callback invoked", result);
}
use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method executorExceptionTrimmingTest.
@Test
public void executorExceptionTrimmingTest() throws InterruptedException {
System.setProperty("org.kie.executor.msg.length", "10");
System.setProperty("org.kie.executor.stacktrace.length", "20");
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.ejb.impl.test.SimpleIncrementCallback");
commandContext.setData("retries", 0);
executorService.scheduleRequest("org.jbpm.executor.ejb.impl.test.ThrowExceptionCommand", commandContext);
logger.info("{} Sleeping for 10 secs", System.currentTimeMillis());
Thread.sleep(10000);
List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
assertEquals(1, inErrorRequests.size());
logger.info("Error: {}", inErrorRequests.get(0));
List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
logger.info("Errors: {}", errors);
assertEquals(1, errors.size());
ErrorInfo error = errors.get(0);
assertEquals(10, error.getMessage().length());
assertEquals(20, error.getStacktrace().length());
}
use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method cancelRequestWithSearchByCommandTest.
@Test
public void cancelRequestWithSearchByCommandTest() throws InterruptedException {
CommandContext ctxCMD = new CommandContext();
String businessKey = UUID.randomUUID().toString();
ctxCMD.setData("businessKey", businessKey);
Date futureDate = new Date(System.currentTimeMillis() + 5000);
Long requestId = executorService.scheduleRequest("org.jbpm.executor.test.CustomCommand", futureDate, ctxCMD);
List<RequestInfo> requests = executorService.getRequestsByCommand("org.jbpm.executor.test.CustomCommand", 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());
}
use of org.kie.api.executor.RequestInfo in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method callbackTest.
@Test
public void callbackTest() throws InterruptedException {
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.ejb.impl.test.SimpleIncrementCallback");
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", commandContext);
Thread.sleep(10000);
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(2, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
}
Aggregations