assertNotNull(pi);
waitForExecutedJobWithRetriesLeft(4);
stillOneJobWithExceptionAndRetriesLeft();
Job job = fetchJob(pi.getProcessInstanceId());
assertNotNull(job);
assertEquals(pi.getProcessInstanceId(), job.getProcessInstanceId());
assertEquals(4, job.getRetries());
ExecutionEntity execution = fetchExecutionEntity(pi.getProcessInstanceId());
assertEquals("failingServiceTask", execution.getActivityId());
waitForExecutedJobWithRetriesLeft(3);
job = refreshJob(job.getId());
assertEquals(3, job.getRetries());
stillOneJobWithExceptionAndRetriesLeft();
execution = refreshExecutionEntity(execution.getId());
assertEquals("failingServiceTask", execution.getActivityId());
waitForExecutedJobWithRetriesLeft(2);
job = refreshJob(job.getId());
assertEquals(2, job.getRetries());
stillOneJobWithExceptionAndRetriesLeft();
execution = refreshExecutionEntity(execution.getId());
assertEquals("failingServiceTask", execution.getActivityId());
waitForExecutedJobWithRetriesLeft(1);
job = refreshJob(job.getId());
assertEquals(1, job.getRetries());
stillOneJobWithExceptionAndRetriesLeft();
execution = refreshExecutionEntity(execution.getId());
assertEquals("failingServiceTask", execution.getActivityId());
waitForExecutedJobWithRetriesLeft(0);
job = refreshJob(job.getId());
assertEquals(0, job.getRetries());
assertEquals(1, managementService.createJobQuery().withException().count());
assertEquals(0, managementService.createJobQuery().withRetriesLeft().count());
assertEquals(1, managementService.createJobQuery().noRetriesLeft().count());
execution = refreshExecutionEntity(execution.getId());