use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerCallbackErrorRetry.
@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerCallbackErrorRetry() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTaskWithError.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.commands.PrintOutCommand"));
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);
assertEquals(0, IncrementService.get());
Map<String, Object> params = new HashMap<String, Object>();
params.put("retryAsync", "1s, 2s, 4s");
ProcessInstance processInstance = ksession.startProcess("ScriptTask", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
countDownListener.waitTillCompleted(2000);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("x", "should be fixed now");
ksession.execute(new SetProcessInstanceVariablesCommand(processInstance.getId(), variables));
countDownListener.waitTillCompleted();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
assertEquals(1, IncrementService.get());
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerWithAbort.
@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerWithAbort() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTaskWithParams.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.commands.PrintOutCommand"));
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> parameters = new HashMap<>();
parameters.put("delayAsync", "5s");
ProcessInstance processInstance = ksession.startProcess("ScriptTask", parameters);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
runtime.getKieSession().abortProcessInstance(processInstance.getId());
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandler.
@Test(timeout = 10000)
public void testRunProcessWithAsyncHandler() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.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.commands.PrintOutCommand"));
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);
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
Thread.sleep(3000);
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testContinueTimer.
@Test(timeout = 20000)
public void testContinueTimer() throws Exception {
// JBPM-4443
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExporations.add(event.getProcessInstance().getId());
}
}
};
// No special configuration for TimerService in order to test RuntimeManager default
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle4.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
manager.close();
countDownListener.reset(1);
// ---- restart ----
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle4.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener)).get();
manager = getManager(environment, true);
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted(3000);
assertEquals(2, timerExporations.size());
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testContinueGlobalTestService.
/**
* Test that illustrates that jobs are persisted and survives server restart
* and as soon as GlobalTimerService is active jobs are fired
* NOTE: this test is disabled by default as it requires real db (not in memory)
* and test to be executed separately each with new jvm process
*/
@Test
@Ignore
public void testContinueGlobalTestService() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle2.bpmn2"), ResourceType.BPMN2).addConfiguration("drools.timerService", "org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate").get();
RuntimeManager manger = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
// build GlobalTimerService instance
TimerService globalTs = new GlobalTimerService(manger, globalScheduler);
// and register it in the registry under 'default' key
TimerServiceRegistry.getInstance().registerTimerService("default", globalTs);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExporations.add(event.getProcessInstance().getId());
}
}
};
Thread.sleep(5000);
}
Aggregations