// check if user task exists
TaskQuery taskQuery = taskService.createTaskQuery();
assertEquals(2, taskQuery.count());
JobQuery jobQuery = managementService.createJobQuery();
assertEquals(3, jobQuery.count());
// execute non interrupting timer job
managementService.executeJob(jobQuery.orderByJobDuedate().asc().list().get(1).getId());
assertEquals(true, DummyServiceTask.wasExecuted);
// after non interrupting timer job execution
assertEquals(2, jobQuery.count());
assertEquals(2, taskQuery.count());
assertEquals(6, executionQuery.count());
// execute interrupting boundary timer job
managementService.executeJob(jobQuery.orderByJobDuedate().asc().list().get(0).getId());
// after interrupting boundary timer job execution
assertEquals(0, jobQuery.count());
assertEquals(0, taskQuery.count());
assertEquals(0, executionQuery.count());
assertProcessEnded(processInstance.getId());
// start process instance again and
// test if boundary events deleted after all tasks are completed
processInstance = runtimeService.startProcessInstanceByKey("process");
jobQuery = managementService.createJobQuery();
assertEquals(3, jobQuery.count());
assertEquals(2, taskQuery.count());
// complete all existing tasks
for (Task task : taskQuery.list()) {
taskService.complete(task.getId());
}
assertEquals(0, jobQuery.count());
assertEquals(0, taskQuery.count());
assertEquals(0, executionQuery.count());
assertProcessEnded(processInstance.getId());