ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");
executeAvailableJobs();
// it exists a job with 0 retries and an incident
Job job = managementService.createJobQuery().singleResult();
assertEquals(0, job.getRetries());
assertEquals(1, runtimeService.createIncidentQuery().count());
// it should not be possible to set negative retries
final JobEntity jobEntity = (JobEntity) job;
processEngineConfiguration
.getCommandExecutorTxRequired()
.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
jobEntity.setRetries(-100);
return null;
}
});
assertEquals(0, job.getRetries());
// retries should still be 0 after execution this job again
try {
managementService.executeJob(job.getId());
fail("Exception expected");
}
catch (ProcessEngineException e) {
// expected
}
job = managementService.createJobQuery().singleResult();
assertEquals(0, job.getRetries());
// also no new incident was created
assertEquals(1, runtimeService.createIncidentQuery().count());
// it should not be possible to set the retries to a negative number with the management service
try {
managementService.setJobRetries(job.getId(), -200);
fail("Exception expected");
}
catch (ProcessEngineException e) {
// expected
}
try {
managementService.setJobRetriesByJobDefinitionId(job.getJobDefinitionId(), -300);
fail("Exception expected");
}
catch (ProcessEngineException e) {
// expected
}