OPEN - BATCH-847: FaultTolerantChunkOrientedTasklet loses chunks when non-skippable exceptions thrown in read phase

exception on read is rethrown as fatal, added logging for exceptions swallowed in SimpleRetryExceptionHandler
This commit is contained in:
robokaso
2008-09-24 10:08:08 +00:00
parent bc9cc55ba8
commit c6da8322df
4 changed files with 84 additions and 27 deletions

View File

@@ -72,6 +72,58 @@ public class SkipLimitStepFactoryBeanTests {
jobExecution = new JobExecution(jobInstance);
}
/**
* Non-skippable (and non-fatal) exception causes failure immediately.
* @throws Exception
*/
@Test
public void testNonSkippableExceptionOnRead() throws Exception {
// nothing is skippable
Collection<Class<? extends Throwable>> empty = Collections.emptySet();
factory.setSkippableExceptionClasses(empty);
// no exceptions on write
factory.setItemWriter(new ItemWriter<String>() {
public void write(List<? extends String> items) throws Exception {
logger.debug(items);
}
});
Step step = (Step) factory.getObject();
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
step.execute(stepExecution);
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
//assertEquals("Ouch!", stepExecution.getFailureExceptions().get(0).getMessage());
}
@Test
public void testNonSkippableException() throws Exception {
// nothing is skippable
Collection<Class<? extends Throwable>> empty = Collections.emptySet();
factory.setSkippableExceptionClasses(empty);
factory.setCommitInterval(1);
// no failures on read
reader = new SkipReaderStub(new String[] { "1", "2", "3", "4", "5" }, new ArrayList<String>());
factory.setItemReader(reader);
factory.setItemWriter(new ItemWriter<String>() {
public void write(List<? extends String> items) throws Exception {
throw new RuntimeException("non-skippable exception");
}
});
Step step = (Step) factory.getObject();
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
step.execute(stepExecution);
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
assertEquals(1, reader.processed.size());
}
/**
* Check items causing errors are skipped as expected.
*/
@@ -99,6 +151,7 @@ public class SkipLimitStepFactoryBeanTests {
assertEquals(expectedOutput, writer.written);
assertEquals(4, stepExecution.getReadCount());
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
}
@@ -195,7 +248,7 @@ public class SkipLimitStepFactoryBeanTests {
step.execute(stepExecution);
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
assertEquals(3, stepExecution.getSkipCount());
assertEquals(2, stepExecution.getReadSkipCount());
assertEquals(1, stepExecution.getWriteSkipCount());

View File

@@ -159,13 +159,13 @@ public class StatefulRetryStepFactoryBeanTests {
assertEquals(0, stepExecution.getSkipCount());
// [a, b, c, null]
assertEquals(4, provided.size());
// [a, c]
assertEquals(2, processed.size());
// [a, b with error]
assertEquals(2, provided.size());
// [a]
assertEquals(1, processed.size());
// []
assertEquals(0, recovered.size());
assertEquals(2, stepExecution.getReadCount());
assertEquals(1, stepExecution.getReadCount());
assertEquals(0, stepExecution.getReadSkipCount());
}