From be5bb78ae9e0d401af983b8ba8c6e6bbb610b43a Mon Sep 17 00:00:00 2001 From: dsyer Date: Thu, 28 Aug 2008 06:58:10 +0000 Subject: [PATCH] Add additional test for skip limit breach --- .../StatefulRetryStepFactoryBeanTests.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/StatefulRetryStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/StatefulRetryStepFactoryBeanTests.java index 40b17ac89..d5f2eb619 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/StatefulRetryStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/StatefulRetryStepFactoryBeanTests.java @@ -260,6 +260,45 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase { assertEquals(0, stepExecution.getItemCount().intValue()); } + public void testRetryWithSkipLimitBreach() throws Exception { + factory.setRetryLimit(0); + factory.setSkipLimit(2); + factory.setCommitInterval(3); + List items = TransactionAwareProxyFactory.createTransactionalList(); + items.addAll(Arrays.asList(new String[] { "a", "b", "c", "d", "e" })); + ItemReader provider = new ListItemReader(items) { + public Object read() { + Object item = super.read(); + count++; + return item; + } + }; + ItemWriter itemWriter = new AbstractItemWriter() { + public void write(Object item) throws Exception { + logger.debug("Write Called! Item: [" + item + "]"); + throw new RuntimeException("Write error - planned but retryable."); + } + }; + factory.setItemReader(provider); + factory.setItemWriter(itemWriter); + AbstractStep step = (AbstractStep) factory.getObject(); + + StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); + try { + step.execute(stepExecution); + fail("Expected SkipLimitExceededException"); + } + catch (SkipLimitExceededException e) { + // expected + } + + assertEquals(2, stepExecution.getSkipCount()); + // One chunk read twice + assertEquals(6, count); + // Crapped out after two skips + assertEquals(2, stepExecution.getItemCount().intValue()); + } + public void testRetryPolicy() throws Exception { factory.setRetryPolicy(new SimpleRetryPolicy(4)); factory.setSkipLimit(0);