use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testTimersOnMultiInstanceSubprocess.
@Test(timeout = 20000)
public void testTimersOnMultiInstanceSubprocess() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("MIDelayTimer", 2);
final List<Long> timerExpirations = new ArrayList<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("MIDebugScript")) {
timerExpirations.add(event.getProcessInstance().getId());
}
}
});
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-MultiInstanceProcess.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance pi1 = ksession.startProcess("defaultPackage.MultiInstanceProcess");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
// wait a bit for some timers to fire
countDownListener.waitTillCompleted();
// now make sure nothing else is triggered
countDownListener.reset(4);
countDownListener.waitTillCompleted(3000);
assertEquals(2, timerExpirations.size());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
pi1 = ksession.getProcessInstance(pi1.getId());
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
ksession.abortProcessInstance(pi1.getId());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testDataBaseFailureInMemoryStorage.
@Test
public void testDataBaseFailureInMemoryStorage() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ksession1.addEventListener(new DefaultProcessEventListener() {
@Override
public void afterProcessStarted(ProcessStartedEvent event) {
pds.close();
}
});
try {
ksession1.startProcess("UserTaskWithRollback");
fail("Start process should fail due to data base error");
} catch (Throwable e) {
// expected
}
int expectedErrors = 1;
try {
manager.disposeRuntimeEngine(runtime1);
} catch (Exception e) {
// expected to fail for some strategies due to data source being down
expectedErrors++;
}
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(expectedErrors, errors.size());
assertExecutionError(errors.get(0), "DB", "UserTaskWithRollback", "Hello");
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class AsyncEndSignalTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
executorService = ExecutorServiceFactory.newExecutorService(getEmf());
executorService.setInterval(1);
executorService.init();
addEnvironmentEntry("ExecutorService", executorService);
addWorkItemHandler("SyncError", new FirstErrorWorkItemHandler());
addProcessEventListener(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
synchronized (LOCK) {
LOCK.notifyAll();
}
}
});
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class AsyncIntermediateCatchSignalTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
executorService = ExecutorServiceFactory.newExecutorService(getEmf());
executorService.setInterval(0);
executorService.setThreadPoolSize(3);
addEnvironmentEntry("ExecutorService", executorService);
addWorkItemHandler("SyncError", new FirstErrorWorkItemHandler());
addProcessEventListener(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
latch.countDown();
}
});
executorService.init();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class AsyncThreadContinuationTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
executorService = ExecutorServiceFactory.newExecutorService(getEmf());
executorService.setInterval(1);
executorService.init();
addEnvironmentEntry("ExecutorService", executorService);
addWorkItemHandler("SyncError", new FirstErrorWorkItemHandler());
addProcessEventListener(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
System.out.println(event.getProcessInstance().getProcessId());
if (event.getProcessInstance().getProcessId().equals(PROCESS_ATC)) {
synchronized (LOCK_ATC) {
LOCK_ATC.notifyAll();
}
} else if (event.getProcessInstance().getProcessId().equals(PROCESS_IT)) {
synchronized (LOCK_IT) {
LOCK_IT.notifyAll();
}
}
}
});
}
Aggregations