// check if user task exists
TaskQuery taskQuery = taskService.createTaskQuery();
assertEquals(1, taskQuery.count());
JobQuery jobQuery = managementService.createJobQuery();
assertEquals(1, jobQuery.count());
String jobIdFirstLoop = jobQuery.list().get(0).getId();
// execute timer job
managementService.executeJob(jobIdFirstLoop);
assertEquals(true, DummyServiceTask.wasExecuted);
DummyServiceTask.wasExecuted = false;
assertEquals(2, executionQuery.count());
assertEquals(1, taskQuery.count());
// complete existing task to start new execution for multi instance loop
// number 2
taskService.complete(taskQuery.list().get(0).getId());
// execute multiInstance loop number 2
assertEquals(2, executionQuery.count());
assertEquals(1, taskQuery.count());
assertEquals(1, jobQuery.count());
String jobIdSecondLoop = jobQuery.list().get(0).getId();
assertNotSame(jobIdFirstLoop, jobIdSecondLoop);
// execute timer job
managementService.executeJob(jobIdSecondLoop);
assertEquals(true, DummyServiceTask.wasExecuted);
// multiInstance loop finished
assertEquals(0, jobQuery.count());
// check if user task doesn't exist because timer start event is
// interrupting
assertEquals(1, taskQuery.count());