-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Related to #4229.
Bug description
Running a Job and then using JobRepositoryTestUtils#removeJobExecutions()
fails, because the method does not delete the StepExecution
s.
The method selects the executions to delete with this code:
Lines 168 to 171 in 9223826
List<JobExecution> jobExecutions = this.jobRepository.findJobExecutions(jobInstance); | |
if (jobExecutions != null && !jobExecutions.isEmpty()) { | |
removeJobExecutions(jobExecutions); | |
} |
But
findJobExecutions(JobInstance)
does not populate the execution's stepExecutions
attribute (we are missing a call to stepExecutionDao#addStepExecutions(JobExecution)
):Lines 100 to 103 in 9223826
@Override | |
public List<JobExecution> findJobExecutions(JobInstance jobInstance) { | |
return this.jobExecutionDao.findJobExecutions(jobInstance); | |
} |
The subsequent call to removeJobExecutions(jobExecutions)
then won't delete the StepExecution
s, due to getStepExecutions()
being empty:
Lines 148 to 151 in 9223826
public void removeJobExecution(JobExecution jobExecution) { | |
for (StepExecution stepExecution : jobExecution.getStepExecutions()) { | |
this.jobRepository.deleteStepExecution(stepExecution); | |
} |
This causes FK constraint violations when the job executions themselves are then deleted afterwards.
Environment
Spring Batch 5.0.0-SNAPSHOT (this commit)
Steps to reproduce
- Run a Job.
- Call
JobRepositoryTestUtils#removeJobExecutions()
Expected behavior
Method call succeeds, all executions are deleted.