// case 1
// given an inconsistent job that is never again picked up by a job executor
createJob(0, "owner", ClockUtil.getCurrentTime());
// when the job retries are reset
JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
managementService.setJobRetries(job.getId(), 3);
// then the job can be picked up again
job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNull(job.getLockOwner());
assertNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
// case 2
// given an inconsistent job that is never again picked up by a job executor
createJob(2, "owner", null);
// when the job retries are reset
job = (JobEntity) managementService.createJobQuery().singleResult();
managementService.setJobRetries(job.getId(), 3);
// then the job can be picked up again
job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNull(job.getLockOwner());
assertNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
// case 3
// given a consistent job
createJob(2, "owner", ClockUtil.getCurrentTime());
// when the job retries are reset
job = (JobEntity) managementService.createJobQuery().singleResult();
managementService.setJobRetries(job.getId(), 3);
// then the lock owner and expiration should not change
job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNotNull(job.getLockOwner());
assertNotNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
}