Fix object graph deletion in SimpleJobRepository#deleteJobExecution
Before this commit, SimpleJobRepository#deleteJobExecution did not delete associated step executions as specified in the contract of the method. This commit fixes the implementation to delete the entire object graph as specified. Resolves #4249
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -320,6 +320,9 @@ public class SimpleJobRepository implements JobRepository {
|
||||
public void deleteJobExecution(JobExecution jobExecution) {
|
||||
this.ecDao.deleteExecutionContext(jobExecution);
|
||||
this.jobExecutionDao.deleteJobExecutionParameters(jobExecution);
|
||||
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
|
||||
deleteStepExecution(stepExecution);
|
||||
}
|
||||
this.jobExecutionDao.deleteJobExecution(jobExecution);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,9 +51,9 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
|
||||
/**
|
||||
* Test SimpleJobRepository. The majority of test cases are tested using EasyMock,
|
||||
* however, there were some issues with using it for the stepExecutionDao when testing
|
||||
* finding or creating steps, so an actual mock class had to be written.
|
||||
* Test SimpleJobRepository. The majority of test cases are tested using Mockito, however,
|
||||
* there were some issues with using it for the stepExecutionDao when testing finding or
|
||||
* creating steps, so an actual mock class had to be written.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Will Schipp
|
||||
@@ -345,4 +345,25 @@ class SimpleJobRepositoryTests {
|
||||
assertEquals(this.jobInstance, jobInstance);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteJobExecution() {
|
||||
// given
|
||||
StepExecution stepExecution1 = mock(StepExecution.class);
|
||||
StepExecution stepExecution2 = mock(StepExecution.class);
|
||||
JobExecution jobExecution = mock(JobExecution.class);
|
||||
when(jobExecution.getStepExecutions()).thenReturn(Arrays.asList(stepExecution1, stepExecution2));
|
||||
|
||||
// when
|
||||
this.jobRepository.deleteJobExecution(jobExecution);
|
||||
|
||||
// then
|
||||
verify(this.ecDao).deleteExecutionContext(jobExecution);
|
||||
verify(this.jobExecutionDao).deleteJobExecutionParameters(jobExecution);
|
||||
verify(this.ecDao).deleteExecutionContext(stepExecution1);
|
||||
verify(this.stepExecutionDao).deleteStepExecution(stepExecution1);
|
||||
verify(this.ecDao).deleteExecutionContext(stepExecution2);
|
||||
verify(this.stepExecutionDao).deleteStepExecution(stepExecution2);
|
||||
verify(this.jobExecutionDao).deleteJobExecution(jobExecution);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -142,13 +142,10 @@ public class JobRepositoryTestUtils {
|
||||
|
||||
/**
|
||||
* Remove the {@link JobExecution} and its associated {@link StepExecution} instances
|
||||
* Ôfrom the standard locations used by Spring Batch.
|
||||
* from the standard locations used by Spring Batch.
|
||||
* @param jobExecution the {@link JobExecution} to delete
|
||||
*/
|
||||
public void removeJobExecution(JobExecution jobExecution) {
|
||||
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
|
||||
this.jobRepository.deleteStepExecution(stepExecution);
|
||||
}
|
||||
this.jobRepository.deleteJobExecution(jobExecution);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user