@Deployment(resources = { "org/activiti/engine/test/api/mgmt/timerOnTask.bpmn20.xml" })
public void testDeleteJobThatWasAlreadyAcquired() {
processEngineConfiguration.getClock().setCurrentTime(new Date());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnTask");
Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
// We need to move time at least one hour to make the timer executable
processEngineConfiguration.getClock().setCurrentTime(new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + 7200000L));
// Acquire job by running the acquire command manually
ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) processEngine;
AcquireTimerJobsCmd acquireJobsCmd = new AcquireTimerJobsCmd("testLockOwner", 60000, 5);
CommandExecutor commandExecutor = processEngineImpl.getProcessEngineConfiguration().getCommandExecutor();
commandExecutor.execute(acquireJobsCmd);
// Try to delete the job. This should fail.
try {
managementService.deleteJob(timerJob.getId());
fail();
} catch (ActivitiException e) {
// Exception is expected
}
// Clean up
managementService.executeJob(timerJob.getId());
}