public void testSetRetriesByJobDefinitionIdResolveIncident() {
startProcessInstance(PROCESS_DEFINITION_KEY);
ProcessInstance pi = runtimeService.createProcessInstanceQuery().singleResult();
HistoricIncidentQuery query = historyService.createHistoricIncidentQuery().processInstanceId(pi.getId());
HistoricIncident incident = query.singleResult();
assertNotNull(incident);
runtimeService.setVariable(pi.getId(), "fail", false);
JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
// set retries to 1 by job definition id
managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 1);
// the incident still exists
HistoricIncident tmp = query.singleResult();
assertEquals(incident.getId(), tmp.getId());
assertNull(tmp.getEndTime());
assertTrue(tmp.isOpen());
// execute the available job (should fail again)
executeAvailableJobs();
// the incident still exists and there
// should be not a new incident
assertEquals(1, query.count());
tmp = query.singleResult();
assertEquals(incident.getId(), tmp.getId());
assertNotNull(tmp.getEndTime());
assertTrue(tmp.isResolved());
assertProcessEnded(pi.getId());