//Delete the process instance.
runtimeService.deleteProcessInstance(instanceUser.getId(), null);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
//Retrieve the HistoricProcessInstance and assert that there is an end time.
HistoricProcessInstance hInstanceUser = historyService.createHistoricProcessInstanceQuery().processInstanceId(instanceUser.getId()).singleResult();
assertNotNull(hInstanceUser.getEndTime());
log.info("End time for the deleted instance of \"Demo Partial Deletion\" that was started with a Task Type of \"user\": " + hInstanceUser.getEndTime() + ".");
log.info("Successfully deleted the instance of \"Demo Partial Deletion\" that was started with a Task Type of \"user\".");
}
//Note that the instance with a Task Type of "java" is being started.
log.info("Starting an instance of \"Demo Partial Deletion\" with a Task Type of \"java\".");
//Set the inputs for the second process instance, which we will NOT be able to completely delete.
Map<String,Object> inputParamsJava = new HashMap<String,Object>();
inputParamsJava.put("taskType", "java");
//Start the process instance & ensure it's started.
ProcessInstance instanceJava = runtimeService.startProcessInstanceByKey("DemoPartialDeletion", inputParamsJava);
assertNotNull(instanceJava);
log.info("Process instance (of process model " + instanceJava.getProcessDefinitionId() + ") started with id: " + instanceJava.getId() + ".");
//Assert that the process instance is active.
Execution executionJava = runtimeService.createExecutionQuery().processInstanceId(instanceJava.getProcessInstanceId()).singleResult();
assertFalse(executionJava.isEnded());
// Try to execute job 3 times
Job jobJava = managementService.createJobQuery().processInstanceId(instanceJava.getId()).singleResult();
assertNotNull(jobJava);
try {
managementService.executeJob(jobJava.getId());
fail("Expected exception");
} catch (Exception e) {
// expected
}
try {
managementService.executeJob(jobJava.getId());
fail("Expected exception");
} catch (Exception e) {
// expected
}
try {
managementService.executeJob(jobJava.getId());
fail("Expected exception");
} catch (Exception e) {
// expected
}
//Assert that there is a failed job.
jobJava = managementService.createJobQuery().processInstanceId(instanceJava.getId()).singleResult();
assertNotNull(jobJava);
assertEquals(0, jobJava.getRetries());
//Delete the process instance.
runtimeService.deleteProcessInstance(instanceJava.getId(), null);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
//Retrieve the HistoricProcessInstance and assert that there is no end time.
HistoricProcessInstance hInstanceJava = historyService.createHistoricProcessInstanceQuery().processInstanceId(instanceJava.getId()).singleResult();
assertNotNull(hInstanceJava.getEndTime());
}
}