Spring Batch
  1. Spring Batch
  2. BATCH-531

Off by one error in itemCount of StepExecution

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.0
    • Fix Version/s: 1.0.1
    • Component/s: Core
    • Labels:
      None

      Description

      The StepExecution always has one more item at the end than it should. Here's a unit test (insert in ItemOrientedStepTests):

      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()); }

        Activity

        Hide
        Lucas Ward added a comment -

        Robert and I just talked about this and it seems like the fix would be to call StepContribution.incrementItemCount() in the SimpleItemHandler before calling doWrite(). The ItemOrientedStep would then combine it accurately with the StepExecution.

        Show
        Lucas Ward added a comment - Robert and I just talked about this and it seems like the fix would be to call StepContribution.incrementItemCount() in the SimpleItemHandler before calling doWrite(). The ItemOrientedStep would then combine it accurately with the StepExecution.
        Hide
        Lucas Ward added a comment -

        I moved the item count increment to the SimpleItemHandler so that it only increments before writing. An interesting side affect of this change is that read failures that cause a skip will not be counted. I feel like this is probably okay since it never actually read an item, so I'm marking resolved. If anyone has an issue with this side affect, please raise as a new issue.

        Show
        Lucas Ward added a comment - I moved the item count increment to the SimpleItemHandler so that it only increments before writing. An interesting side affect of this change is that read failures that cause a skip will not be counted. I feel like this is probably okay since it never actually read an item, so I'm marking resolved. If anyone has an issue with this side affect, please raise as a new issue.
        Hide
        Dave Syer added a comment -

        Assume closed as resolved and released

        Show
        Dave Syer added a comment - Assume closed as resolved and released

          People

          • Assignee:
            Lucas Ward
            Reporter:
            Dave Syer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: