use of org.jbpm.executor.entities.RequestInfo in project jBPM5-Developer-Guide by Salaboy.
the class BasicExecutorBaseTest method callbackTest.
/**
* Tests callback execution after a command was successfully executed.
* @throws InterruptedException
*/
@Test
public void callbackTest() throws InterruptedException {
CommandContext commandContext = new CommandContext();
//We register a business key in the command context so we can add
//extra information on it.
commandContext.setData("businessKey", UUID.randomUUID().toString());
//We are going to put a new AtomicLong in the context. The idea is
//that the callback we will register will get this 'entity' and increments
//its value.
cachedEntities.put((String) commandContext.getData("businessKey"), new AtomicLong(1));
//A job is scheduled. Using commandContext we can register a callback
//using its CDI name.
commandContext.setData("callbacks", "SimpleIncrementCallback");
executor.scheduleRequest("PrintOutCmd", commandContext);
Thread.sleep(10000);
//after 10 seconds we should have no errors, no queued requests and
//one executed request.
List<RequestInfo> inErrorRequests = executor.getInErrorRequests();
assertEquals(0, inErrorRequests.size());
List<RequestInfo> queuedRequests = executor.getQueuedRequests();
assertEquals(0, queuedRequests.size());
List<RequestInfo> executedRequests = executor.getExecutedRequests();
assertEquals(1, executedRequests.size());
//Since the callback was invoked, the value of the entity should have
//been incremented.
assertEquals(2, ((AtomicLong) cachedEntities.get((String) commandContext.getData("businessKey"))).longValue());
}
use of org.jbpm.executor.entities.RequestInfo in project jBPM5-Developer-Guide by Salaboy.
the class BasicExecutorBaseTest method defaultRequestRetryTest.
/**
* Test showing the retry mechanism for failing commands.
* @throws InterruptedException
*/
@Test
public void defaultRequestRetryTest() throws InterruptedException {
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
//The command we are registering will cause an exception.
//Remeber that the default number of reties is 3.
executor.scheduleRequest("ThrowExceptionCmd", ctxCMD);
Thread.sleep(12000);
//After 12 seconds we should have 4 errors: 1 corresponding to the
//first time the command failed. The other 3 correspond to the 3
//retries.
List<RequestInfo> inErrorRequests = executor.getInErrorRequests();
assertEquals(1, inErrorRequests.size());
List<ErrorInfo> errors = executor.getAllErrors();
System.out.println(" >>> Errors: " + errors);
// Three retries means 4 executions in total 1(regular) + 3(retries)
assertEquals(4, errors.size());
}
use of org.jbpm.executor.entities.RequestInfo in project jBPM5-Developer-Guide by Salaboy.
the class SlowWebServicesInteractionsTest method testSlowWebServicesWait.
/**
* Invokes 3 web services that take some time to be executed. The process
* will wait for each web service to finish before continuing to the next
* task. The process -> web service interaction is performed using the
* Execution Service component. The Command being used is {@link CXFWebServiceCommand}
* and the web service implementation is {@link SlowServiceImpl}.
* @throws InterruptedException
*/
@Test
public void testSlowWebServicesWait() throws InterruptedException {
initializeSession("three-systems-interactions-wait.bpmn");
SessionStoreUtil.sessionCache.put("sessionId=" + session.getId(), session);
HashMap<String, Object> input = new HashMap<String, Object>();
String patientName = "John Doe";
input.put("bedrequest_patientname", patientName);
AsyncGenericWorkItemHandler webServiceHandler = new AsyncGenericWorkItemHandler(executor, session.getId());
session.getWorkItemManager().registerWorkItemHandler("Slow Web Service", webServiceHandler);
WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("ThreeSystemsInteractions", input);
//No web service was invoked yet, so the process remains ACTIVE
List<RequestInfo> resultList = executor.getExecutedRequests();
assertEquals(0, resultList.size());
assertEquals(ProcessInstance.STATE_ACTIVE, pI.getState());
Thread.sleep(35000);
//After 35 seconds we could see that the web services were invoked
//correctly.
resultList = executor.getExecutedRequests();
assertEquals(3, resultList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
session.dispose();
}
use of org.jbpm.executor.entities.RequestInfo in project jBPM5-Developer-Guide by Salaboy.
the class SlowWebServicesInteractionsTest method testSlowWebServicesNoWait.
/**
* Invokes 3 web services that take some time to be executed. The process
* will continue with its execution without waiting for each web service to
* finish. The process -> web service interaction is performed using the
* Execution Service component. The Command being used is {@link CXFWebServiceCommand}
* and the web service implementation is {@link SlowServiceImpl}.
* @throws InterruptedException
*/
@Test
public void testSlowWebServicesNoWait() throws InterruptedException {
initializeSession("three-systems-interactions-nowait.bpmn");
HashMap<String, Object> input = new HashMap<String, Object>();
String patientName = "John Doe";
input.put("bedrequest_patientname", patientName);
AsyncGenericWorkItemHandler webServiceHandler = new AsyncGenericWorkItemHandler(executor, session.getId());
session.getWorkItemManager().registerWorkItemHandler("Slow Web Service", webServiceHandler);
WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("ThreeSystemsInteractions", input);
//Even if the requests are not executed yet, the process is completed.
List<RequestInfo> resultList = executor.getExecutedRequests();
assertEquals(0, resultList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
Thread.sleep(35000);
//After 35 seconds we could see that the web services were invoked
//correctly.
resultList = executor.getExecutedRequests();
assertEquals(3, resultList.size());
session.dispose();
}
use of org.jbpm.executor.entities.RequestInfo in project jBPM5-Developer-Guide by Salaboy.
the class ExecutorImpl method cancelRequest.
public void cancelRequest(Long requestId) {
logger.log(Level.INFO, " >>> Before - Cancelling Request with Id: {0}", requestId);
String eql = "Select r from RequestInfo as r where (r.status ='QUEUED' or r.status ='RETRYING') and id = :id";
List<?> result = em.createQuery(eql).setParameter("id", requestId).getResultList();
if (result.isEmpty()) {
return;
}
RequestInfo r = (RequestInfo) result.iterator().next();
em.lock(r, LockModeType.PESSIMISTIC_READ);
r.setStatus(STATUS.CANCELLED);
em.merge(r);
logger.log(Level.INFO, " >>> After - Cancelling Request with Id: {0}", requestId);
}
Aggregations