use of org.jbpm.process.instance.command.UpdateTimerCommand in project jbpm by kiegroup.
the class ProcessInstanceAdminServiceImpl method updateTimer.
@Override
public void updateTimer(long processInstanceId, long timerId, long delay, long period, int repeatLimit) throws NodeInstanceNotFoundException, ProcessInstanceNotFoundException {
ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
if (pi == null) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
}
processService.execute(pi.getDeploymentId(), ProcessInstanceIdContext.get(processInstanceId), new UpdateTimerCommand(processInstanceId, timerId, delay, period, repeatLimit));
}
use of org.jbpm.process.instance.command.UpdateTimerCommand in project jbpm by kiegroup.
the class IntermediateEventTest method testIntermediateCatchEventTimerDurationWithError.
@Test(timeout = 10000)
@RequirePersistence
public void testIntermediateCatchEventTimerDurationWithError() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 0);
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
long waitTime = 2;
assertProcessInstanceActive(processInstance);
// now wait for 1 second for timer to trigger
countDownListener.waitTillCompleted(waitTime * 1000);
assertProcessInstanceActive(processInstance);
processInstance = ksession.getProcessInstance(processInstance.getId());
// reschedule it to allow to move on
ksession.setGlobal("TestOK", Boolean.TRUE);
ksession.execute(new UpdateTimerCommand(processInstance.getId(), "timer", waitTime + 1));
countDownListener.reset(1);
countDownListener.waitTillCompleted();
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.process.instance.command.UpdateTimerCommand in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerLongerDelayTest.
@Test(timeout = 30000)
public void updateTimerLongerDelayTest() {
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 8s
kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, 8));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 8000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
use of org.jbpm.process.instance.command.UpdateTimerCommand in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerSubprocessLongerDelayTest.
@Test(timeout = 30000)
public void updateTimerSubprocessLongerDelayTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_SUBPROCESS_NAME, 1);
// delay is set for 5s
setProcessScenario(TIMER_SUBPROCESS_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());
}
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (TIMER_SUBPROCESS_NAME.equals(event.getNodeInstance().getNodeName())) {
System.setProperty(TIMER_FIRED_TEXT, "");
System.setProperty(TIMER_FIRED_TIME_PROP, String.valueOf(System.currentTimeMillis()));
}
}
});
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(PROCESS_SUBPROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set delay to 8s
kieSession.execute(new UpdateTimerCommand(id, TIMER_SUBPROCESS_NAME, 8));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 8000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
use of org.jbpm.process.instance.command.UpdateTimerCommand in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerBeforeDelayTest.
@Test(timeout = 30000)
public void updateTimerBeforeDelayTest() {
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 on time that passed -> expected that timer fired immediately
kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, -5));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
Aggregations