use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testTimerOnPerCaseManager.
@Test(timeout = 10000)
public void testTimerOnPerCaseManager() throws Exception {
final Set<Long> ksessionUsed = new HashSet<Long>();
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
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("timer")) {
timerExpirations.add(event.getProcessInstance().getId());
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
}
});
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(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(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
long ksession1Id = ksession.getIdentifier();
ProcessInstance pi1 = ksession.startProcess("IntermediateCatchEvent");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
// wait a bit for some timers to fire
countDownListener.waitTillCompleted();
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
ksession.abortProcessInstance(pi1.getId());
manager.disposeRuntimeEngine(runtime);
manager.close();
// there should be only one ksession used
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
}
use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testRestoreTimersAfterManagerClose.
@Test(timeout = 30000)
public void testRestoreTimersAfterManagerClose() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 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("timer")) {
timerExpirations.add(event.getProcessInstance().getId());
}
}
});
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventTimerCycle3.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("IntermediateCatchEvent");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
// wait a bit for some timers to fire
countDownListener.waitTillCompleted();
((AbstractRuntimeManager) manager).close(true);
int currentNumberOfTriggers = timerExpirations.size();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
countDownListener.reset(2);
countDownListener.waitTillCompleted();
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
runtime.getKieSession().abortProcessInstance(pi1.getId());
manager.disposeRuntimeEngine(runtime);
manager.close();
assertTrue(timerExpirations.size() > currentNumberOfTriggers);
}
Aggregations