List of usage examples for org.springframework.batch.core SkipListener onSkipInWrite
void onSkipInWrite(S item, Throwable t);
From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanNonBufferingTests.java
/** * Check items causing errors are skipped as expected. *///w w w . j a v a 2 s . c o m @Test public void testSkip() throws Exception { @SuppressWarnings("unchecked") SkipListener<Integer, String> skipListener = mock(SkipListener.class); skipListener.onSkipInWrite("3", exception); skipListener.onSkipInWrite("4", exception); factory.setListeners(new SkipListener[] { skipListener }); Step step = factory.getObject(); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals(2, stepExecution.getSkipCount()); assertEquals(0, stepExecution.getReadSkipCount()); assertEquals(2, stepExecution.getWriteSkipCount()); // only one exception caused rollback, and only once in this case // because all items in that chunk were skipped immediately assertEquals(1, stepExecution.getRollbackCount()); assertFalse(writer.written.contains("4")); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,5")); assertEquals(expectedOutput, writer.written); // 5 items + 1 rollbacks reading 2 items each time assertEquals(7, stepExecution.getReadCount()); }