// 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();
assertEquals("First Task", task1.getName());
JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertEquals(2, jobs.size());
// After setting the clock to time '1 hour and 5 seconds', the first timer should fire
ClockUtil.setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L);
// we still have one timer more to fire
assertEquals(1L, jobQuery.count());
// and we are still in the first state, but in the second state as well!
assertEquals(2L, taskService.createTaskQuery().count());
List<Task> taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
assertEquals("First Task", taskList.get(0).getName());
assertEquals("Escalation Task 1", taskList.get(1).getName());
// complete the task and end the forked execution
taskService.complete(taskList.get(1).getId());
// but we still have the original executions
assertEquals(1L, taskService.createTaskQuery().count());
assertEquals("First Task", taskService.createTaskQuery().singleResult().getName());
// After setting the clock to time '2 hour and 5 seconds', the second timer should fire
ClockUtil.setCurrentTime(new Date(startTime.getTime() + ((2 * 60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L);
// no more timers to fire
assertEquals(0L, jobQuery.count());
// and we are still in the first state, but in the next escalation state as well
assertEquals(2L, taskService.createTaskQuery().count());
taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
assertEquals("First Task", taskList.get(0).getName());
assertEquals("Escalation Task 2", taskList.get(1).getName());
// This time we end the main task
taskService.complete(taskList.get(0).getId());
// but we still have the escalation task
assertEquals(1L, taskService.createTaskQuery().count());
Task escalationTask = taskService.createTaskQuery().singleResult();
assertEquals("Escalation Task 2", escalationTask.getName());
taskService.complete(escalationTask.getId());
// now we are really done :-)
assertProcessEnded(pi.getId());
}