diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java index 41e02112e..bc6ec6931 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java @@ -31,6 +31,7 @@ import org.springframework.batch.retry.policy.RecoveryCallbackRetryPolicy; import org.springframework.batch.retry.policy.SimpleRetryPolicy; import org.springframework.batch.retry.support.RetryTemplate; import org.springframework.batch.support.SubclassExceptionClassifier; +import org.springframework.util.Assert; /** * Factory bean for step that provides options for configuring skip behavior. @@ -63,7 +64,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { private int cacheCapacity = 0; - private int retryLimit = 0; + private int retryLimit = 1; private Class[] retryableExceptionClasses = new Class[] {}; @@ -86,11 +87,13 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { /** * Public setter for the retry limit. Each item can be retried up to this - * limit. + * limit. Note the limit includes the initial attempt, so it must be greater + * or equal to 1. * * @param retryLimit the retry limit to set */ public void setRetryLimit(int retryLimit) { + Assert.isTrue(retryLimit >= 1, "retry limit must be greater or equal to 1"); this.retryLimit = retryLimit; } @@ -199,7 +202,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { protected void applyConfiguration(ItemOrientedStep step) { super.applyConfiguration(step); - if (retryLimit > 0 || skipLimit > 0 || retryPolicy != null) { + if (retryLimit > 1 || skipLimit > 0 || retryPolicy != null) { addFatalExceptionIfMissing(SkipLimitExceededException.class); addFatalExceptionIfMissing(NonSkippableException.class); 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 4f5cccd3e..d55a58bf9 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 @@ -80,6 +80,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase { /* * (non-Javadoc) + * * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { @@ -141,8 +142,8 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase { StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); try { - step.execute(stepExecution); - fail(); + step.execute(stepExecution); + fail(); } catch (NonSkippableException expected) { assertEquals(0, stepExecution.getSkipCount()); @@ -152,7 +153,6 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase { assertEquals(1, stepExecution.getItemCount().intValue()); } - } public void testSkipAndRetry() throws Exception { @@ -268,7 +268,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase { } public void testRetryWithSkipLimitBreach() throws Exception { - factory.setRetryLimit(0); + factory.setRetryLimit(1); factory.setSkipLimit(2); factory.setCommitInterval(3); List items = TransactionAwareProxyFactory.createTransactionalList(); @@ -302,7 +302,7 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase { assertEquals(2, stepExecution.getSkipCount()); // One chunk read twice assertEquals(6, count); - // Crapped out after two skips + // Crapped out after two skips assertEquals(2, stepExecution.getItemCount().intValue()); }