use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncModeWithTimer.
@Test(timeout = 10000)
public void testAsyncModeWithTimer() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryEnd", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("ProbAsync.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).addEnvironmentEntry("AsyncMode", "true").registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
Map<String, Object> params = new HashMap<>();
params.put("timer1", "2s");
params.put("timer2", "10s");
ProcessInstance processInstance = ksession.startProcess("ProbAsync", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
assertNull(processInstance);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncModeWithSignal.
@Test(timeout = 10000)
public void testAsyncModeWithSignal() throws Exception {
CountDownAsyncJobListener initialJob = new CountDownAsyncJobListener(1);
((ExecutorServiceImpl) executorService).addAsyncJobListener(initialJob);
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("SignalEnd", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("ProbAsync.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).addEnvironmentEntry("AsyncMode", "true").registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
Map<String, Object> params = new HashMap<>();
params.put("timer1", "20s");
params.put("timer2", "10s");
ProcessInstance processInstance = ksession.startProcess("ProbAsync", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
initialJob.waitTillCompleted();
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
runtime.getTaskService().start(taskId, "john");
runtime.getTaskService().complete(taskId, "john", null);
runtime.getKieSession().signalEvent("signal1", null, processInstanceId);
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
assertNull(processInstance);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testSubProcessWithSomeAsyncNodes.
@Test(timeout = 10000)
public void testSubProcessWithSomeAsyncNodes() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Goodbye", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-SubProcessSomeAsyncNodes.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new SystemOutWorkItemHandler());
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = ksession.startProcess("SubProcess", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
assertNotNull(logs);
assertEquals(18, logs.size());
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncMIUserTask.
@Test(timeout = 10000)
public void testAsyncMIUserTask() throws Exception {
final NodeTriggeredCountDownProcessEventListener countDownListener = new NodeTriggeredCountDownProcessEventListener("Hello", 3);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-MultiInstanceLoopCharacteristicsTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new SystemOutWorkItemHandler());
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ArrayList<String> items = new ArrayList<String>();
items.add("one");
items.add("two");
items.add("three");
Map<String, Object> params = new HashMap<String, Object>();
params.put("list", items);
ProcessInstance processInstance = ksession.startProcess("MultiInstanceLoopCharacteristicsTask", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(3, tasks.size());
for (TaskSummary task : tasks) {
runtime.getTaskService().start(task.getId(), "john");
runtime.getTaskService().complete(task.getId(), "john", null);
}
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
assertNotNull(logs);
assertEquals(12, logs.size());
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerCallbackErrorRetryUpdateJobData.
@Test(timeout = 20000)
public void testRunProcessWithAsyncHandlerCallbackErrorRetryUpdateJobData() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTaskWithRetryParam.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new AsyncWorkItemHandler(executorService, "org.jbpm.executor.test.MissingDataCommand"));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
Map<String, Object> params = new HashMap<String, Object>();
params.put("retryAsync", "1s, 2s, 3s");
ProcessInstance processInstance = ksession.startProcess("ScriptTask", params);
Long processInstanceId = processInstance.getId();
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
countDownListener.waitTillCompleted(2000);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
List<RequestInfo> requests = executorService.getRequestsByProcessInstance(processInstanceId, Arrays.asList(STATUS.RETRYING), new QueryContext());
assertEquals(1, requests.size());
Long requestId = requests.get(0).getId();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("amount", 200);
executorService.updateRequestData(requestId, variables);
countDownListener.waitTillCompleted();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
requests = executorService.getRequestsByProcessInstance(processInstanceId, Arrays.asList(STATUS.DONE), new QueryContext());
assertEquals(1, requests.size());
}
Aggregations