use of org.kie.api.executor.CommandContext in project jbpm by kiegroup.
the class AsyncIntermediateCatchSignalTest method testCorrectProcessStateAfterExceptionSignalCommand.
@Test(timeout = 10000)
public void testCorrectProcessStateAfterExceptionSignalCommand() throws InterruptedException {
latch = new CountDownLatch(1);
RuntimeManager runtimeManager = createRuntimeManager(BPMN_AICS);
KieSession ksession = getRuntimeEngine().getKieSession();
ProcessInstance pi = ksession.startProcess(PROCESS_AICS, null);
long pid = pi.getId();
CommandContext ctx = new CommandContext();
ctx.setData("DeploymentId", runtimeManager.getIdentifier());
ctx.setData("ProcessInstanceId", pid);
ctx.setData("Signal", "MySignal");
ctx.setData("Event", null);
executorService.scheduleRequest(AsyncSignalEventCommand.class.getName(), ctx);
latch.await();
}
use of org.kie.api.executor.CommandContext in project jbpm by kiegroup.
the class AsyncEventNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
ExecutorService executorService = (ExecutorService) getProcessInstance().getKnowledgeRuntime().getEnvironment().get("ExecutorService");
if (executorService != null) {
RuntimeManager runtimeManager = ((RuntimeManager) getProcessInstance().getKnowledgeRuntime().getEnvironment().get("RuntimeManager"));
CommandContext ctx = new CommandContext();
ctx.setData("deploymentId", runtimeManager.getIdentifier());
ctx.setData("processInstanceId", getProcessInstance().getId());
ctx.setData("Signal", getEventType());
ctx.setData("Event", null);
executorService.scheduleRequest(AsyncSignalEventCommand.class.getName(), ctx);
Node node = getNode();
if (node != null) {
String uniqueId = (String) node.getMetaData().get("UniqueId");
if (uniqueId == null) {
uniqueId = ((NodeImpl) node).getUniqueId();
}
((WorkflowProcessInstanceImpl) getProcessInstance()).getIterationLevels().remove(getNode().getMetaData().get("UniqueId"));
}
} else {
logger.warn("No async executor service found continuing as sync operation...");
// if there is no executor service available move as sync node
triggerCompleted();
}
}
use of org.kie.api.executor.CommandContext in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method cancelRequestTest.
@Test
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() + 5000);
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());
}
use of org.kie.api.executor.CommandContext in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method multipleCallbackTest.
@Test
public void multipleCallbackTest() 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, org.jbpm.executor.ejb.impl.test.CustomCallback");
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());
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.CommandContext in project jbpm by kiegroup.
the class BasicExecutorIntegrationTest method simpleExcecutionTest.
@Test
public void simpleExcecutionTest() throws InterruptedException {
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD);
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());
}
Aggregations