diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java index fe5ad0998..83b2872a5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java @@ -207,7 +207,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw throw new JobInterruptedException("JobExecution interrupted."); } - stepExecution.setStatus(BatchStatus.COMPLETED); + // Need to upgrade here not set, in case the execution was stopped + stepExecution.upgradeStatus(BatchStatus.COMPLETED); logger.debug("Step execution success: id=" + stepExecution.getId()); } catch (Throwable e) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java index 7132cb573..c09f9f546 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java @@ -104,4 +104,28 @@ public class PartitionStepTests { assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); } + @Test + public void testStoppedStepExecution() throws Exception { + step.setStepExecutionSplitter(new SimpleStepExecutionSplitter(jobRepository, remote)); + step.setPartitionHandler(new PartitionHandler() { + public Collection handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution) + throws Exception { + Set executions = stepSplitter.split(stepExecution, 2); + for (StepExecution execution : executions) { + execution.setStatus(BatchStatus.STOPPED); + execution.setExitStatus(ExitStatus.STOPPED); + } + return executions; + } + }); + step.afterPropertiesSet(); + JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters()); + StepExecution stepExecution = jobExecution.createStepExecution("foo"); + jobRepository.add(stepExecution); + step.execute(stepExecution); + // one master and two workers + assertEquals(3, stepExecution.getJobExecution().getStepExecutions().size()); + assertEquals(BatchStatus.STOPPED, stepExecution.getStatus()); + } + }