BATCH-531: Moved item count increment from Step to ItemHandler so that the last call to ItemReader#read() doesn't inadvertently increment the count. Also added a test case.

This commit is contained in:
lucasward
2008-04-09 03:38:27 +00:00
parent 3877476e15
commit 3edc30eec6
3 changed files with 18 additions and 1 deletions

View File

@@ -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)}