use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.
the class BoundaryTimerEventTest method testNullExpressionOnTimer.
@Deployment
public void testNullExpressionOnTimer() {
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("duration", null);
// After process start, there should be a timer created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testNullExpressionOnTimer", variables);
// NO job scheduled as null expression set
TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertThat(jobs).hasSize(0);
// which means the process is still running waiting for human task input.
ProcessInstance processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
assertThat(processInstance).isNotNull();
}
use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.
the class BoundaryTimerEventTest method testMultipleTimersOnUserTask.
/*
* Test for when multiple boundary timer events are defined on the same user task
*
* Configuration: - timer 1 -> 2 hours -> secondTask - timer 2 -> 1 hour -> thirdTask - timer 3 -> 3 hours -> fourthTask
*
* See process image next to the process xml resource
*/
@Deployment
public void testMultipleTimersOnUserTask() {
// Set the clock fixed
Date startTime = new Date();
// After process start, there should be 3 timers created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("multipleTimersOnUserTask");
TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertThat(jobs).hasSize(3);
// After setting the clock to time '1 hour and 5 seconds', the second
// timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L, 25L);
assertThat(jobQuery.count()).isEqualTo(0L);
// which means that the third task is reached
Task task = taskService.createTaskQuery().singleResult();
assertThat(task.getName()).isEqualTo("Third Task");
}
use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testJoin.
@Deployment
public void testJoin() {
// Set the clock fixed
Date startTime = new Date();
// After process start, there should be 3 timers created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testJoin");
Task task1 = taskService.createTaskQuery().singleResult();
assertThat(task1.getName()).isEqualTo("Main Task");
TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertThat(jobs).hasSize(1);
// After setting the clock to time '1 hour and 5 seconds', the first timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L, 25L);
// timer has fired
assertThat(jobQuery.count()).isEqualTo(0L);
// we now have both tasks
assertThat(taskService.createTaskQuery().count()).isEqualTo(2L);
// end the first
taskService.complete(task1.getId());
// we now have one task left
assertThat(taskService.createTaskQuery().count()).isEqualTo(1L);
Task task2 = taskService.createTaskQuery().singleResult();
assertThat(task2.getName()).isEqualTo("Escalation Task");
// complete the task, the parallel gateway should fire
taskService.complete(task2.getId());
// and the process has ended
assertProcessEnded(pi.getId());
}
use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testMultipleTimersOnUserTask.
@Deployment
public void testMultipleTimersOnUserTask() {
// Set the clock fixed
Date startTime = new Date();
// After process start, there should be 3 timers created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("nonInterruptingTimersOnUserTask");
Task task1 = taskService.createTaskQuery().singleResult();
assertThat(task1.getName()).isEqualTo("First Task");
TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertThat(jobs).hasSize(2);
// After setting the clock to time '1 hour and 5 seconds', the first timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
Job job = managementService.createTimerJobQuery().executable().singleResult();
assertThat(job).isNotNull();
managementService.moveTimerToExecutableJob(job.getId());
managementService.executeJob(job.getId());
// we still have one timer more to fire
assertThat(jobQuery.count()).isEqualTo(1L);
// and we are still in the first state, but in the second state as well!
assertThat(taskService.createTaskQuery().count()).isEqualTo(2L);
List<Task> taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
assertThat(taskList.get(0).getName()).isEqualTo("First Task");
assertThat(taskList.get(1).getName()).isEqualTo("Escalation Task 1");
// complete the task and end the forked execution
taskService.complete(taskList.get(1).getId());
// but we still have the original executions
assertThat(taskService.createTaskQuery().count()).isEqualTo(1L);
assertThat(taskService.createTaskQuery().singleResult().getName()).isEqualTo("First Task");
// After setting the clock to time '2 hour and 5 seconds', the second timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((2 * 60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L, 25L);
// no more timers to fire
assertThat(jobQuery.count()).isEqualTo(0L);
// and we are still in the first state, but in the next escalation state as well
assertThat(taskService.createTaskQuery().count()).isEqualTo(2L);
taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
assertThat(taskList.get(0).getName()).isEqualTo("First Task");
assertThat(taskList.get(1).getName()).isEqualTo("Escalation Task 2");
// This time we end the main task
taskService.complete(taskList.get(0).getId());
// but we still have the escalation task
assertThat(taskService.createTaskQuery().count()).isEqualTo(1L);
Task escalationTask = taskService.createTaskQuery().singleResult();
assertThat(escalationTask.getName()).isEqualTo("Escalation Task 2");
taskService.complete(escalationTask.getId());
// now we are really done :-)
assertProcessEnded(pi.getId());
}
use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testReceiveTaskWithBoundaryTimer.
@Deployment
public /**
* see https://activiti.atlassian.net/browse/ACT-1106
*/
void testReceiveTaskWithBoundaryTimer() {
// Set the clock fixed
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("timeCycle", "R/PT1H");
// After process start, there should be a timer created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("nonInterruptingCycle", variables);
TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertThat(jobs).hasSize(1);
// The Execution Query should work normally and find executions in state "task"
List<Execution> executions = runtimeService.createExecutionQuery().activityId("task").list();
assertThat(executions).hasSize(1);
List<String> activeActivityIds = runtimeService.getActiveActivityIds(executions.get(0).getId());
assertThat(activeActivityIds).hasSize(2);
Collections.sort(activeActivityIds);
assertThat(activeActivityIds.get(0)).isEqualTo("task");
assertThat(activeActivityIds.get(1)).isEqualTo("timer");
runtimeService.trigger(executions.get(0).getId());
// // After setting the clock to time '1 hour and 5 seconds', the second
// timer should fire
// processEngineConfiguration.getClock().setCurrentTime(new
// Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
// waitForJobExecutorToProcessAllJobs(5000L, 25L);
// assertThat(jobQuery.count()).isEqualTo(0L);
// which means the process has ended
assertProcessEnded(pi.getId());
}
Aggregations