Package org.springframework.batch.core

Examples of org.springframework.batch.core.Step


    reader.setFailures("2");
    writer.setFailures("4");

    factory.setSkipLimit(1);

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(1, stepExecution.getSkipCount());

    // writer did not skip "2" as it never made it to writer, only "4" did
    assertTrue(reader.getRead().contains("4"));
    assertFalse(writer.getCommitted().contains("4"));

    // failure on "4" tripped the skip limit so we never got to "5"
    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,3"));
    assertEquals(expectedOutput, writer.getCommitted());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here


    writer.setFailures("4");

    factory.setSkipLimit(3);
    factory.setSkippableExceptionClasses(getExceptionMap(Exception.class));

    Step step = factory.getObject();

    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());

    assertEquals(3, stepExecution.getSkipCount());
    assertEquals(2, stepExecution.getReadSkipCount());
    assertEquals(1, stepExecution.getWriteSkipCount());
    assertEquals(2, stepExecution.getReadCount());

    // writer did not skip "2" as it never made it to writer, only "4" did
    assertFalse(reader.getRead().contains("2"));
    assertTrue(reader.getRead().contains("4"));

    // only "1" was ever committed
    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1"));
    assertEquals(expectedOutput, writer.getCommitted());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

      }
    } });
    factory.setCommitInterval(2);
    factory.setSkipLimit(2);

    Step step = factory.getObject();

    step.execute(stepExecution);

    // 1,3 skipped inside a committed chunk. 5 tripped the skip
    // limit but it was skipped in a chunk that rolled back, so
    // it will re-appear on a restart and the listener is not called.
    assertEquals(2, listenerCalls.size());
View Full Code Here

        throw new RuntimeException("oops");
      }
    } });
    factory.setSkippableExceptionClasses(getExceptionMap(Exception.class));

    Step step = factory.getObject();

    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals("oops", stepExecution.getFailureExceptions().get(0).getCause().getMessage());

    // listeners are called only once chunk is about to commit, so
    // listener failure does not affect other statistics
    assertEquals(2, stepExecution.getReadSkipCount());
    // but we didn't get as far as the write skip in the scan:
    assertEquals(0, stepExecution.getWriteSkipCount());
    assertEquals(2, stepExecution.getSkipCount());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

        throw new RuntimeException("oops");
      }
    } });
    factory.setSkippableExceptionClasses(getExceptionMap(Exception.class));

    Step step = factory.getObject();

    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals("oops", stepExecution.getFailureExceptions().get(0).getCause().getMessage());
    assertEquals(1, stepExecution.getSkipCount());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(1, stepExecution.getWriteSkipCount());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

  }

  @Test
  public void testNoInputNoListeners() throws Exception{
    reader = new FailingListItemReader(new ArrayList<String>());
    Step step = builder.chunk(25).reader(reader).processor(processor).writer(writer).listener((ItemReadListener<String>) readListener).build();

    runStep(step);

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertEquals(0, processor.count);
View Full Code Here

    writer.setFailures("4");

    factory.setSkipLimit(4);

    Step step = factory.getObject();

    step.execute(stepExecution);
    assertEquals(4, stepExecution.getSkipCount());
    assertEquals(3, stepExecution.getReadSkipCount());
    assertEquals(1, stepExecution.getWriteSkipCount());

    // skipped 2,3,4,5
    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,6"));
    assertEquals(expectedOutput, writer.getCommitted());

    // reader exceptions should not cause rollback, 1 writer exception
    // causes 2 rollbacks
    assertEquals(2, stepExecution.getRollbackCount());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

    assertEquals(0, stepExecution.getWriteSkipCount());
  }

  @Test
  public void testSimpleScenarioNoListeners() throws Exception{
    Step step = builder.chunk(25).reader(reader).processor(processor).writer(writer).build();

    runStep(step);

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertEquals(0, stepExecution.getProcessSkipCount());
View Full Code Here

    }
  }

  @Test
  public void testSimpleScenarioNoProcessor() throws Exception{
    Step step = builder.chunk(25).reader(reader).writer(writer).listener((ItemReadListener<String>) readListener).build();

    runStep(step);

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertEquals(0, stepExecution.getProcessSkipCount());
View Full Code Here

  }

  @Test
  public void testProcessorFilteringNoListeners() throws Exception{
    processor.filter = true;
    Step step = builder.chunk(25).reader(reader).processor(processor).writer(writer).listener((ItemReadListener<String>) readListener).build();

    runStep(step);

    int count = 0;
    for (String curItem : writer.results) {
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.Step

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.