Search in sources :

Example 1 with TransactionalThreadPoolSchedulerService

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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TransactionalThreadPoolSchedulerService(org.jbpm.test.functional.timer.addon.TransactionalThreadPoolSchedulerService) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 TransactionalThreadPoolSchedulerService (org.jbpm.test.functional.timer.addon.TransactionalThreadPoolSchedulerService)1 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)1 Test (org.junit.Test)1 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)1 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)1 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)1