diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/job/JobStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/job/JobStep.java index 93ecb313d..4a2214c44 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/job/JobStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/job/JobStep.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.step.job; +import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; @@ -119,6 +120,9 @@ public class JobStep extends AbstractStep { // AbstractStep will take care of the step execution status throw new UnexpectedJobExecutionException("Step failure: the delegate Job failed in JobStep."); } + else if(jobExecution.getStatus().equals(BatchStatus.STOPPED)) { + stepExecution.setStatus(BatchStatus.STOPPED); + } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java index 45a119fd5..c44e4e14e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java @@ -15,8 +15,11 @@ */ package org.springframework.batch.core.step.job; +import java.util.Date; + import org.junit.Before; import org.junit.Test; + import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; @@ -28,8 +31,6 @@ import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.batch.item.ExecutionContext; -import java.util.Date; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -171,4 +172,35 @@ public class JobStepTests { } + @Test + public void testStoppedChild() throws Exception { + + DefaultJobParametersExtractor jobParametersExtractor = new DefaultJobParametersExtractor(); + jobParametersExtractor.setKeys(new String[] {"foo"}); + ExecutionContext executionContext = stepExecution.getExecutionContext(); + executionContext.put("foo", "bar"); + step.setJobParametersExtractor(jobParametersExtractor); + + step.setJob(new JobSupport("child") { + @Override + public void execute(JobExecution execution) { + assertEquals(1, execution.getJobParameters().getParameters().size()); + execution.setStatus(BatchStatus.STOPPED); + execution.setEndTime(new Date()); + jobRepository.update(execution); + } + @Override + public boolean isRestartable() { + return true; + } + }); + + step.afterPropertiesSet(); + step.execute(stepExecution); + JobExecution jobExecution = stepExecution.getJobExecution(); + jobExecution.setEndTime(new Date()); + jobRepository.update(jobExecution); + + assertEquals(BatchStatus.STOPPED, stepExecution.getStatus()); + } }