use of org.jbpm.test.functional.timer.addon.TransactionalThreadPoolSchedulerService in project jbpm by kiegroup.
the class GlobalThreadPoolTimerServiceTest method testInterediateTimerWithGlobalTestServiceWithinTransaction.
@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestServiceWithinTransaction() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
globalScheduler = new TransactionalThreadPoolSchedulerService(3);
// 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());
}
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).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");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for first timer to trigger
countDownListener.waitTillCompleted(2000);
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
countDownListener.reset(1);
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
assertEquals(3, timerExporations.size());
manager.disposeRuntimeEngine(runtime);
}
Aggregations