Skip to content

Commit a8e138c

Browse files
committed
Replace usage of JobExplorer with JobRepository in SystemCommandTasklet
Resolves #4927
1 parent 821b03a commit a8e138c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import org.springframework.batch.core.ExitStatus;
2626
import org.springframework.batch.core.job.JobExecution;
2727
import org.springframework.batch.core.job.JobInterruptedException;
28+
import org.springframework.batch.core.repository.JobRepository;
2829
import org.springframework.batch.core.step.StepContribution;
2930
import org.springframework.batch.core.step.StepExecution;
3031
import org.springframework.batch.core.listener.StepExecutionListener;
31-
import org.springframework.batch.core.repository.explore.JobExplorer;
3232
import org.springframework.batch.core.scope.context.ChunkContext;
3333
import org.springframework.batch.repeat.RepeatStatus;
3434
import org.springframework.beans.factory.InitializingBean;
@@ -88,7 +88,7 @@ public class SystemCommandTasklet implements StepExecutionListener, StoppableTas
8888

8989
private volatile boolean stopped = false;
9090

91-
private JobExplorer jobExplorer;
91+
private JobRepository jobRepository;
9292

9393
private boolean stoppable = false;
9494

@@ -113,7 +113,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
113113
Thread.sleep(checkInterval);// moved to the end of the logic
114114

115115
if (stoppable) {
116-
JobExecution jobExecution = jobExplorer
116+
JobExecution jobExecution = jobRepository
117117
.getJobExecution(chunkContext.getStepContext().getStepExecution().getJobExecutionId());
118118

119119
if (jobExecution.isStopping()) {
@@ -201,11 +201,11 @@ public void afterPropertiesSet() throws Exception {
201201
Assert.state(systemProcessExitCodeMapper != null, "SystemProcessExitCodeMapper must be set");
202202
Assert.state(timeout > 0, "timeout value must be greater than zero");
203203
Assert.state(taskExecutor != null, "taskExecutor is required");
204-
stoppable = jobExplorer != null;
204+
stoppable = jobRepository != null;
205205
}
206206

207-
public void setJobExplorer(JobExplorer jobExplorer) {
208-
this.jobExplorer = jobExplorer;
207+
public void setJobRepository(JobRepository jobRepository) {
208+
this.jobRepository = jobRepository;
209209
}
210210

211211
/**

spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import org.springframework.batch.core.job.JobInstance;
3131
import org.springframework.batch.core.job.JobInterruptedException;
3232
import org.springframework.batch.core.job.parameters.JobParameters;
33+
import org.springframework.batch.core.repository.JobRepository;
3334
import org.springframework.batch.core.step.StepContribution;
3435
import org.springframework.batch.core.step.StepExecution;
35-
import org.springframework.batch.core.repository.explore.JobExplorer;
3636
import org.springframework.batch.core.scope.context.ChunkContext;
3737
import org.springframework.batch.core.scope.context.StepContext;
3838
import org.springframework.batch.repeat.RepeatStatus;
@@ -61,7 +61,7 @@ class SystemCommandTaskletIntegrationTests {
6161
new JobExecution(new JobInstance(1L, "systemCommandJob"), 1L, new JobParameters()));
6262

6363
@Mock
64-
private JobExplorer jobExplorer;
64+
private JobRepository jobRepository;
6565

6666
@BeforeEach
6767
void setUp() throws Exception {
@@ -247,14 +247,14 @@ void testWorkingDirectory() throws Exception {
247247
@Test
248248
void testStopped() throws Exception {
249249
initializeTasklet();
250-
tasklet.setJobExplorer(jobExplorer);
250+
tasklet.setJobRepository(jobRepository);
251251
tasklet.afterPropertiesSet();
252252
tasklet.beforeStep(stepExecution);
253253

254254
JobExecution stoppedJobExecution = new JobExecution(stepExecution.getJobExecution());
255255
stoppedJobExecution.setStatus(BatchStatus.STOPPING);
256256

257-
when(jobExplorer.getJobExecution(1L)).thenReturn(stepExecution.getJobExecution(),
257+
when(jobRepository.getJobExecution(1L)).thenReturn(stepExecution.getJobExecution(),
258258
stepExecution.getJobExecution(), stoppedJobExecution);
259259

260260
String[] command = isRunningOnWindows() ? new String[] { "ping", "127.0.0.1", "-n", "5" }

0 commit comments

Comments
 (0)