diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java index e03f7d41e..a55a0fe50 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemOrientedStep.java @@ -320,7 +320,6 @@ public class ItemOrientedStep extends AbstractStep { // check for interruption before each item as well interruptionPolicy.checkInterrupted(execution); ExitStatus exitStatus = itemHandler.handle(contribution); - contribution.incrementItemCount(); // check for interruption after each item as well interruptionPolicy.checkInterrupted(execution); return exitStatus; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleItemHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleItemHandler.java index c5ea475bd..c2d047c3f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleItemHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleItemHandler.java @@ -89,6 +89,7 @@ public class SimpleItemHandler implements ItemHandler { * @param contribution current context */ protected void write(Object item, StepContribution contribution) throws Exception { + contribution.incrementItemCount(); doWrite(item); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java index 1a5041755..48adb486e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/ItemOrientedStepTests.java @@ -52,6 +52,7 @@ import org.springframework.batch.item.MarkFailedException; import org.springframework.batch.item.ResetFailedException; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.batch.support.PropertiesConverter; @@ -750,6 +751,22 @@ public class ItemOrientedStepTests extends TestCase { assertTrue(stepExecution.getExecutionContext().getString("spam").equals("bucket")); } } + + public void testStepToCompletion() throws Exception { + + RepeatTemplate template = new RepeatTemplate(); + + // process all items: + template.setCompletionPolicy(new DefaultResultCompletionPolicy()); + itemOrientedStep.setStepOperations(template); + + JobExecution jobExecutionContext = new JobExecution(jobInstance); + StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext); + + itemOrientedStep.execute(stepExecution); + assertEquals(3, processed.size()); + assertEquals(3, stepExecution.getItemCount().intValue()); + } /** * Exception in {@link StepExecutionListener#afterStep(StepExecution)}