Search in sources :

Example 6 with UpdateTimerCommand

use of org.jbpm.process.instance.command.UpdateTimerCommand in project jbpm by kiegroup.

the class TimerUpdateTest method updateTimerShortherDelayTest.

@Test(timeout = 30000)
public void updateTimerShortherDelayTest() {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_NAME, 1);
    // delay is set for 5s
    setProcessScenario(TIMER_FILE);
    kieSession.addEventListener(countDownListener);
    final List<Long> list = new ArrayList<Long>();
    kieSession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    Assertions.assertThat(list).isEmpty();
    long id = kieSession.startProcess(PROCESS_NAME).getId();
    long startTime = System.currentTimeMillis();
    Assertions.assertThat(list).isNotEmpty();
    // set delay to 3s
    kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, 3));
    countDownListener.waitTillCompleted();
    Assertions.assertThat(timerHasFired()).isTrue();
    long firedTime = timerFiredTime();
    long timeDifference = Math.abs(firedTime - startTime - 3000);
    logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
    Assertions.assertThat(timeDifference).isLessThan(500);
    Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) UpdateTimerCommand(org.jbpm.process.instance.command.UpdateTimerCommand) Test(org.junit.Test)

Example 7 with UpdateTimerCommand

use of org.jbpm.process.instance.command.UpdateTimerCommand in project jbpm by kiegroup.

the class TimerUpdateTest method updateBoundaryTimerTest.

@Test(timeout = 30000)
public void updateBoundaryTimerTest() {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(BOUNDARY_TIMER_NAME, 1);
    // timer is set for long duration (100s)
    setProcessScenario(BOUNDARY_TIMER_FILE);
    final List<Long> list = new ArrayList<Long>();
    kieSession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    kieSession.addEventListener(countDownListener);
    Assertions.assertThat(list).isEmpty();
    long id = kieSession.startProcess(BOUNDARY_PROCESS_NAME).getId();
    long startTime = System.currentTimeMillis();
    Assertions.assertThat(list).isNotEmpty();
    // set timer delay to 3s
    kieSession.execute(new UpdateTimerCommand(id, BOUNDARY_TIMER_ATTACHED_TO_NAME, 3));
    countDownListener.waitTillCompleted();
    Assertions.assertThat(timerHasFired()).isTrue();
    long firedTime = timerFiredTime();
    long timeDifference = Math.abs(firedTime - startTime - 3000);
    logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
    Assertions.assertThat(timeDifference).isLessThan(1000);
    Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) UpdateTimerCommand(org.jbpm.process.instance.command.UpdateTimerCommand) Test(org.junit.Test)

Aggregations

UpdateTimerCommand (org.jbpm.process.instance.command.UpdateTimerCommand)7 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)5 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)5 HashMap (java.util.HashMap)1 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)1 RelativeUpdateTimerCommand (org.jbpm.process.instance.command.RelativeUpdateTimerCommand)1 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)1 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)1 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)1 KieBase (org.kie.api.KieBase)1 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1