Search in sources :

Example 1 with DefaultCountDownProcessEventListener

use of org.jbpm.test.listener.DefaultCountDownProcessEventListener in project jbpm by kiegroup.

the class ETransactionTest method testTimer.

@Test
public void testTimer() throws Exception {
    DefaultCountDownProcessEventListener listener = new DefaultCountDownProcessEventListener(0) {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if ("Timer".equals(event.getNodeInstance().getNodeName())) {
                countDown();
            }
        }
    };
    RuntimeManager manager = deploymentService.getRuntimeManager(kieJar);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    engine.getKieSession().addEventListener(listener);
    Long processInstanceId = startProcessInstance(PROCESS_ID);
    UserTransaction ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
    ut.begin();
    try {
        processService.signalProcessInstance(processInstanceId, "start", "timer");
        Assertions.assertThat(hasNodeLeft(processInstanceId, "timer")).isTrue();
    } catch (Exception e) {
        ut.rollback();
        throw e;
    }
    ut.rollback();
    ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
    ut.begin();
    try {
        processService.signalProcessInstance(processInstanceId, "start", "timer");
    } catch (Exception e) {
        ut.rollback();
        throw e;
    }
    ut.commit();
    listener.reset(1);
    listener.waitTillCompleted();
    Assertions.assertThat(hasNodeLeft(processInstanceId, "timer")).isTrue();
    Assertions.assertThat(hasNodeLeft(processInstanceId, "Timer")).isTrue();
    processService.signalProcessInstance(processInstanceId, "finish", null);
    Assertions.assertThat(hasProcessInstanceCompleted(processInstanceId)).isTrue();
}
Also used : UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DefaultCountDownProcessEventListener(org.jbpm.test.listener.DefaultCountDownProcessEventListener) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) AbstractRuntimeEJBServicesTest(org.jbpm.test.container.AbstractRuntimeEJBServicesTest) Test(org.junit.Test)

Aggregations

UserTransaction (javax.transaction.UserTransaction)1 AbstractRuntimeEJBServicesTest (org.jbpm.test.container.AbstractRuntimeEJBServicesTest)1 DefaultCountDownProcessEventListener (org.jbpm.test.listener.DefaultCountDownProcessEventListener)1 Test (org.junit.Test)1 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1