job.setRestartable(true);
StepSupport step = new StepSupport("restartedStep");
// first execution
JobExecution firstJobExec = jobRepository.createJobExecution(job.getName(), jobParameters);
StepExecution firstStepExec = new StepExecution(step.getName(), firstJobExec);
jobRepository.add(firstStepExec);
assertEquals(1, jobRepository.getStepExecutionCount(firstJobExec.getJobInstance(), step.getName()));
assertEquals(firstStepExec, jobRepository.getLastStepExecution(firstJobExec.getJobInstance(), step.getName()));
// first execution failed
firstJobExec.setStartTime(new Date(4));
firstStepExec.setStartTime(new Date(5));
firstStepExec.setStatus(BatchStatus.FAILED);
firstStepExec.setEndTime(new Date(6));
jobRepository.update(firstStepExec);
firstJobExec.setStatus(BatchStatus.FAILED);
firstJobExec.setEndTime(new Date(7));
jobRepository.update(firstJobExec);
// second execution
JobExecution secondJobExec = jobRepository.createJobExecution(job.getName(), jobParameters);
StepExecution secondStepExec = new StepExecution(step.getName(), secondJobExec);
jobRepository.add(secondStepExec);
assertEquals(2, jobRepository.getStepExecutionCount(secondJobExec.getJobInstance(), step.getName()));
assertEquals(secondStepExec, jobRepository.getLastStepExecution(secondJobExec.getJobInstance(), step.getName()));
}