diff --git a/spring-batch-core/ivy.xml b/spring-batch-core/ivy.xml index 15dc75608..b838e6552 100644 --- a/spring-batch-core/ivy.xml +++ b/spring-batch-core/ivy.xml @@ -39,8 +39,10 @@ + + diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java index 23802f857..1600f8ba9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java @@ -25,7 +25,6 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.aop.framework.Advised; -import org.springframework.batch.classify.BinaryExceptionClassifier; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; @@ -58,15 +57,16 @@ import org.springframework.batch.item.ItemWriter; import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate; -import org.springframework.batch.retry.RetryListener; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.backoff.BackOffPolicy; -import org.springframework.batch.retry.policy.MapRetryContextCache; -import org.springframework.batch.retry.policy.RetryContextCache; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; +import org.springframework.classify.BinaryExceptionClassifier; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.TaskExecutor; +import org.springframework.retry.RetryListener; +import org.springframework.retry.RetryPolicy; +import org.springframework.retry.backoff.BackOffPolicy; +import org.springframework.retry.policy.MapRetryContextCache; +import org.springframework.retry.policy.RetryContextCache; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchRetryTemplate.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchRetryTemplate.java index f9641a31a..8e995f956 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchRetryTemplate.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchRetryTemplate.java @@ -21,21 +21,21 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryListener; -import org.springframework.batch.retry.RetryOperations; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.RetryState; -import org.springframework.batch.retry.backoff.BackOffPolicy; -import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.batch.retry.policy.RetryContextCache; -import org.springframework.batch.retry.support.DefaultRetryState; -import org.springframework.batch.retry.support.RetrySynchronizationManager; -import org.springframework.batch.retry.support.RetryTemplate; +import org.springframework.classify.Classifier; +import org.springframework.retry.ExhaustedRetryException; +import org.springframework.retry.RecoveryCallback; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryListener; +import org.springframework.retry.RetryOperations; +import org.springframework.retry.RetryPolicy; +import org.springframework.retry.RetryState; +import org.springframework.retry.backoff.BackOffPolicy; +import org.springframework.retry.context.RetryContextSupport; +import org.springframework.retry.policy.RetryContextCache; +import org.springframework.retry.support.DefaultRetryState; +import org.springframework.retry.support.RetrySynchronizationManager; +import org.springframework.retry.support.RetryTemplate; /** * A special purpose retry template that deals specifically with multi-valued diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java index 9b70190d8..608364cf5 100755 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java @@ -25,8 +25,8 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.batch.classify.BinaryExceptionClassifier; -import org.springframework.batch.classify.Classifier; +import org.springframework.classify.BinaryExceptionClassifier; +import org.springframework.classify.Classifier; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy; import org.springframework.batch.core.step.skip.NonSkippableProcessException; @@ -35,12 +35,12 @@ import org.springframework.batch.core.step.skip.SkipListenerFailedException; import org.springframework.batch.core.step.skip.SkipPolicy; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryException; -import org.springframework.batch.retry.support.DefaultRetryState; +import org.springframework.retry.ExhaustedRetryException; +import org.springframework.retry.RecoveryCallback; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryException; +import org.springframework.retry.support.DefaultRetryState; /** * FaultTolerant implementation of the {@link ChunkProcessor} interface, that diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProvider.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProvider.java index 7e6af16e6..e8fcf0e8a 100755 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProvider.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProvider.java @@ -16,8 +16,8 @@ package org.springframework.batch.core.step.item; -import org.springframework.batch.classify.BinaryExceptionClassifier; -import org.springframework.batch.classify.Classifier; +import org.springframework.classify.BinaryExceptionClassifier; +import org.springframework.classify.Classifier; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy; import org.springframework.batch.core.step.skip.NonSkippableReadException; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java index bcfb8fa3d..1b276d603 100755 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBean.java @@ -23,9 +23,9 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import org.springframework.batch.classify.BinaryExceptionClassifier; -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.classify.SubclassClassifier; +import org.springframework.classify.BinaryExceptionClassifier; +import org.springframework.classify.Classifier; +import org.springframework.classify.SubclassClassifier; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.Step; @@ -45,17 +45,17 @@ import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; import org.springframework.batch.repeat.RepeatOperations; import org.springframework.batch.repeat.support.RepeatTemplate; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RetryException; -import org.springframework.batch.retry.RetryListener; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.backoff.BackOffPolicy; -import org.springframework.batch.retry.policy.CompositeRetryPolicy; -import org.springframework.batch.retry.policy.ExceptionClassifierRetryPolicy; -import org.springframework.batch.retry.policy.MapRetryContextCache; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.policy.RetryContextCache; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; +import org.springframework.retry.ExhaustedRetryException; +import org.springframework.retry.RetryException; +import org.springframework.retry.RetryListener; +import org.springframework.retry.RetryPolicy; +import org.springframework.retry.backoff.BackOffPolicy; +import org.springframework.retry.policy.CompositeRetryPolicy; +import org.springframework.retry.policy.ExceptionClassifierRetryPolicy; +import org.springframework.retry.policy.MapRetryContextCache; +import org.springframework.retry.policy.NeverRetryPolicy; +import org.springframework.retry.policy.RetryContextCache; +import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.transaction.TransactionException; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java index d666ac20c..84cdd9b86 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java @@ -19,14 +19,14 @@ import java.util.Collection; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.Log; -import org.springframework.batch.classify.BinaryExceptionClassifier; +import org.springframework.classify.BinaryExceptionClassifier; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.exception.ExceptionHandler; import org.springframework.batch.repeat.support.RepeatSynchronizationManager; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.listener.RetryListenerSupport; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryPolicy; +import org.springframework.retry.listener.RetryListenerSupport; /** * An {@link ExceptionHandler} that is aware of the retry context so that it can diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/ExceptionClassifierSkipPolicy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/ExceptionClassifierSkipPolicy.java index 3f759138c..600324486 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/ExceptionClassifierSkipPolicy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/ExceptionClassifierSkipPolicy.java @@ -17,8 +17,8 @@ package org.springframework.batch.core.step.skip; import java.util.Map; -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.classify.SubclassClassifier; +import org.springframework.classify.Classifier; +import org.springframework.classify.SubclassClassifier; /** * A {@link SkipPolicy} that depends on an exception classifier to make its diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java index dc545976b..ce1ab2d29 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java @@ -19,8 +19,8 @@ import java.io.FileNotFoundException; import java.util.Collections; import java.util.Map; -import org.springframework.batch.classify.BinaryExceptionClassifier; -import org.springframework.batch.classify.Classifier; +import org.springframework.classify.BinaryExceptionClassifier; +import org.springframework.classify.Classifier; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.item.file.FlatFileParseException; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java index 33d2edc66..1662547dc 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/ChunkElementParserTests.java @@ -15,19 +15,27 @@ */ package org.springframework.batch.core.configuration.xml; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; + import org.junit.Test; -import org.springframework.batch.classify.SubclassClassifier; import org.springframework.batch.core.Step; import org.springframework.batch.core.step.item.SimpleChunkProcessor; import org.springframework.batch.core.step.skip.SkipPolicy; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.support.CompositeItemStream; -import org.springframework.batch.retry.RetryListener; -import org.springframework.batch.retry.listener.RetryListenerSupport; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; import org.springframework.beans.PropertyAccessorUtils; import org.springframework.beans.factory.BeanCreationException; +import org.springframework.classify.SubclassClassifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -36,20 +44,12 @@ import org.springframework.dao.CannotSerializeTransactionException; import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.DeadlockLoserDataAccessException; import org.springframework.dao.PessimisticLockingFailureException; +import org.springframework.retry.RetryListener; +import org.springframework.retry.listener.RetryListenerSupport; +import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.StringUtils; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - /** * @author Dan Garrette * @author Dave Syer diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyRetryListener.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyRetryListener.java index 9e813e730..90f092a27 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyRetryListener.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyRetryListener.java @@ -1,8 +1,8 @@ package org.springframework.batch.core.configuration.xml; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryListener; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryListener; /** * @author Dan Garrette diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java index 694d43ae7..744068aa4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBeanTests.java @@ -41,10 +41,10 @@ import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.file.FlatFileItemReader; import org.springframework.batch.item.support.PassThroughItemProcessor; import org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate; -import org.springframework.batch.retry.listener.RetryListenerSupport; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor; +import org.springframework.retry.listener.RetryListenerSupport; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java index b1a94a40e..5c1c1d829 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java @@ -38,8 +38,8 @@ import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.step.AbstractStep; -import org.springframework.batch.core.step.item.FatalSkippableException; import org.springframework.batch.core.step.item.FatalRuntimeException; +import org.springframework.batch.core.step.item.FatalSkippableException; import org.springframework.batch.core.step.item.ForceRollbackForWriteSkipException; import org.springframework.batch.core.step.item.SkippableException; import org.springframework.batch.core.step.item.SkippableRuntimeException; @@ -49,14 +49,14 @@ import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.support.CompositeItemStream; import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; -import org.springframework.batch.retry.RetryListener; -import org.springframework.batch.retry.listener.RetryListenerSupport; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.dao.DeadlockLoserDataAccessException; +import org.springframework.retry.RetryListener; +import org.springframework.retry.listener.RetryListenerSupport; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests.java index 6b00c7d4b..395404f31 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests.java @@ -28,9 +28,9 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepListener; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.retry.RetryListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.retry.RetryListener; import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestRetryListener.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestRetryListener.java index 29a3b4fe3..5a2c4b4b6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestRetryListener.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestRetryListener.java @@ -1,8 +1,8 @@ package org.springframework.batch.core.configuration.xml; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryListener; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryListener; public class TestRetryListener extends AbstractTestComponent implements RetryListener { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/BatchRetryTemplateTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/BatchRetryTemplateTests.java index 8812b6bf9..360b4e939 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/BatchRetryTemplateTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/BatchRetryTemplateTests.java @@ -10,13 +10,13 @@ import java.util.Collections; import java.util.List; import org.junit.Test; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryState; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; -import org.springframework.batch.retry.support.DefaultRetryState; +import org.springframework.retry.ExhaustedRetryException; +import org.springframework.retry.RecoveryCallback; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryState; +import org.springframework.retry.policy.SimpleRetryPolicy; +import org.springframework.retry.support.DefaultRetryState; public class BatchRetryTemplateTests { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessorTests.java index dac7a3d27..a08506083 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessorTests.java @@ -11,7 +11,6 @@ import java.util.List; import org.junit.Before; import org.junit.Test; -import org.springframework.batch.classify.BinaryExceptionClassifier; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; @@ -21,10 +20,11 @@ import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.PassThroughItemProcessor; -import org.springframework.batch.retry.RetryException; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; +import org.springframework.classify.BinaryExceptionClassifier; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.retry.RetryException; +import org.springframework.retry.policy.NeverRetryPolicy; +import org.springframework.retry.policy.SimpleRetryPolicy; public class FaultTolerantChunkProcessorTests { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java index 6a6c1091c..ec204823f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java @@ -52,10 +52,10 @@ import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader; import org.springframework.batch.item.support.ListItemReader; -import org.springframework.batch.retry.policy.MapRetryContextCache; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; +import org.springframework.retry.policy.MapRetryContextCache; +import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.StringUtils; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java index 1d2ca4564..75991dfac 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java @@ -24,10 +24,10 @@ import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; import org.springframework.batch.repeat.exception.SimpleLimitExceptionHandler; import org.springframework.batch.repeat.support.RepeatSynchronizationManager; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.policy.AlwaysRetryPolicy; -import org.springframework.batch.retry.policy.NeverRetryPolicy; +import org.springframework.retry.RetryContext; +import org.springframework.retry.RetryPolicy; +import org.springframework.retry.policy.AlwaysRetryPolicy; +import org.springframework.retry.policy.NeverRetryPolicy; /** * @author Dave Syer diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementLateBindingParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementLateBindingParserTests-context.xml index 4aa058fa1..41db9e3e9 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementLateBindingParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementLateBindingParserTests-context.xml @@ -19,7 +19,7 @@ - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementParentAttributeParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementParentAttributeParserTests-context.xml index d0a439238..cb5b6587c 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementParentAttributeParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementParentAttributeParserTests-context.xml @@ -101,7 +101,7 @@ - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml index 01b9e727c..54370499f 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ChunkElementRetryPolicyParserTests-context.xml @@ -15,7 +15,7 @@ - + @@ -24,16 +24,16 @@ - + - + - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentRetryableLateBindingStepFactoryBeanParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentRetryableLateBindingStepFactoryBeanParserTests-context.xml index 09c99d9f3..10a855335 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentRetryableLateBindingStepFactoryBeanParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentRetryableLateBindingStepFactoryBeanParserTests-context.xml @@ -21,7 +21,7 @@ - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml index 624f76564..c0877eba9 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/ParentStepFactoryBeanParserTests-context.xml @@ -7,16 +7,16 @@ - + - + - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml index a53e9a873..ecee1de40 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml @@ -162,7 +162,7 @@ - + diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java index fcab1f027..1c9daf5f2 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java @@ -34,12 +34,12 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.support.DefaultRetryState; -import org.springframework.batch.retry.support.RetryTemplate; +import org.springframework.retry.RecoveryCallback; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.policy.NeverRetryPolicy; +import org.springframework.retry.support.DefaultRetryState; +import org.springframework.retry.support.RetryTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java index 16cbc7ee4..d9f54c31f 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java @@ -35,15 +35,15 @@ import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatSynchronizationManager; import org.springframework.batch.repeat.support.RepeatTemplate; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; -import org.springframework.batch.retry.support.DefaultRetryState; -import org.springframework.batch.retry.support.RetryTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jms.core.JmsTemplate; +import org.springframework.retry.RecoveryCallback; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.policy.SimpleRetryPolicy; +import org.springframework.retry.support.DefaultRetryState; +import org.springframework.retry.support.RetryTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.PlatformTransactionManager; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java index e6c6c1d54..a7c076bee 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java @@ -30,14 +30,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.DefaultRetryState; -import org.springframework.batch.retry.support.RetryTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jms.core.JmsTemplate; +import org.springframework.retry.RecoveryCallback; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.support.DefaultRetryState; +import org.springframework.retry.support.RetryTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.PlatformTransactionManager; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java index aaacb8b44..ba1285270 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java @@ -31,12 +31,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.item.jms.JmsItemReader; import org.springframework.batch.jms.ExternalRetryInBatchTests; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.RetryTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jms.core.JmsTemplate; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; +import org.springframework.retry.support.RetryTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.AfterTransaction; diff --git a/spring-batch-infrastructure/ivy.xml b/spring-batch-infrastructure/ivy.xml index 5e12c6ce3..d3d974737 100644 --- a/spring-batch-infrastructure/ivy.xml +++ b/spring-batch-infrastructure/ivy.xml @@ -47,6 +47,7 @@ + diff --git a/spring-batch-infrastructure/pom.xml b/spring-batch-infrastructure/pom.xml index 369931b5c..e429bcf43 100644 --- a/spring-batch-infrastructure/pom.xml +++ b/spring-batch-infrastructure/pom.xml @@ -201,6 +201,10 @@ spring-orm true + + org.springframework.retry + spring-retry + org.springframework spring-test diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/BackToBackPatternClassifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/BackToBackPatternClassifier.java deleted file mode 100644 index a2cb385f5..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/BackToBackPatternClassifier.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import java.util.Map; - -/** - * A special purpose {@link Classifier} with easy configuration options for - * mapping from one arbitrary type of object to another via a pattern matcher. - * - * @author Dave Syer - * - */ -public class BackToBackPatternClassifier implements Classifier { - - private Classifier router; - - private Classifier matcher; - - /** - * Default constructor, provided as a convenience for people using setter - * injection. - */ - public BackToBackPatternClassifier() { - } - - /** - * Set up a classifier with input to the router and output from the matcher. - * - * @param router see {@link #setRouterDelegate(Object)} - * @param matcher see {@link #setMatcherMap(Map)} - */ - public BackToBackPatternClassifier(Classifier router, Classifier matcher) { - super(); - this.router = router; - this.matcher = matcher; - } - - /** - * A convenience method for creating a pattern matching classifier for the - * matcher component. - * - * @param map maps pattern keys with wildcards to output values - */ - public void setMatcherMap(Map map) { - this.matcher = new PatternMatchingClassifier(map); - } - - /** - * A convenience method of creating a router classifier based on a plain old - * Java Object. The object provided must have precisely one public method - * that either has the @Classifier annotation or accepts a single argument - * and outputs a String. This will be used to create an input classifier for - * the router component.
- * - * @param delegate the delegate object used to create a router classifier - */ - public void setRouterDelegate(Object delegate) { - this.router = new ClassifierAdapter(delegate); - } - - /** - * Classify the input and map to a String, then take that and put it into a - * pattern matcher to match to an output value. - */ - public T classify(C classifiable) { - return matcher.classify(router.classify(classifiable)); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/BinaryExceptionClassifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/BinaryExceptionClassifier.java deleted file mode 100644 index d206b80ff..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/BinaryExceptionClassifier.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -/** - * A {@link Classifier} for exceptions that has only two classes (true and - * false). Classifies objects according to their inheritance relation with the - * supplied types. If the object to be classified is one of the provided types, - * or is a subclass of one of the types, then the non-default value is returned - * (usually true). - * - * @see SubclassClassifier - * - * @author Dave Syer - * - */ -public class BinaryExceptionClassifier extends SubclassClassifier { - - /** - * Create a binary exception classifier with the provided default value. - * - * @param defaultValue defaults to false - */ - public BinaryExceptionClassifier(boolean defaultValue) { - super(defaultValue); - } - - /** - * Create a binary exception classifier with the provided classes and their - * subclasses. The mapped value for these exceptions will be the one - * provided (which will be the opposite of the default). - * - * @param value - */ - public BinaryExceptionClassifier(Collection> exceptionClasses, boolean value) { - this(!value); - if (exceptionClasses != null) { - Map, Boolean> map = new HashMap, Boolean>(); - for (Class type : exceptionClasses) { - map.put(type, !getDefault()); - } - setTypeMap(map); - } - } - - /** - * Create a binary exception classifier with the default value false and - * value mapping true for the provided classes and their subclasses. - */ - public BinaryExceptionClassifier(Collection> exceptionClasses) { - this(exceptionClasses, true); - } - - /** - * Create a binary exception classifier using the given classification map - * and a default classification of false. - * - * @param typeMap - */ - public BinaryExceptionClassifier(Map, Boolean> typeMap) { - this(typeMap, false); - } - - /** - * Create a binary exception classifier using the given classification map - * and a default classification of false. - * - * @param typeMap - */ - public BinaryExceptionClassifier(Map, Boolean> typeMap, boolean defaultValue) { - super(typeMap, defaultValue); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/Classifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/Classifier.java deleted file mode 100644 index 3b937b3c9..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/Classifier.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.classify; - -/** - * Interface for a classifier. At its simplest a {@link Classifier} is just a - * map from objects of one type to objects of another type. - * - * @author Dave Syer - * - */ -public interface Classifier { - - /** - * Classify the given object and return an object of a different type, - * possibly an enumerated type. - * - * @param classifiable the input object. Can be null. - * @return an object. Can be null, but implementations should declare if - * this is the case. - */ - T classify(C classifiable); - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/ClassifierAdapter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/ClassifierAdapter.java deleted file mode 100644 index 6eba544a3..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/ClassifierAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import org.springframework.batch.support.MethodInvoker; -import org.springframework.batch.support.MethodInvokerUtils; -import org.springframework.util.Assert; - -/** - * Wrapper for an object to adapt it to the {@link Classifier} interface. - * - * @author Dave Syer - * - */ -public class ClassifierAdapter implements Classifier { - - private MethodInvoker invoker; - - private Classifier classifier; - - /** - * Default constructor for use with setter injection. - */ - public ClassifierAdapter() { - super(); - } - - /** - * Create a new {@link Classifier} from the delegate provided. Use the - * constructor as an alternative to the {@link #setDelegate(Object)} method. - * - * @param delegate - */ - public ClassifierAdapter(Object delegate) { - setDelegate(delegate); - } - - /** - * Create a new {@link Classifier} from the delegate provided. Use the - * constructor as an alternative to the {@link #setDelegate(Classifier)} - * method. - * - * @param delegate - */ - public ClassifierAdapter(Classifier delegate) { - classifier = delegate; - } - - public void setDelegate(Classifier delegate) { - classifier = delegate; - invoker = null; - } - - /** - * Search for the - * {@link org.springframework.batch.support.annotation.Classifier - * Classifier} annotation on a method in the supplied delegate and use that - * to create a {@link Classifier} from the parameter type to the return - * type. If the annotation is not found a unique non-void method with a - * single parameter will be used, if it exists. The signature of the method - * cannot be checked here, so might be a runtime exception when the method - * is invoked if the signature doesn't match the classifier types. - * - * @param delegate an object with an annotated method - */ - public final void setDelegate(Object delegate) { - classifier = null; - invoker = MethodInvokerUtils.getMethodInvokerByAnnotation( - org.springframework.batch.support.annotation.Classifier.class, delegate); - if (invoker == null) { - invoker = MethodInvokerUtils. getMethodInvokerForSingleArgument(delegate); - } - Assert.state(invoker != null, "No single argument public method with or without " - + "@Classifier was found in delegate of type " + delegate.getClass()); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public T classify(C classifiable) { - if (classifier != null) { - return classifier.classify(classifiable); - } - return (T) invoker.invokeMethod(classifiable); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/ClassifierSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/ClassifierSupport.java deleted file mode 100644 index ad2926378..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/ClassifierSupport.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.classify; - -/** - * Base class for {@link Classifier} implementations. Provides default behaviour - * and some convenience members, like constants. - * - * @author Dave Syer - * - */ -public class ClassifierSupport implements Classifier { - - final private T defaultValue; - - /** - * @param defaultValue - */ - public ClassifierSupport(T defaultValue) { - super(); - this.defaultValue = defaultValue; - } - - /** - * Always returns the default value. This is the main extension point for - * subclasses, so it must be able to classify null. - * - * @see org.springframework.batch.classify.Classifier#classify(Object) - */ - public T classify(C throwable) { - return defaultValue; - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/PatternMatchingClassifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/PatternMatchingClassifier.java deleted file mode 100644 index 11d483517..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/PatternMatchingClassifier.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.batch.support.PatternMatcher; - -/** - * A {@link Classifier} that maps from String patterns with wildcards to a set - * of values of a given type. An input String is matched with the most specific - * pattern possible to the corresponding value in an input map. A default value - * should be specified with a pattern key of "*". - * - * @author Dave Syer - * - */ -public class PatternMatchingClassifier implements Classifier { - - private PatternMatcher values; - - /** - * Default constructor. Use the setter or the other constructor to create a - * sensible classifier, otherwise all inputs will cause an exception. - */ - public PatternMatchingClassifier() { - this(new HashMap()); - } - - /** - * Create a classifier from the provided map. The keys are patterns, using - * '?' as a single character and '*' as multi-character wildcard. - * - * @param values - */ - public PatternMatchingClassifier(Map values) { - super(); - this.values = new PatternMatcher(values); - } - - /** - * A map from pattern to value - * @param values the pattern map to set - */ - public void setPatternMap(Map values) { - this.values = new PatternMatcher(values); - } - - /** - * Classify the input by matching it against the patterns provided in - * {@link #setPatternMap(Map)}. The most specific pattern that matches will - * be used to locate a value. - * - * @return the value matching the most specific pattern possible - * - * @throws IllegalStateException if no matching value is found. - */ - public T classify(String classifiable) { - T value = values.match(classifiable); - return value; - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/SubclassClassifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/SubclassClassifier.java deleted file mode 100644 index ef2910d44..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/classify/SubclassClassifier.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import java.io.Serializable; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * A {@link Classifier} for a parameterised object type based on a map. - * Classifies objects according to their inheritance relation with the supplied - * type map. If the object to be classified is one of the keys of the provided - * map, or is a subclass of one of the keys, then the map entry value for that - * key is returned. Otherwise returns the default value which is null by - * default. - * - * @author Dave Syer - * - */ -public class SubclassClassifier implements Classifier { - - private ConcurrentMap, C> classified = new ConcurrentHashMap, C>(); - - private C defaultValue = null; - - /** - * Create a {@link SubclassClassifier} with null default value. - * - */ - public SubclassClassifier() { - this(null); - } - - /** - * Create a {@link SubclassClassifier} with supplied default value. - * - * @param defaultValue - */ - public SubclassClassifier(C defaultValue) { - this(new HashMap, C>(), defaultValue); - } - - /** - * Create a {@link SubclassClassifier} with supplied default value. - * - * @param defaultValue - */ - public SubclassClassifier(Map, C> typeMap, C defaultValue) { - super(); - this.classified = new ConcurrentHashMap, C>(typeMap); - this.defaultValue = defaultValue; - } - - /** - * Public setter for the default value for mapping keys that are not found - * in the map (or their subclasses). Defaults to false. - * - * @param defaultValue the default value to set - */ - public void setDefaultValue(C defaultValue) { - this.defaultValue = defaultValue; - } - - /** - * Set the classifications up as a map. The keys are types and these will be - * mapped along with all their subclasses to the corresponding value. The - * most specific types will match first. - * - * @param map a map from type to class - */ - public void setTypeMap(Map, C> map) { - this.classified = new ConcurrentHashMap, C>(map); - } - - /** - * Return the value from the type map whose key is the class of the given - * Throwable, or its nearest ancestor if a subclass. - * - */ - public C classify(T classifiable) { - - if (classifiable == null) { - return defaultValue; - } - - @SuppressWarnings("unchecked") - Class exceptionClass = (Class) classifiable.getClass(); - if (classified.containsKey(exceptionClass)) { - return classified.get(exceptionClass); - } - - // check for subclasses - Set> classes = new TreeSet>(new ClassComparator()); - classes.addAll(classified.keySet()); - for (Class cls : classes) { - if (cls.isAssignableFrom(exceptionClass)) { - C value = classified.get(cls); - this.classified.put(exceptionClass, value); - return value; - } - } - - return defaultValue; - } - - /** - * Return the default value supplied in the constructor (default false). - */ - final public C getDefault() { - return defaultValue; - } - - /** - * Comparator for classes to order by inheritance. - * - * @author Dave Syer - * - */ - private static class ClassComparator implements Comparator>, Serializable { - /** - * @return 1 if arg0 is assignable from arg1, -1 otherwise - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(Class arg0, Class arg1) { - if (arg0.isAssignableFrom(arg1)) { - return 1; - } - return -1; - } - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java index dff7e575b..b7c099d55 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java @@ -20,7 +20,7 @@ import javax.jms.JMSException; import javax.jms.Message; import org.springframework.batch.item.UnexpectedInputException; -import org.springframework.batch.retry.interceptor.MethodArgumentsKeyGenerator; +import org.springframework.retry.interceptor.MethodArgumentsKeyGenerator; /** * A {@link MethodArgumentsKeyGenerator} for JMS @@ -34,7 +34,7 @@ public class JmsMethodArgumentsKeyGenerator implements MethodArgumentsKeyGenerat * If the message is a {@link Message} then returns the JMS message ID. * Otherwise just return the first argument. * - * @see org.springframework.batch.retry.interceptor.MethodArgumentsKeyGenerator#getKey(Object[]) + * @see org.springframework.retry.interceptor.MethodArgumentsKeyGenerator#getKey(Object[]) * * @throws UnexpectedInputException if the JMS id cannot be determined from * a JMS Message diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java index 836259757..03c087d0b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java @@ -17,7 +17,7 @@ package org.springframework.batch.item.jms; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.batch.retry.interceptor.MethodInvocationRecoverer; +import org.springframework.retry.interceptor.MethodInvocationRecoverer; import org.springframework.jms.JmsException; import org.springframework.jms.core.JmsOperations; @@ -44,7 +44,7 @@ public class JmsMethodInvocationRecoverer implements MethodInvocationRecovere * Send one message per item in the arguments list using the default destination of * the jms template. If the recovery is successful null is returned. * - * @see org.springframework.batch.retry.interceptor.MethodInvocationRecoverer#recover(Object[], + * @see org.springframework.retry.interceptor.MethodInvocationRecoverer#recover(Object[], * Throwable) */ public T recover(Object[] items, Throwable cause) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java index eb37701f4..2cfb61a87 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java @@ -20,7 +20,7 @@ import javax.jms.JMSException; import javax.jms.Message; import org.springframework.batch.item.UnexpectedInputException; -import org.springframework.batch.retry.interceptor.NewMethodArgumentsIdentifier; +import org.springframework.retry.interceptor.NewMethodArgumentsIdentifier; /** * A {@link NewMethodArgumentsIdentifier} for JMS that looks for a message in @@ -35,7 +35,7 @@ public class JmsNewMethodArgumentsIdentifier implements NewMethodArgumentsIde * If any of the arguments is a message, check the JMS re-delivered flag and * return it, otherwise return false to be on the safe side. * - * @see org.springframework.batch.retry.interceptor.NewMethodArgumentsIdentifier#isNew(java.lang.Object[]) + * @see org.springframework.retry.interceptor.NewMethodArgumentsIdentifier#isNew(java.lang.Object[]) */ public boolean isNew(Object[] args) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java index 44688e254..a3fa648c7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java @@ -21,8 +21,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.classify.ClassifierSupport; +import org.springframework.classify.Classifier; +import org.springframework.classify.ClassifierSupport; import org.springframework.batch.item.ItemWriter; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java index 0ede464a4..f50997f4e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java @@ -18,8 +18,8 @@ package org.springframework.batch.repeat.exception; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.classify.ClassifierSupport; +import org.springframework.classify.Classifier; +import org.springframework.classify.ClassifierSupport; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatException; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java index 521daefdd..8ffe0e0b7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java @@ -22,8 +22,8 @@ import java.util.Map.Entry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.classify.SubclassClassifier; +import org.springframework.classify.Classifier; +import org.springframework.classify.SubclassClassifier; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextCounter; import org.springframework.util.ObjectUtils; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/ExhaustedRetryException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/ExhaustedRetryException.java deleted file mode 100644 index 82c658114..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/ExhaustedRetryException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -public class ExhaustedRetryException extends RetryException { - - public ExhaustedRetryException(String msg, Throwable cause) { - super(msg, cause); - } - - public ExhaustedRetryException(String msg) { - super(msg); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RecoveryCallback.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RecoveryCallback.java deleted file mode 100644 index 27ce5b00a..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RecoveryCallback.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry; - -/** - * Callback for stateful retry after all tries are exhausted. - * - * @author Dave Syer - * - * @since 1.1 - */ -public interface RecoveryCallback { - - /** - * @param context the current retry context - * @return an Object that can be used to replace the callback result that - * failed - * @throws Exception - */ - T recover(RetryContext context) throws Exception; - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryCallback.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryCallback.java deleted file mode 100644 index 88d863517..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryCallback.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -/** - * Callback interface for an operation that can be retried using a - * {@link RetryOperations}. - * - * @author Rob Harrop - * @author Dave Syer - */ -public interface RetryCallback { - - /** - * Execute an operation with retry semantics. Operations should generally be - * idempotent, but implementations may choose to implement compensation - * semantics when an operation is retried. - * @param context the current retry context. - * @return the result of the successful operation. - * @throws Exception if processing fails - */ - T doWithRetry(RetryContext context) throws Exception; -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryContext.java deleted file mode 100644 index 8242aa027..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryContext.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import org.springframework.core.AttributeAccessor; - -/** - * Low-level access to ongoing retry operation. Normally not needed by clients, - * but can be used to alter the course of the retry, e.g. force an early - * termination. - * - * @author Dave Syer - * - */ -public interface RetryContext extends AttributeAccessor { - - /** - * Signal to the framework that no more attempts should be made to try or - * retry the current {@link RetryCallback}. - */ - void setExhaustedOnly(); - - /** - * Public accessor for the exhausted flag {@link #setExhaustedOnly()}. - * - * @return true if the flag has been set. - */ - boolean isExhaustedOnly(); - - /** - * Accessor for the parent context if retry blocks are nested. - * - * @return the parent or null if there is none. - */ - RetryContext getParent(); - - /** - * Counts the number of retry attempts. Before the first attempt this - * counter is zero, and before the first and subsequent attempts it should - * increment accordingly. - * - * @return the number of retries. - */ - int getRetryCount(); - - /** - * Accessor for the exception object that caused the current retry. - * - * @return the last exception that caused a retry, or possibly null. It will - * be null if this is the first attempt, but also if the enclosing policy - * decides not to provide it (e.g. because of concerns about memory usage). - */ - Throwable getLastThrowable(); - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryException.java deleted file mode 100644 index 8f436f629..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import org.springframework.core.NestedRuntimeException; - -public class RetryException extends NestedRuntimeException { - - public RetryException(String msg, Throwable cause) { - super(msg, cause); - } - - public RetryException(String msg) { - super(msg); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryListener.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryListener.java deleted file mode 100644 index 0eceaff0a..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryListener.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - - -/** - * Interface for listener that can be used to add behaviour to a retry. - * Implementations of {@link RetryOperations} can chose to issue callbacks to an - * interceptor during the retry lifecycle. - * - * @author Dave Syer - * - */ -public interface RetryListener { - - /** - * Called before the first attempt in a retry. For instance, implementers - * can set up state that is needed by the policies in the - * {@link RetryOperations}. The whole retry can be vetoed by returning - * false from this method, in which case a {@link TerminatedRetryException} - * will be thrown. - * - * @param context the current {@link RetryContext}. - * @param callback the current {@link RetryCallback}. - * @return true if the retry should proceed. - */ - boolean open(RetryContext context, RetryCallback callback); - - /** - * Called after the final attempt (successful or not). Allow the interceptor - * to clean up any resource it is holding before control returns to the - * retry caller. - * - * @param context the current {@link RetryContext}. - * @param callback the current {@link RetryCallback}. - * @param throwable the last exception that was thrown by the callback. - */ - void close(RetryContext context, RetryCallback callback, Throwable throwable); - - /** - * Called after every unsuccessful attempt at a retry. - * - * @param context the current {@link RetryContext}. - * @param callback the current {@link RetryCallback}. - * @param throwable the last exception that was thrown by the callback. - */ - void onError(RetryContext context, RetryCallback callback, Throwable throwable); -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryOperations.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryOperations.java deleted file mode 100644 index 158987dcd..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryOperations.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import org.springframework.batch.retry.support.DefaultRetryState; - -/** - * Defines the basic set of operations implemented by {@link RetryOperations} to - * execute operations with configurable retry behaviour. - * - * @author Rob Harrop - * @author Dave Syer - */ -public interface RetryOperations { - - /** - * Execute the supplied {@link RetryCallback} with the configured retry - * semantics. See implementations for configuration details. - * - * @return the value returned by the {@link RetryCallback} upon successful - * invocation. - * @throws Exception any {@link Exception} raised by the - * {@link RetryCallback} upon unsuccessful retry. - */ - T execute(RetryCallback retryCallback) throws Exception; - - /** - * Execute the supplied {@link RetryCallback} with a fallback on exhausted - * retry to the {@link RecoveryCallback}. See implementations for - * configuration details. - * - * @return the value returned by the {@link RetryCallback} upon successful - * invocation, and that returned by the {@link RecoveryCallback} otherwise. - * @throws Exception any {@link Exception} raised by the - * {@link RecoveryCallback} upon unsuccessful retry. - */ - T execute(RetryCallback retryCallback, RecoveryCallback recoveryCallback) throws Exception; - - /** - * A simple stateful retry. Execute the supplied {@link RetryCallback} with - * a target object for the attempt identified by the {@link DefaultRetryState}. - * Exceptions thrown by the callback are always propagated immediately so - * the state is required to be able to identify the previous attempt, if - * there is one - hence the state is required. Normal patterns would see - * this method being used inside a transaction, where the callback might - * invalidate the transaction if it fails.

- * - * See implementations for configuration details. - * - * @return the value returned by the {@link RetryCallback} upon successful - * invocation, and that returned by the {@link RecoveryCallback} otherwise. - * @throws Exception any {@link Exception} raised by the - * {@link RecoveryCallback}. - * @throws ExhaustedRetryException if the last attempt for this state has - * already been reached - */ - T execute(RetryCallback retryCallback, RetryState retryState) throws Exception, ExhaustedRetryException; - - /** - * A stateful retry with a recovery path. Execute the supplied - * {@link RetryCallback} with a fallback on exhausted retry to the - * {@link RecoveryCallback} and a target object for the retry attempt - * identified by the {@link DefaultRetryState}. - * - * @see #execute(RetryCallback, RetryState) - * - * @return the value returned by the {@link RetryCallback} upon successful - * invocation, and that returned by the {@link RecoveryCallback} otherwise. - * @throws Exception any {@link Exception} raised by the - * {@link RecoveryCallback} upon unsuccessful retry. - */ - T execute(RetryCallback retryCallback, RecoveryCallback recoveryCallback, RetryState retryState) - throws Exception; - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryPolicy.java deleted file mode 100644 index c22b17216..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryPolicy.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -/** - * A {@link RetryPolicy} is responsible for allocating and managing resources - * needed by {@link RetryOperations}. The {@link RetryPolicy} allows retry - * operations to be aware of their context. Context can be internal to the retry - * framework, e.g. to support nested retries. Context can also be external, and - * the {@link RetryPolicy} provides a uniform API for a range of different - * platforms for the external context. - * - * @author Dave Syer - * - */ -public interface RetryPolicy { - - /** - * @param context the current retry status - * @return true if the operation can proceed - */ - boolean canRetry(RetryContext context); - - /** - * Acquire resources needed for the retry operation. The callback is passed - * in so that marker interfaces can be used and a manager can collaborate - * with the callback to set up some state in the status token. - * @param parent the parent context if we are in a nested retry. - * - * @return a {@link RetryContext} object specific to this manager. - * - */ - RetryContext open(RetryContext parent); - - /** - * @param context a retry status created by the - * {@link #open(RetryContext)} method of this manager. - */ - void close(RetryContext context); - - /** - * Called once per retry attempt, after the callback fails. - * - * @param context the current status object. - * - */ - void registerThrowable(RetryContext context, Throwable throwable); - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryState.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryState.java deleted file mode 100644 index 0dee88f99..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryState.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry; - -/** - * Stateful retry is characterised by having to recognise the items that are - * being processed, so this interface is used primarily to provide a cache key in - * between failed attempts. It also provides a hints to the - * {@link RetryOperations} for optimisations to do with avoidable cache hits and - * switching to stateless retry if a rollback is not needed. - * - * @author Dave Syer - * - */ -public interface RetryState { - - /** - * Key representing the state for a retry attempt. Stateful retry is - * characterised by having to recognise the items that are being processed, - * so this value is used as a cache key in between failed attempts. - * - * @return the key that this state represents - */ - Object getKey(); - - /** - * Indicate whether a cache lookup can be avoided. If the key is known ahead - * of the retry attempt to be fresh (i.e. has never been seen before) then a - * cache lookup can be avoided if this flag is true. - * - * @return true if the state does not require an explicit check for the key - */ - boolean isForceRefresh(); - - /** - * Check whether this exception requires a rollback. The default is always - * true, which is conservative, so this method provides an optimisation for - * switching to stateless retry if there is an exception for which rollback - * is unnecessary. Example usage would be for a stateful retry to specify a - * validation exception as not for rollback. - * - * @param exception the exception that caused a retry attempt to fail - * @return true if this exception should cause a rollback - */ - boolean rollbackFor(Throwable exception); - -} \ No newline at end of file diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryStatistics.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryStatistics.java deleted file mode 100644 index caf352a80..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/RetryStatistics.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -/** - * Interface for statistics reporting of retry attempts. Counts the number of - * retry attempts, successes, errors (including retries), and aborts. - * - * @author Dave Syer - * - */ -public interface RetryStatistics { - - /** - * @return the number of completed retry attempts (successful or not). - */ - int getCompleteCount(); - - /** - * Get the number of times a retry block has been entered, irrespective of - * how many times the operation was retried. - * - * @return the number of retry blocks started. - */ - int getStartedCount(); - - /** - * Get the number of errors detected, whether or not they resulted in a - * retry. - * - * @return the number of errors detected. - */ - int getErrorCount(); - - /** - * Get the number of times a block failed to complete successfully, even - * after retry. - * - * @return the number of retry attempts that failed overall. - */ - int getAbortCount(); - - /** - * Get an identifier for the retry block for reporting purposes. - * - * @return an identifier for the block. - */ - String getName(); - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/TerminatedRetryException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/TerminatedRetryException.java deleted file mode 100644 index 65d376ec0..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/TerminatedRetryException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -public class TerminatedRetryException extends RetryException { - - public TerminatedRetryException(String msg, Throwable cause) { - super(msg, cause); - } - - public TerminatedRetryException(String msg) { - super(msg); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffContext.java deleted file mode 100644 index 3a070f46b..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffContext.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -/** - * @author Rob Harrop - * @since 2.1 - */ -public interface BackOffContext { - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffInterruptedException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffInterruptedException.java deleted file mode 100644 index 7b43d1d24..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffInterruptedException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -import org.springframework.batch.retry.RetryException; - -/** - * Exception class signifiying that an attempt to back off using a - * {@link BackOffPolicy} was interrupted, most likely by an - * {@link InterruptedException} during a call to {@link Thread#sleep(long)}. - * - * @author Rob Harrop - * @since 2.1 - */ -public class BackOffInterruptedException extends RetryException { - - public BackOffInterruptedException(String msg) { - super(msg); - } - - public BackOffInterruptedException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffPolicy.java deleted file mode 100644 index 980a82583..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/BackOffPolicy.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -import org.springframework.batch.retry.RetryContext; - -/** - * Strategy interface to control back off between attempts in a single - * {@link org.springframework.batch.retry.support.RetryTemplate retry operation}. - *

Implementations are expected to be thread-safe and should be designed - * for concurrent access. Configuration for each implementation is also expected - * to be thread-safe but need not be suitable for high load concurrent access. - *

For each block of retry operations the {@link #start} method is called - * and implementations can return an implementation-specific - * {@link BackOffContext} that can be used to track state through subsequent - * back off invocations.

Each back off process is handled via a call to - * {@link #backOff}. The - * {@link org.springframework.batch.retry.support.RetryTemplate} will pass in - * the corresponding {@link BackOffContext} object created by the call to - * {@link #start}. - * - * @author Rob Harrop - * @author Dave Syer - */ -public interface BackOffPolicy { - - /** - * Start a new block of back off operations. Implementations can choose to - * pause when this method is called, but normally it returns immediately. - * - * @param context the current retry context, which might contain information - * that we can use to decide how to proceed. - * @return the implementation-specific {@link BackOffContext} or 'null'. - */ - BackOffContext start(RetryContext context); - - /** - * Back off/pause in an implementation-specific fashion. The passed in - * {@link BackOffContext} corresponds to the one created by the call to - * {@link #start} for a given retry operation set. - * - * @throws BackOffInterruptedException if the attempt at back off is - * interrupted. - */ - void backOff(BackOffContext backOffContext) throws BackOffInterruptedException; - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicy.java deleted file mode 100644 index 594d2dafe..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicy.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -import org.springframework.batch.retry.RetryContext; -import org.springframework.util.ClassUtils; - -/** - * Implementation of {@link BackOffPolicy} that increases the back off period - * for each retry attempt in a given set using the {@link Math#exp(double) - * exponential} function. - *

- * This implementation is thread-safe and suitable for concurrent access. - * Modifications to the configuration do not affect any retry sets that are - * already in progress. - *

- * The {@link #setInitialInterval(long)} property controls the initial value - * passed to {@link Math#exp(double)} and the {@link #setMultiplier(double)} - * property controls by how much this value is increased for each subsequent - * attempt. - * - * @author Rob Harrop - * @author Dave Syer - */ -public class ExponentialBackOffPolicy implements BackOffPolicy { - - /** - * The default 'initialInterval' value - 100 millisecs. Coupled with the - * default 'multiplier' value this gives a useful initial spread of pauses - * for 1-5 retries. - */ - public static final long DEFAULT_INITIAL_INTERVAL = 100L; - - /** - * The default maximum backoff time (30 seconds). - */ - public static final long DEFAULT_MAX_INTERVAL = 30000L; - - /** - * The default 'multiplier' value - value 2 (100% increase per backoff). - */ - public static final double DEFAULT_MULTIPLIER = 2; - - /** - * The initial sleep interval. - */ - private volatile long initialInterval = DEFAULT_INITIAL_INTERVAL; - - /** - * The maximum value of the backoff period in milliseconds. - */ - private volatile long maxInterval = DEFAULT_MAX_INTERVAL; - - /** - * The value to increment the exp seed with for each retry attempt. - */ - private volatile double multiplier = DEFAULT_MULTIPLIER; - - private Sleeper sleeper = new ObjectWaitSleeper(); - - /** - * Public setter for the {@link Sleeper} strategy. - * @param sleeper the sleeper to set defaults to {@link ObjectWaitSleeper}. - */ - public void setSleeper(Sleeper sleeper) { - this.sleeper = sleeper; - } - - /** - * Set the initial sleep interval value. Default is 100 - * millisecond. Cannot be set to a value less than one. - */ - public void setInitialInterval(long initialInterval) { - this.initialInterval = (initialInterval > 1 ? initialInterval : 1); - } - - /** - * Set the multiplier value. Default is '2.0'. Hint: do not use - * values much in excess of 1.0 (or the backoff will get very long very - * fast). - */ - public void setMultiplier(double multiplier) { - this.multiplier = (multiplier > 1.0 ? multiplier : 1.0); - } - - /** - * Setter for maximum back off period. Default is 30000 (30 seconds). the - * value will be reset to 1 if this method is called with a value less than - * 1. Set this to avoid infinite waits if backing off a large number of - * times (or if the multiplier is set too high). - * - * @param maxInterval in milliseconds. - */ - public void setMaxInterval(long maxInterval) { - this.maxInterval = maxInterval > 0 ? maxInterval : 1; - } - - /** - * The initial period to sleep on the first backoff. - * @return the initial interval - */ - public long getInitialInterval() { - return initialInterval; - } - - /** - * The maximum interval to sleep for. Defaults to 30 seconds. - * - * @return the maximum interval. - */ - public long getMaxInterval() { - return maxInterval; - } - - /** - * The multiplier to use to generate the next backoff interval from the - * last. - * - * @return the multiplier in use - */ - public double getMultiplier() { - return multiplier; - } - - /** - * Returns a new instance of {@link BackOffContext} configured with the - * 'expSeed' and 'increment' values. - */ - public BackOffContext start(RetryContext context) { - return new ExponentialBackOffContext(this.initialInterval, this.multiplier, this.maxInterval); - } - - /** - * Pause for a length of time equal to ' - * exp(backOffContext.expSeed)'. - */ - public void backOff(BackOffContext backOffContext) throws BackOffInterruptedException { - ExponentialBackOffContext context = (ExponentialBackOffContext) backOffContext; - try { - sleeper.sleep(context.getSleepAndIncrement()); - } - catch (InterruptedException e) { - throw new BackOffInterruptedException("Thread interrupted while sleeping", e); - } - } - - private static class ExponentialBackOffContext implements BackOffContext { - - private final double multiplier; - - private long interval; - - private long maxInterval; - - public ExponentialBackOffContext(long expSeed, double multiplier, long maxInterval) { - this.interval = expSeed; - this.multiplier = multiplier; - this.maxInterval = maxInterval; - } - - public synchronized long getSleepAndIncrement() { - long sleep = this.interval; - if (sleep > maxInterval) { - sleep = (long) maxInterval; - } - else { - this.interval *= this.multiplier; - } - return sleep; - } - } - - public String toString() { - return ClassUtils.getShortName(getClass()) + "[initialInterval=" + initialInterval + ", multiplier=" - + multiplier + ", maxInterval=" + maxInterval + "]"; - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/FixedBackOffPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/FixedBackOffPolicy.java deleted file mode 100644 index cfdd0eb05..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/FixedBackOffPolicy.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - - -/** - * Implementation of {@link BackOffPolicy} that pauses for a fixed period of - * time before continuing. A pause is implemented using {@link Thread#sleep(long)}. - *

{@link #setBackOffPeriod(long)} is thread-safe and it is safe to call - * {@link #setBackOffPeriod} during execution from multiple threads, however - * this may cause a single retry operation to have pauses of different - * intervals. - * @author Rob Harrop - * @author Dave Syer - */ -public class FixedBackOffPolicy extends StatelessBackOffPolicy { - - /** - * Default back off period - 1000ms. - */ - private static final long DEFAULT_BACK_OFF_PERIOD = 1000L; - - /** - * The back off period in milliseconds. Defaults to 1000ms. - */ - private volatile long backOffPeriod = DEFAULT_BACK_OFF_PERIOD; - - - private Sleeper sleeper = new ObjectWaitSleeper(); - - /** - * Public setter for the {@link Sleeper} strategy. - * @param sleeper the sleeper to set defaults to {@link ObjectWaitSleeper}. - */ - public void setSleeper(Sleeper sleeper) { - this.sleeper = sleeper; - } - - /** - * Set the back off period in milliseconds. Cannot be < 1. Default value - * is 1000ms. - */ - public void setBackOffPeriod(long backOffPeriod) { - this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1); - } - - /** - * The backoff period in milliseconds. - * @return the backoff period - */ - public long getBackOffPeriod() { - return backOffPeriod; - } - - /** - * Pause for the {@link #setBackOffPeriod(long)}. - * @throws BackOffInterruptedException if interrupted during sleep. - */ - protected void doBackOff() throws BackOffInterruptedException { - try { - sleeper.sleep(backOffPeriod); - } - catch (InterruptedException e) { - throw new BackOffInterruptedException("Thread interrupted while sleeping", e); - } - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/NoBackOffPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/NoBackOffPolicy.java deleted file mode 100644 index ae85ccc2f..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/NoBackOffPolicy.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - - -/** - * Implementation of {@link BackOffPolicy} that performs a no-op and as such all - * retry operation in a given set proceed one after the other with no pause. - * - * @author Rob Harrop - * @since 2.1 - */ -public class NoBackOffPolicy extends StatelessBackOffPolicy { - - protected void doBackOff() throws BackOffInterruptedException { - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ObjectWaitSleeper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ObjectWaitSleeper.java deleted file mode 100644 index 254b43a67..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/ObjectWaitSleeper.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.backoff; - -/** - * Simple {@link Sleeper} implementation that just waits on a local Object. - * - * @author Dave Syer - * - */ -public class ObjectWaitSleeper implements Sleeper { - - /* - * (non-Javadoc) - * @see org.springframework.batch.retry.backoff.Sleeper#sleep(long) - */ - public void sleep(long backOffPeriod) throws InterruptedException { - Object mutex = new Object(); - synchronized (mutex) { - mutex.wait(backOffPeriod); - } - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/Sleeper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/Sleeper.java deleted file mode 100644 index d547b4163..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/Sleeper.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.backoff; - -/** - * Strategy interface for backoff policies to delegate the pausing of execution. - * - * @author Dave Syer - * - */ -public interface Sleeper { - - /** - * Pause for the specified period using whatever means available. - * - * @param backOffPeriod - */ - void sleep(long backOffPeriod) throws InterruptedException; - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/StatelessBackOffPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/StatelessBackOffPolicy.java deleted file mode 100644 index 836459e74..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/StatelessBackOffPolicy.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -import org.springframework.batch.retry.RetryContext; - -/** - * Simple base class for {@link BackOffPolicy} implementations that maintain no - * state across invocations. - * - * @author Rob Harrop - * @author Dave Syer - */ -public abstract class StatelessBackOffPolicy implements BackOffPolicy { - - /** - * Delegates directly to the {@link #doBackOff()} method without passing on - * the {@link BackOffContext} argument which is not needed for stateless - * implementations. - */ - public final void backOff(BackOffContext backOffContext) throws BackOffInterruptedException { - doBackOff(); - } - - /** - * Returns 'null'. Subclasses can add behaviour, e.g. - * initial sleep before first attempt. - */ - public BackOffContext start(RetryContext status) { - return null; - } - - /** - * Sub-classes should implement this method to perform the actual back off. - */ - protected abstract void doBackOff() throws BackOffInterruptedException; -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/package.html b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/package.html deleted file mode 100644 index 53837ce90..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/backoff/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Infrastructure implementations of retry backoff concerns. -

- - diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/context/RetryContextSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/context/RetryContextSupport.java deleted file mode 100644 index 321c67ee5..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/context/RetryContextSupport.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.context; - -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.core.AttributeAccessorSupport; - -public class RetryContextSupport extends AttributeAccessorSupport implements RetryContext { - - private boolean terminate = false; - - private int count; - - private Throwable lastException; - - private RetryContext parent; - - public RetryContextSupport(RetryContext parent) { - super(); - this.parent = parent; - } - - public RetryContext getParent() { - return this.parent; - } - - public boolean isExhaustedOnly() { - return terminate; - } - - public void setExhaustedOnly() { - terminate = true; - } - - public int getRetryCount() { - return count; - } - - public Throwable getLastThrowable() { - return lastException; - } - - /** - * Set the exception for the public interface {@link RetryContext}, and - * also increment the retry count if the throwable is non-null.
- * - * All {@link RetryPolicy} implementations should use this method when they - * register the throwable. It should only be called once per retry attempt - * because it increments a counter.
- * - * Use of this method is not enforced by the framework - it is a service - * provider contract for authors of policies. - * - * @param throwable the exception that caused the current retry attempt to - * fail. - */ - public void registerThrowable(Throwable throwable) { - this.lastException = throwable; - if (throwable != null) - count++; - } - - @Override - public String toString() { - return String.format("[RetryContext: count=%d, lastException=%s, exhausted=%b]", count, lastException, terminate); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/context/package.html b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/context/package.html deleted file mode 100644 index d27756320..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/context/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Infrastructure implementations of retry context concerns. -

- - diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/MethodArgumentsKeyGenerator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/MethodArgumentsKeyGenerator.java deleted file mode 100644 index ddbae85c6..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/MethodArgumentsKeyGenerator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.interceptor; - -/** - * Interface that allows method parameters to be identified and tagged by a - * unique key. - * - * @author Dave Syer - * - */ -public interface MethodArgumentsKeyGenerator { - - /** - * Get a unique identifier for the item that can be used to cache it between - * calls if necessary, and then identify it later. - * - * @param item the current item. - * @return a unique identifier. - */ - Object getKey(Object[] item); - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/MethodInvocationRecoverer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/MethodInvocationRecoverer.java deleted file mode 100644 index cbc16ca44..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/MethodInvocationRecoverer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.interceptor; - - -/** - * Strategy interface for recovery action when processing of an item fails.
- * - * @author Dave Syer - */ -public interface MethodInvocationRecoverer { - - /** - * Recover gracefully from an error. Clients can call this if processing of - * the item throws an unexpected exception. Caller can use the return value - * to decide whether to try more corrective action or perhaps throw an - * exception. - * - * @param args - * the arguments for the method invocation that failed. - * @param cause - * the cause of the failure that led to this recovery. - * @return the value to be returned to the caller - */ - T recover(Object[] args, Throwable cause); -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/NewMethodArgumentsIdentifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/NewMethodArgumentsIdentifier.java deleted file mode 100644 index 86548dcfd..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/NewMethodArgumentsIdentifier.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.interceptor; - -/** - * Strategy interface to distinguish new arguments from ones that have been - * processed before, e.g. by examining a message flag. - * - * @author Dave Syer - * - */ -public interface NewMethodArgumentsIdentifier { - - /** - * Inspect the arguments and determine if they have never been processed - * before. The safest choice when the answer is indeterminate is 'false'. - * - * @param args the current method arguments. - * @return true if the item is known to have never been processed before. - */ - boolean isNew(Object[] args); - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/RetryOperationsInterceptor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/RetryOperationsInterceptor.java deleted file mode 100644 index b09caf6be..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/RetryOperationsInterceptor.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.interceptor; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.ProxyMethodInvocation; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryOperations; -import org.springframework.batch.retry.support.RetryTemplate; -import org.springframework.util.Assert; - -/** - * A {@link MethodInterceptor} that can be used to automatically retry calls to - * a method on a service if it fails. The injected {@link RetryOperations} is - * used to control the number of retries. By default it will retry a fixed - * number of times, according to the defaults in {@link RetryTemplate}.
- * - * Hint about transaction boundaries. If you want to retry a failed transaction - * you need to make sure that the transaction boundary is inside the retry, - * otherwise the successful attempt will roll back with the whole transaction. - * If the method being intercepted is also transactional, then use the ordering - * hints in the advice declarations to ensure that this one is before the - * transaction interceptor in the advice chain. - * - * @author Rob Harrop - * @author Dave Syer - */ -public class RetryOperationsInterceptor implements MethodInterceptor { - - private RetryOperations retryOperations = new RetryTemplate(); - - public void setRetryOperations(RetryOperations retryTemplate) { - Assert.notNull(retryTemplate, "'retryOperations' cannot be null."); - this.retryOperations = retryTemplate; - } - - public Object invoke(final MethodInvocation invocation) throws Throwable { - - return this.retryOperations.execute(new RetryCallback() { - - public Object doWithRetry(RetryContext context) throws Exception { - - /* - * If we don't copy the invocation carefully it won't keep a - * reference to the other interceptors in the chain. We don't - * have a choice here but to specialise to - * ReflectiveMethodInvocation (but how often would another - * implementation come along?). - */ - if (invocation instanceof ProxyMethodInvocation) { - try { - return ((ProxyMethodInvocation) invocation) - .invocableClone().proceed(); - } - catch (Exception e) { - throw e; - } catch (Error e) { - throw e; - } catch (Throwable e) { - throw new IllegalStateException(e); - } - } else { - throw new IllegalStateException( - "MethodInvocation of the wrong type detected - this should not happen with Spring AOP, so please raise an issue if you see this exception"); - } - } - - }); - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/StatefulRetryOperationsInterceptor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/StatefulRetryOperationsInterceptor.java deleted file mode 100644 index b446d0b95..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/StatefulRetryOperationsInterceptor.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.interceptor; - -import java.util.Arrays; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryOperations; -import org.springframework.batch.retry.RetryState; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.support.DefaultRetryState; -import org.springframework.batch.retry.support.RetryTemplate; -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; - -/** - * A {@link MethodInterceptor} that can be used to automatically retry calls to - * a method on a service if it fails. The argument to the service method is - * treated as an item to be remembered in case the call fails. So the retry - * operation is stateful, and the item that failed is tracked by its unique key - * (via {@link MethodArgumentsKeyGenerator}) until the retry is exhausted, at - * which point the {@link MethodInvocationRecoverer} is called.
- * - * The main use case for this is where the service is transactional, via a - * transaction interceptor on the interceptor chain. In this case the retry (and - * recovery on exhausted) always happens in a new transaction.
- * - * The injected {@link RetryOperations} is used to control the number of - * retries. By default it will retry a fixed number of times, according to the - * defaults in {@link RetryTemplate}.
- * - * @author Dave Syer - */ -public class StatefulRetryOperationsInterceptor implements MethodInterceptor { - - private transient Log logger = LogFactory.getLog(getClass()); - - private MethodArgumentsKeyGenerator keyGenerator; - - private MethodInvocationRecoverer recoverer; - - private NewMethodArgumentsIdentifier newMethodArgumentsIdentifier; - - private RetryOperations retryOperations; - - public void setRetryOperations(RetryOperations retryTemplate) { - Assert.notNull(retryTemplate, "'retryOperations' cannot be null."); - this.retryOperations = retryTemplate; - } - - /** - * - */ - public StatefulRetryOperationsInterceptor() { - super(); - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new NeverRetryPolicy()); - retryOperations = retryTemplate; - } - - /** - * Public setter for the {@link MethodInvocationRecoverer} to use if the - * retry is exhausted. The recoverer should be able to return an object of - * the same type as the target object because its return value will be used - * to return to the caller in the case of a recovery.
- * - * If no recoverer is set then an exhausted retry will result in an - * {@link ExhaustedRetryException}. - * - * @param recoverer the {@link MethodInvocationRecoverer} to set - */ - public void setRecoverer(MethodInvocationRecoverer recoverer) { - this.recoverer = recoverer; - } - - public void setKeyGenerator(MethodArgumentsKeyGenerator keyGenerator) { - this.keyGenerator = keyGenerator; - } - - /** - * Public setter for the {@link NewMethodArgumentsIdentifier}. Only set this - * if the arguments to the intercepted method can be inspected to find out - * if they have never been processed before. - * @param newMethodArgumentsIdentifier the - * {@link NewMethodArgumentsIdentifier} to set - */ - public void setNewItemIdentifier(NewMethodArgumentsIdentifier newMethodArgumentsIdentifier) { - this.newMethodArgumentsIdentifier = newMethodArgumentsIdentifier; - } - - /** - * Wrap the method invocation in a stateful retry with the policy and other - * helpers provided. If there is a failure the exception will generally be - * re-thrown. The only time it is not re-thrown is when retry is exhausted - * and the recovery path is taken (though the - * {@link MethodInvocationRecoverer} provided if there is one). In that case - * the value returned from the method invocation will be the value returned - * by the recoverer (so the return type for that should be the same as the - * intercepted method). - * - * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) - * @see MethodInvocationRecoverer#recover(Object[], Throwable) - * - * @throws ExhaustedRetryException if the retry is exhausted and no - * {@link MethodInvocationRecoverer} is provided. - */ - public Object invoke(final MethodInvocation invocation) throws Throwable { - - logger.debug("Executing proxied method in stateful retry: " + invocation.getStaticPart() + "(" - + ObjectUtils.getIdentityHexString(invocation) + ")"); - - Object[] args = invocation.getArguments(); - Assert.state(args.length > 0, "Stateful retry applied to method that takes no arguments: " - + invocation.getStaticPart()); - Object arg = args; - if (args.length == 1) { - arg = args[0]; - } - final Object item = arg; - - RetryState retryState = new DefaultRetryState(keyGenerator != null ? keyGenerator.getKey(args) : item, - newMethodArgumentsIdentifier != null ? newMethodArgumentsIdentifier.isNew(args) : false); - - Object result = retryOperations.execute(new MethodInvocationRetryCallback(invocation), - new ItemRecovererCallback(args, recoverer), retryState); - - logger.debug("Exiting proxied method in stateful retry with result: (" + result + ")"); - - return result; - - } - - /** - * @author Dave Syer - * - */ - private static final class MethodInvocationRetryCallback implements RetryCallback { - /** - * - */ - private final MethodInvocation invocation; - - /** - * @param invocation - */ - private MethodInvocationRetryCallback(MethodInvocation invocation) { - this.invocation = invocation; - } - - public Object doWithRetry(RetryContext context) throws Exception { - try { - return invocation.proceed(); - } - catch (Exception e) { - throw e; - } - catch (Error e) { - throw e; - } - catch (Throwable e) { - throw new IllegalStateException(e); - } - } - } - - /** - * @author Dave Syer - * - */ - private static final class ItemRecovererCallback implements RecoveryCallback { - - private final Object[] args; - - private final MethodInvocationRecoverer recoverer; - - /** - * @param args the item that failed. - */ - private ItemRecovererCallback(Object[] args, MethodInvocationRecoverer recoverer) { - this.args = Arrays.asList(args).toArray(); - this.recoverer = recoverer; - } - - public Object recover(RetryContext context) { - if (recoverer != null) { - return recoverer.recover(args, context.getLastThrowable()); - } - throw new ExhaustedRetryException("Retry was exhausted but there was no recovery path."); - } - - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/package.html b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/package.html deleted file mode 100644 index 2c8937847..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/interceptor/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Infrastructure implementations of retry aop concerns. -

- - diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/listener/RetryListenerSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/listener/RetryListenerSupport.java deleted file mode 100644 index 18cad8921..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/listener/RetryListenerSupport.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.listener; - -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryListener; - -/** - * Empty method implementation of {@link RetryListener}. - * - * @author Dave Syer - * - */ -public class RetryListenerSupport implements RetryListener { - - public void close(RetryContext context, RetryCallback callback, Throwable throwable) { - } - - public void onError(RetryContext context, RetryCallback callback, Throwable throwable) { - } - - public boolean open(RetryContext context, RetryCallback callback) { - return true; - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/listener/package.html b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/listener/package.html deleted file mode 100644 index f75aebfc2..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/listener/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Infrastructure implementations of retry interceptor concerns. -

- - diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/package.html b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/package.html deleted file mode 100644 index eb1cc9dc1..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Infrastructure implementations of retry concerns. -

- - diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/AlwaysRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/AlwaysRetryPolicy.java deleted file mode 100644 index f2aa4798a..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/AlwaysRetryPolicy.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; - -/** - * A {@link RetryPolicy} that always permits a retry. Can also be used as a base - * class for other policies, e.g. for test purposes as a stub. - * - * @author Dave Syer - * - */ -public class AlwaysRetryPolicy extends NeverRetryPolicy { - - /** - * Always returns true. - * - * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext) - */ - public boolean canRetry(RetryContext context) { - return true; - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/CompositeRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/CompositeRetryPolicy.java deleted file mode 100644 index a379b38fb..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/CompositeRetryPolicy.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.context.RetryContextSupport; - -/** - * A {@link RetryPolicy} that composes a list of other policies and delegates - * calls to them in order. - * - * @author Dave Syer - * - */ -public class CompositeRetryPolicy implements RetryPolicy { - - RetryPolicy[] policies = new RetryPolicy[0]; - - /** - * Setter for policies. - * - * @param policies - */ - public void setPolicies(RetryPolicy[] policies) { - this.policies = Arrays.asList(policies).toArray(new RetryPolicy[policies.length]); - } - - /** - * Delegate to the policies that were in operation when the context was - * created. If any of them cannot retry then return false, oetherwise return - * true. - * - * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext) - */ - public boolean canRetry(RetryContext context) { - RetryContext[] contexts = ((CompositeRetryContext) context).contexts; - RetryPolicy[] policies = ((CompositeRetryContext) context).policies; - for (int i = 0; i < contexts.length; i++) { - if (!policies[i].canRetry(contexts[i])) { - return false; - } - } - return true; - } - - /** - * Delegate to the policies that were in operation when the context was - * created. If any of them fails to close the exception is propagated (and - * those later in the chain are closed before re-throwing). - * - * @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext) - */ - public void close(RetryContext context) { - RetryContext[] contexts = ((CompositeRetryContext) context).contexts; - RetryPolicy[] policies = ((CompositeRetryContext) context).policies; - RuntimeException exception = null; - for (int i = 0; i < contexts.length; i++) { - try { - policies[i].close(contexts[i]); - } - catch (RuntimeException e) { - if (exception == null) { - exception = e; - } - } - } - if (exception != null) { - throw exception; - } - } - - /** - * Creates a new context that copies the existing policies and keeps a list - * of the contexts from each one. - * - * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) - */ - public RetryContext open(RetryContext parent) { - List list = new ArrayList(); - for (int i = 0; i < policies.length; i++) { - list.add(policies[i].open(parent)); - } - return new CompositeRetryContext(parent, list); - } - - /** - * Delegate to the policies that were in operation when the context was - * created. - * - * @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext) - */ - public void registerThrowable(RetryContext context, Throwable throwable) { - RetryContext[] contexts = ((CompositeRetryContext) context).contexts; - RetryPolicy[] policies = ((CompositeRetryContext) context).policies; - for (int i = 0; i < contexts.length; i++) { - policies[i].registerThrowable(contexts[i], throwable); - } - ((RetryContextSupport) context).registerThrowable(throwable); - } - - private class CompositeRetryContext extends RetryContextSupport { - RetryContext[] contexts; - - RetryPolicy[] policies; - - public CompositeRetryContext(RetryContext parent, List contexts) { - super(parent); - this.contexts = contexts.toArray(new RetryContext[0]); - this.policies = CompositeRetryPolicy.this.policies; - } - - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/ExceptionClassifierRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/ExceptionClassifierRetryPolicy.java deleted file mode 100644 index 7bb4fc8cb..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/ExceptionClassifierRetryPolicy.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.classify.ClassifierSupport; -import org.springframework.batch.classify.SubclassClassifier; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.util.Assert; - -/** - * A {@link RetryPolicy} that dynamically adapts to one of a set of injected - * policies according to the value of the latest exception. - * - * @author Dave Syer - * - */ -public class ExceptionClassifierRetryPolicy implements RetryPolicy { - - private Classifier exceptionClassifier = new ClassifierSupport( - new NeverRetryPolicy()); - - /** - * Setter for policy map used to create a classifier. Either this property - * or the exception classifier directly should be set, but not both. - * - * @param policyMap a map of Throwable class to {@link RetryPolicy} that - * will be used to create a {@link Classifier} to locate a policy. - */ - public void setPolicyMap(Map, RetryPolicy> policyMap) { - SubclassClassifier subclassClassifier = new SubclassClassifier( - policyMap, (RetryPolicy) new NeverRetryPolicy()); - this.exceptionClassifier = subclassClassifier; - } - - /** - * Setter for an exception classifier. The classifier is responsible for - * translating exceptions to concrete retry policies. Either this property - * or the policy map should be used, but not both. - * - * @param exceptionClassifier ExceptionClassifier to use - */ - public void setExceptionClassifier(Classifier exceptionClassifier) { - this.exceptionClassifier = exceptionClassifier; - } - - /** - * Delegate to the policy currently activated in the context. - * - * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext) - */ - public boolean canRetry(RetryContext context) { - RetryPolicy policy = (RetryPolicy) context; - return policy.canRetry(context); - } - - /** - * Delegate to the policy currently activated in the context. - * - * @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext) - */ - public void close(RetryContext context) { - RetryPolicy policy = (RetryPolicy) context; - policy.close(context); - } - - /** - * Create an active context that proxies a retry policy by chosing a target - * from the policy map. - * - * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) - */ - public RetryContext open(RetryContext parent) { - return new ExceptionClassifierRetryContext(parent, exceptionClassifier).open(parent); - } - - /** - * Delegate to the policy currently activated in the context. - * - * @see org.springframework.batch.retry.RetryPolicy#registerThrowable(org.springframework.batch.retry.RetryContext, - * Throwable) - */ - public void registerThrowable(RetryContext context, Throwable throwable) { - RetryPolicy policy = (RetryPolicy) context; - policy.registerThrowable(context, throwable); - ((RetryContextSupport) context).registerThrowable(throwable); - } - - private static class ExceptionClassifierRetryContext extends RetryContextSupport implements RetryPolicy { - - final private Classifier exceptionClassifier; - - // Dynamic: depends on the latest exception: - private RetryPolicy policy; - - // Dynamic: depends on the policy: - private RetryContext context; - - final private Map contexts = new HashMap(); - - public ExceptionClassifierRetryContext(RetryContext parent, - Classifier exceptionClassifier) { - super(parent); - this.exceptionClassifier = exceptionClassifier; - } - - public boolean canRetry(RetryContext context) { - if (this.context == null) { - // there was no error yet - return true; - } - return policy.canRetry(this.context); - } - - public void close(RetryContext context) { - // Only close those policies that have been used (opened): - for (RetryPolicy policy : contexts.keySet()) { - policy.close(getContext(policy, context.getParent())); - } - } - - public RetryContext open(RetryContext parent) { - return this; - } - - public void registerThrowable(RetryContext context, Throwable throwable) { - policy = exceptionClassifier.classify(throwable); - Assert.notNull(policy, "Could not locate policy for exception=[" + throwable + "]."); - this.context = getContext(policy, context.getParent()); - policy.registerThrowable(this.context, throwable); - } - - private RetryContext getContext(RetryPolicy policy, RetryContext parent) { - RetryContext context = contexts.get(policy); - if (context == null) { - context = policy.open(parent); - contexts.put(policy, context); - } - return context; - } - - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/MapRetryContextCache.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/MapRetryContextCache.java deleted file mode 100644 index 7bae045f2..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/MapRetryContextCache.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.policy; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.springframework.batch.retry.RetryContext; - -/** - * Map-based implementation of {@link RetryContextCache}. The map backing the - * cache of contexts is synchronized. - * - * @author Dave Syer - * - */ -public class MapRetryContextCache implements RetryContextCache { - - /** - * Default value for maximum capacity of the cache. This is set to a - * reasonably low value (4096) to avoid users inadvertently filling the - * cache with item keys that are inconsistent. - */ - public static final int DEFAULT_CAPACITY = 4096; - - private Map map = Collections.synchronizedMap(new HashMap()); - - private int capacity; - - /** - * Create a {@link MapRetryContextCache} with default capacity. - */ - public MapRetryContextCache() { - this(DEFAULT_CAPACITY); - } - - /** - * @param defaultCapacity - */ - public MapRetryContextCache(int defaultCapacity) { - super(); - this.capacity = defaultCapacity; - } - - /** - * Public setter for the capacity. Prevents the cache from growing - * unboundedly if items that fail are misidentified and two references to an - * identical item actually do not have the same key. This can happen when - * users implement equals and hashCode based on mutable fields, for - * instance. - * - * @param capacity the capacity to set - */ - public void setCapacity(int capacity) { - this.capacity = capacity; - } - - public boolean containsKey(Object key) { - return map.containsKey(key); - } - - public RetryContext get(Object key) { - return map.get(key); - } - - public void put(Object key, RetryContext context) { - if (map.size() >= capacity) { - throw new RetryCacheCapacityExceededException("Retry cache capacity limit breached. " - + "Do you need to re-consider the implementation of the key generator, " - + "or the equals and hashCode of the items that failed?"); - } - map.put(key, context); - } - - public void remove(Object key) { - map.remove(key); - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/NeverRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/NeverRetryPolicy.java deleted file mode 100644 index 343cf9afe..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/NeverRetryPolicy.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.context.RetryContextSupport; - -/** - * A {@link RetryPolicy} that allows the first attempt but never permits a - * retry. Also be used as a base class for other policies, e.g. for test - * purposes as a stub. - * - * @author Dave Syer - * - */ -public class NeverRetryPolicy implements RetryPolicy { - - /** - * Returns false after the first exception. So there is always one try, and - * then the retry is prevented. - * - * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext) - */ - public boolean canRetry(RetryContext context) { - return !((NeverRetryContext) context).isFinished(); - } - - /** - * Do nothing. - * - * @see org.springframework.batch.retry.RetryPolicy#close(org.springframework.batch.retry.RetryContext) - */ - public void close(RetryContext context) { - // no-op - } - - /** - * Return a context that can respond to early termination requests, but does - * nothing else. - * - * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) - */ - public RetryContext open(RetryContext parent) { - return new NeverRetryContext(parent); - } - - /** - * Make the throwable available for downstream use through the context. - * @see org.springframework.batch.retry.RetryPolicy#registerThrowable(org.springframework.batch.retry.RetryContext, - * Throwable) - */ - public void registerThrowable(RetryContext context, Throwable throwable) { - ((NeverRetryContext) context).setFinished(); - ((RetryContextSupport) context).registerThrowable(throwable); - } - - /** - * Special context object for {@link NeverRetryPolicy}. Implements a flag - * with a similar function to {@link RetryContext#isExhaustedOnly()}, but - * kept separate so that if subclasses of {@link NeverRetryPolicy} need to - * they can modify the behaviour of - * {@link NeverRetryPolicy#canRetry(RetryContext)} without affecting - * {@link RetryContext#isExhaustedOnly()}. - * - * @author Dave Syer - * - */ - private static class NeverRetryContext extends RetryContextSupport { - private boolean finished = false; - - public NeverRetryContext(RetryContext parent) { - super(parent); - } - - public boolean isFinished() { - return finished; - } - - public void setFinished() { - this.finished = true; - } - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/RetryCacheCapacityExceededException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/RetryCacheCapacityExceededException.java deleted file mode 100644 index 2bc264eb6..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/RetryCacheCapacityExceededException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.policy; - -import org.springframework.batch.retry.RetryException; - -/** - * Exception that indicates that a cache limit was exceeded. This is often a - * sign of badly or inconsistently implemented hashCode, equals in failed items. - * Items can then fail repeatedly and appear different to the cache, so they get - * added over and over again until a limit is reached and this exception is - * thrown. Consult the documentation of the {@link RetryContextCache} in use to - * determine how to increase the limit if appropriate. - * - * @author Dave Syer - * - */ -public class RetryCacheCapacityExceededException extends RetryException { - - /** - * Constructs a new instance with a message. - * - * @param message - */ - public RetryCacheCapacityExceededException(String message) { - super(message); - } - - /** - * Constructs a new instance with a message and nested exception. - * - * @param msg the exception message. - * - */ - public RetryCacheCapacityExceededException(String msg, Throwable nested) { - super(msg, nested); - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/RetryContextCache.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/RetryContextCache.java deleted file mode 100644 index 9fa243fa0..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/RetryContextCache.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import org.springframework.batch.retry.RetryContext; - -/** - * Simple map-like abstraction for stateful retry policies to use when storing - * and retrieving {@link RetryContext} instances. - * - * @author Dave Syer - * - * @see MapRetryContextCache - * - */ -public interface RetryContextCache { - - RetryContext get(Object key); - - void put(Object key, RetryContext context) throws RetryCacheCapacityExceededException; - - void remove(Object key); - - boolean containsKey(Object key); - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java deleted file mode 100644 index 70ba48ec4..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import java.util.Collections; -import java.util.Map; - -import org.springframework.batch.classify.BinaryExceptionClassifier; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.context.RetryContextSupport; - -/** - * - * Simple retry policy that retries a fixed number of times for a set of named - * exceptions (and subclasses). The number of attempts includes the initial try, - * so e.g. - * - *
- * retryTemplate = new RetryTemplate(new SimpleRetryPolicy(3));
- * retryTemplate.execute(callback);
- * 
- * - * will execute the callback at least once, and as many as 3 times. - * - * @author Dave Syer - * @author Rob Harrop - * - */ -public class SimpleRetryPolicy implements RetryPolicy { - - /** - * The default limit to the number of attempts for a new policy. - */ - public final static int DEFAULT_MAX_ATTEMPTS = 3; - - private volatile int maxAttempts; - - private volatile BinaryExceptionClassifier retryableClassifier = new BinaryExceptionClassifier(false); - - /** - * Create a {@link SimpleRetryPolicy} with the default number of retry - * attempts. - */ - public SimpleRetryPolicy() { - this(DEFAULT_MAX_ATTEMPTS, Collections - ., Boolean> singletonMap(Exception.class, true)); - } - - /** - * Create a {@link SimpleRetryPolicy} with the specified number of retry - * attempts. - * - * @param maxAttempts - * @param retryableExceptions - */ - public SimpleRetryPolicy(int maxAttempts, Map, Boolean> retryableExceptions) { - super(); - this.maxAttempts = maxAttempts; - this.retryableClassifier = new BinaryExceptionClassifier(retryableExceptions); - } - - /** - * @param retryableExceptions - */ - public void setRetryableExceptions(Map, Boolean> retryableExceptions) { - this.retryableClassifier = new BinaryExceptionClassifier(retryableExceptions); - } - - /** - * Setter for retry attempts. - * - * @param retryAttempts the number of attempts before a retry becomes - * impossible. - */ - public void setMaxAttempts(int retryAttempts) { - this.maxAttempts = retryAttempts; - } - - /** - * The maximum number of retry attempts before failure. - * - * @return the maximum number of attempts - */ - public int getMaxAttempts() { - return maxAttempts; - } - - /** - * Test for retryable operation based on the status. - * - * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext) - * - * @return true if the last exception was retryable and the number of - * attempts so far is less than the limit. - */ - public boolean canRetry(RetryContext context) { - Throwable t = context.getLastThrowable(); - return (t == null || retryForException(t)) && context.getRetryCount() < maxAttempts; - } - - /** - * @see org.springframework.batch.retry.RetryPolicy#close(RetryContext) - */ - public void close(RetryContext status) { - } - - /** - * Update the status with another attempted retry and the latest exception. - * - * @see RetryPolicy#registerThrowable(RetryContext, Throwable) - */ - public void registerThrowable(RetryContext context, Throwable throwable) { - SimpleRetryContext simpleContext = ((SimpleRetryContext) context); - simpleContext.registerThrowable(throwable); - } - - /** - * Get a status object that can be used to track the current operation - * according to this policy. Has to be aware of the latest exception and the - * number of attempts. - * - * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) - */ - public RetryContext open(RetryContext parent) { - return new SimpleRetryContext(parent); - } - - private static class SimpleRetryContext extends RetryContextSupport { - public SimpleRetryContext(RetryContext parent) { - super(parent); - } - } - - /** - * Delegates to an exception classifier. - * - * @param ex - * @return true if this exception or its ancestors have been registered as - * retryable. - */ - private boolean retryForException(Throwable ex) { - return retryableClassifier.classify(ex); - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SoftReferenceMapRetryContextCache.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SoftReferenceMapRetryContextCache.java deleted file mode 100644 index 3e52e64f4..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SoftReferenceMapRetryContextCache.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.policy; - -import java.lang.ref.SoftReference; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.springframework.batch.retry.RetryContext; - -/** - * Map-based implementation of {@link RetryContextCache}. The map backing the - * cache of contexts is synchronized and its entries are soft-referenced, so may - * be garbage collected under pressure. - * - * @see MapRetryContextCache for non-soft referenced version - * - * @author Dave Syer - * - */ -public class SoftReferenceMapRetryContextCache implements RetryContextCache { - - /** - * Default value for maximum capacity of the cache. This is set to a - * reasonably low value (4096) to avoid users inadvertently filling the - * cache with item keys that are inconsistent. - */ - public static final int DEFAULT_CAPACITY = 4096; - - private Map> map = Collections - .synchronizedMap(new HashMap>()); - - private int capacity; - - /** - * Create a {@link SoftReferenceMapRetryContextCache} with default capacity. - */ - public SoftReferenceMapRetryContextCache() { - this(DEFAULT_CAPACITY); - } - - /** - * @param defaultCapacity - */ - public SoftReferenceMapRetryContextCache(int defaultCapacity) { - super(); - this.capacity = defaultCapacity; - } - - /** - * Public setter for the capacity. Prevents the cache from growing - * unboundedly if items that fail are misidentified and two references to an - * identical item actually do not have the same key. This can happen when - * users implement equals and hashCode based on mutable fields, for - * instance. - * - * @param capacity the capacity to set - */ - public void setCapacity(int capacity) { - this.capacity = capacity; - } - - public boolean containsKey(Object key) { - if (!map.containsKey(key)) { - return false; - } - if (map.get(key).get() == null) { - // our reference was garbage collected - map.remove(key); - } - return map.containsKey(key); - } - - public RetryContext get(Object key) { - return map.get(key).get(); - } - - public void put(Object key, RetryContext context) { - if (map.size() >= capacity) { - throw new RetryCacheCapacityExceededException("Retry cache capacity limit breached. " - + "Do you need to re-consider the implementation of the key generator, " - + "or the equals and hashCode of the items that failed?"); - } - map.put(key, new SoftReference(context)); - } - - public void remove(Object key) { - map.remove(key); - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/TimeoutRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/TimeoutRetryPolicy.java deleted file mode 100644 index d49acb95c..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/TimeoutRetryPolicy.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.context.RetryContextSupport; - -/** - * A {@link RetryPolicy} that allows a retry only if it hasn't timed out. The - * clock is started on a call to {@link #open(RetryContext)}. - * - * @author Dave Syer - * - */ -public class TimeoutRetryPolicy implements RetryPolicy { - - /** - * Default value for timeout (milliseconds). - */ - public static final long DEFAULT_TIMEOUT = 1000; - - private long timeout = DEFAULT_TIMEOUT; - - /** - * Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}. - * @param timeout - */ - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - /** - * The value of the timeout. - * - * @return the timeout in milliseconds - */ - public long getTimeout() { - return timeout; - } - - /** - * Only permits a retry if the timeout has not expired. Does not check the - * exception at all. - * - * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext) - */ - public boolean canRetry(RetryContext context) { - return ((TimeoutRetryContext) context).isAlive(); - } - - public void close(RetryContext context) { - } - - public RetryContext open(RetryContext parent) { - return new TimeoutRetryContext(parent, timeout); - } - - public void registerThrowable(RetryContext context, Throwable throwable) { - ((RetryContextSupport) context).registerThrowable(throwable); - // otherwise no-op - we only time out, otherwise retry everything... - } - - private static class TimeoutRetryContext extends RetryContextSupport { - private long timeout; - - private long start; - - public TimeoutRetryContext(RetryContext parent, long timeout) { - super(parent); - this.start = System.currentTimeMillis(); - this.timeout = timeout; - } - - public boolean isAlive() { - return (System.currentTimeMillis() - start) <= timeout; - } - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/package.html b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/package.html deleted file mode 100644 index 765200937..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Infrastructure implementations of retry policy concerns. -

- - diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/DefaultRetryState.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/DefaultRetryState.java deleted file mode 100644 index 339d22c4d..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/DefaultRetryState.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.support; - -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryOperations; -import org.springframework.batch.retry.RetryState; - -/** - * - * @author Dave Syer - * - */ -public class DefaultRetryState implements RetryState { - - final private Object key; - - final private boolean forceRefresh; - - final private Classifier rollbackClassifier; - - /** - * Create a {@link DefaultRetryState} representing the state for a new retry - * attempt. - * - * @see RetryOperations#execute(RetryCallback, RetryState) - * @see RetryOperations#execute(RetryCallback, RecoveryCallback, RetryState) - * - * @param key the key for the state to allow this retry attempt to be - * recognised - * @param forceRefresh true if the attempt is known to be a brand new state - * (could not have previously failed) - * @param rollbackClassifier the rollback classifier to set. The rollback - * classifier answers true if the exception provided should cause a - * rollback. - */ - public DefaultRetryState(Object key, boolean forceRefresh, Classifier rollbackClassifier) { - this.key = key; - this.forceRefresh = forceRefresh; - this.rollbackClassifier = rollbackClassifier; - } - - /** - * Defaults the force refresh flag to false. - * @see DefaultRetryState#DefaultRetryState(Object, boolean, Classifier) - */ - public DefaultRetryState(Object key, Classifier rollbackClassifier) { - this(key, false, rollbackClassifier); - } - - /** - * Defaults the rollback classifier to null. - * @see DefaultRetryState#DefaultRetryState(Object, boolean, Classifier) - */ - public DefaultRetryState(Object key, boolean forceRefresh) { - this(key, forceRefresh, null); - } - - /** - * Defaults the force refresh flag (to false) and the rollback classifier - * (to null). - * - * @see DefaultRetryState#DefaultRetryState(Object, boolean, Classifier) - */ - public DefaultRetryState(Object key) { - this(key, false, null); - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.retry.IRetryState#getKey() - */ - public Object getKey() { - return key; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.retry.IRetryState#isForceRefresh() - */ - public boolean isForceRefresh() { - return forceRefresh; - } - - /* - * (non-Javadoc) - * - * @see - * org.springframework.batch.retry.RetryState#rollbackFor(java.lang.Throwable - * ) - */ - public boolean rollbackFor(Throwable exception) { - if (rollbackClassifier == null) { - return true; - } - return rollbackClassifier.classify(exception); - } - - @Override - public String toString() { - return String.format("[%s: key=%s, forceRefresh=%b]", getClass().getSimpleName(), key, forceRefresh); - } -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetrySynchronizationManager.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetrySynchronizationManager.java deleted file mode 100644 index 30fa5448a..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetrySynchronizationManager.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.support; - -import org.springframework.batch.repeat.RepeatOperations; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryOperations; - -/** - * Global variable support for retry clients. Normally it is not necessary for - * clients to be aware of the surrounding environment because a - * {@link RetryCallback} can always use the context it is passed by the - * enclosing {@link RetryOperations}. But occasionally it might be helpful to - * have lower level access to the ongoing {@link RetryContext} so we provide a - * global accessor here. The mutator methods ({@link #clear()} and - * {@link #register(RetryContext)} should not be used except internally by - * {@link RetryOperations} implementations. - * - * @author Dave Syer - * - */ -public final class RetrySynchronizationManager { - - private RetrySynchronizationManager() {} - - private static final ThreadLocal context = new ThreadLocal(); - - /** - * Public accessor for the locally enclosing {@link RetryContext}. - * - * @return the current retry context, or null if there isn't one - */ - public static RetryContext getContext() { - RetryContext result = (RetryContext) context.get(); - return result; - } - - /** - * Method for registering a context - should only be used by - * {@link RetryOperations} implementations to ensure that - * {@link #getContext()} always returns the correct value. - * - * @param context the new context to register - * @return the old context if there was one - */ - public static RetryContext register(RetryContext context) { - RetryContext oldContext = getContext(); - RetrySynchronizationManager.context.set(context); - return oldContext; - } - - /** - * Clear the current context at the end of a batch - should only be used by - * {@link RepeatOperations} implementations. - * - * @return the old value if there was one. - */ - public static RetryContext clear() { - RetryContext value = getContext(); - RetryContext parent = value == null ? null : value.getParent(); - RetrySynchronizationManager.context.set(parent); - return value; - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetryTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetryTemplate.java deleted file mode 100644 index c694f23a8..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetryTemplate.java +++ /dev/null @@ -1,490 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.support; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.batch.repeat.RepeatException; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryException; -import org.springframework.batch.retry.RetryListener; -import org.springframework.batch.retry.RetryOperations; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.RetryState; -import org.springframework.batch.retry.TerminatedRetryException; -import org.springframework.batch.retry.backoff.BackOffContext; -import org.springframework.batch.retry.backoff.BackOffInterruptedException; -import org.springframework.batch.retry.backoff.BackOffPolicy; -import org.springframework.batch.retry.backoff.NoBackOffPolicy; -import org.springframework.batch.retry.policy.MapRetryContextCache; -import org.springframework.batch.retry.policy.RetryContextCache; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; - -/** - * Template class that simplifies the execution of operations with retry - * semantics.
- * Retryable operations are encapsulated in implementations of the - * {@link RetryCallback} interface and are executed using one of the supplied - * execute methods.
- * - * By default, an operation is retried if is throws any {@link Exception} or - * subclass of {@link Exception}. This behaviour can be changed by using the - * {@link #setRetryPolicy(RetryPolicy)} method.
- * - * Also by default, each operation is retried for a maximum of three attempts - * with no back off in between. This behaviour can be configured using the - * {@link #setRetryPolicy(RetryPolicy)} and - * {@link #setBackOffPolicy(BackOffPolicy)} properties. The - * {@link org.springframework.batch.retry.backoff.BackOffPolicy} controls how - * long the pause is between each individual retry attempt.
- * - * This class is thread-safe and suitable for concurrent access when executing - * operations and when performing configuration changes. As such, it is possible - * to change the number of retries on the fly, as well as the - * {@link BackOffPolicy} used and no in progress retryable operations will be - * affected. - * - * @author Rob Harrop - * @author Dave Syer - */ -public class RetryTemplate implements RetryOperations { - - protected final Log logger = LogFactory.getLog(getClass()); - - private volatile BackOffPolicy backOffPolicy = new NoBackOffPolicy(); - - private volatile RetryPolicy retryPolicy = new SimpleRetryPolicy(3, Collections - ., Boolean> singletonMap(Exception.class, true)); - - private volatile RetryListener[] listeners = new RetryListener[0]; - - private RetryContextCache retryContextCache = new MapRetryContextCache(); - - /** - * Public setter for the {@link RetryContextCache}. - * - * @param retryContextCache the {@link RetryContextCache} to set. - */ - public void setRetryContextCache(RetryContextCache retryContextCache) { - this.retryContextCache = retryContextCache; - } - - /** - * Setter for listeners. The listeners are executed before and after a retry - * block (i.e. before and after all the attempts), and on an error (every - * attempt). - * - * @param listeners - * @see RetryListener - */ - public void setListeners(RetryListener[] listeners) { - this.listeners = Arrays.asList(listeners).toArray(new RetryListener[listeners.length]); - } - - /** - * Register an additional listener. - * - * @param listener - * @see #setListeners(RetryListener[]) - */ - public void registerListener(RetryListener listener) { - List list = new ArrayList(Arrays.asList(listeners)); - list.add(listener); - listeners = list.toArray(new RetryListener[list.size()]); - } - - /** - * Setter for {@link BackOffPolicy}. - * - * @param backOffPolicy - */ - public void setBackOffPolicy(BackOffPolicy backOffPolicy) { - this.backOffPolicy = backOffPolicy; - } - - /** - * Setter for {@link RetryPolicy}. - * - * @param retryPolicy - */ - public void setRetryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; - } - - /** - * Keep executing the callback until it either succeeds or the policy - * dictates that we stop, in which case the most recent exception thrown by - * the callback will be rethrown. - * - * @see RetryOperations#execute(RetryCallback) - * - * @throws TerminatedRetryException if the retry has been manually - * terminated by a listener. - */ - public final T execute(RetryCallback retryCallback) throws Exception { - return doExecute(retryCallback, null, null); - } - - /** - * Keep executing the callback until it either succeeds or the policy - * dictates that we stop, in which case the recovery callback will be - * executed. - * - * @see RetryOperations#execute(RetryCallback, RecoveryCallback) - * - * @throws TerminatedRetryException if the retry has been manually - * terminated by a listener. - */ - public final T execute(RetryCallback retryCallback, RecoveryCallback recoveryCallback) throws Exception { - return doExecute(retryCallback, recoveryCallback, null); - } - - /** - * Execute the callback once if the policy dictates that we can, re-throwing - * any exception encountered so that clients can re-present the same task - * later. - * - * @see RetryOperations#execute(RetryCallback, RetryState) - * - * @throws ExhaustedRetryException if the retry has been exhausted. - */ - public final T execute(RetryCallback retryCallback, RetryState retryState) throws Exception, - ExhaustedRetryException { - return doExecute(retryCallback, null, retryState); - } - - /** - * Execute the callback once if the policy dictates that we can, re-throwing - * any exception encountered so that clients can re-present the same task - * later. - * - * @see RetryOperations#execute(RetryCallback, RetryState) - */ - public final T execute(RetryCallback retryCallback, RecoveryCallback recoveryCallback, - RetryState retryState) throws Exception, ExhaustedRetryException { - return doExecute(retryCallback, recoveryCallback, retryState); - } - - /** - * Execute the callback once if the policy dictates that we can, otherwise - * execute the recovery callback. - * - * @see RetryOperations#execute(RetryCallback, RecoveryCallback, RetryState) - * @throws ExhaustedRetryException if the retry has been exhausted. - */ - protected T doExecute(RetryCallback retryCallback, RecoveryCallback recoveryCallback, RetryState state) - throws Exception, ExhaustedRetryException { - - RetryPolicy retryPolicy = this.retryPolicy; - BackOffPolicy backOffPolicy = this.backOffPolicy; - - // Allow the retry policy to initialise itself... - RetryContext context = open(retryPolicy, state); - if (logger.isTraceEnabled()) { - logger.trace("RetryContext retrieved: " + context); - } - - // Make sure the context is available globally for clients who need - // it... - RetrySynchronizationManager.register(context); - - Throwable lastException = null; - - try { - - // Give clients a chance to enhance the context... - boolean running = doOpenInterceptors(retryCallback, context); - - if (!running) { - throw new TerminatedRetryException("Retry terminated abnormally by interceptor before first attempt"); - } - - // Start the backoff context... - BackOffContext backOffContext = backOffPolicy.start(context); - - /* - * We allow the whole loop to be skipped if the policy or context - * already forbid the first try. This is used in the case of - * stateful retry to allow a recovery in handleRetryExhausted - * without the callback processing (which would throw an exception). - */ - while (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) { - - try { - logger.debug("Retry: count=" + context.getRetryCount()); - // Reset the last exception, so if we are successful - // the close interceptors will not think we failed... - lastException = null; - return retryCallback.doWithRetry(context); - } - catch (Throwable e) { - - lastException = e; - - doOnErrorInterceptors(retryCallback, context, e); - - try { - registerThrowable(retryPolicy, state, context, e); - } catch (Exception ex) { - throw new TerminatedRetryException("Terminated retry after error in policy", ex); - } - - if (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) { - try { - backOffPolicy.backOff(backOffContext); - } - catch (BackOffInterruptedException ex) { - lastException = e; - // back off was prevented by another thread - fail - // the retry - logger.debug("Abort retry because interrupted: count=" + context.getRetryCount()); - throw ex; - } - } - - logger.debug("Checking for rethrow: count=" + context.getRetryCount()); - if (shouldRethrow(retryPolicy, context, state)) { - logger.debug("Rethrow in retry for policy: count=" + context.getRetryCount()); - throw wrapIfNecessary(e); - } - - } - - /* - * A stateful attempt that can retry should have rethrown the - * exception by now - i.e. we shouldn't get this far for a - * stateful attempt if it can retry. - */ - } - - logger.debug("Retry failed last attempt: count=" + context.getRetryCount()); - - if (context.isExhaustedOnly()) { - throw new ExhaustedRetryException("Retry exhausted after last attempt with no recovery path.", context - .getLastThrowable()); - } - - return handleRetryExhausted(recoveryCallback, context, state); - - } - finally { - close(retryPolicy, context, state, lastException == null); - doCloseInterceptors(retryCallback, context, lastException); - RetrySynchronizationManager.clear(); - } - - } - - /** - * Decide whether to proceed with the ongoing retry attempt. This method is - * called before the {@link RetryCallback} is executed, but after the - * backoff and open interceptors. - * - * @param retryPolicy the policy to apply - * @param context the current retry context - * @return true if we can continue with the attempt - */ - protected boolean canRetry(RetryPolicy retryPolicy, RetryContext context) { - return retryPolicy.canRetry(context); - } - - /** - * Clean up the cache if necessary and close the context provided (if the - * flag indicates that processing was successful). - * - * @param context - * @param state - * @param succeeded - */ - protected void close(RetryPolicy retryPolicy, RetryContext context, RetryState state, boolean succeeded) { - if (state != null) { - if (succeeded) { - retryContextCache.remove(state.getKey()); - retryPolicy.close(context); - } - } - else { - retryPolicy.close(context); - } - } - - /** - * @param retryPolicy - * @param state - * @param context - * @param e - */ - protected void registerThrowable(RetryPolicy retryPolicy, RetryState state, RetryContext context, Throwable e) { - if (state != null) { - Object key = state.getKey(); - if (context.getRetryCount() > 0 && !retryContextCache.containsKey(key)) { - throw new RetryException("Inconsistent state for failed item key: cache key has changed. " - + "Consider whether equals() or hashCode() for the key might be inconsistent, " - + "or if you need to supply a better key"); - } - retryContextCache.put(key, context); - } - retryPolicy.registerThrowable(context, e); - } - - /** - * Delegate to the {@link RetryPolicy} having checked in the cache for an - * existing value if the state is not null. - * - * @param retryPolicy a {@link RetryPolicy} to delegate the context creation - * @return a retry context, either a new one or the one used last time the - * same state was encountered - */ - protected RetryContext open(RetryPolicy retryPolicy, RetryState state) { - - if (state == null) { - return doOpenInternal(retryPolicy); - } - - Object key = state.getKey(); - if (state.isForceRefresh()) { - return doOpenInternal(retryPolicy); - } - - // If there is no cache hit we can avoid the possible expense of the - // cache re-hydration. - if (!retryContextCache.containsKey(key)) { - // The cache is only used if there is a failure. - return doOpenInternal(retryPolicy); - } - - RetryContext context = retryContextCache.get(key); - if (context == null) { - if (retryContextCache.containsKey(key)) { - throw new RetryException("Inconsistent state for failed item: no history found. " - + "Consider whether equals() or hashCode() for the item might be inconsistent, " - + "or if you need to supply a better ItemKeyGenerator"); - } - // The cache could have been expired in between calls to - // containsKey(), so we have to live with this: - return doOpenInternal(retryPolicy); - } - - return context; - - } - - /** - * @param retryPolicy - * @return - */ - private RetryContext doOpenInternal(RetryPolicy retryPolicy) { - return retryPolicy.open(RetrySynchronizationManager.getContext()); - } - - /** - * Actions to take after final attempt has failed. If there is state clean - * up the cache. If there is a recovery callback, execute that and return - * its result. Otherwise throw an exception. - * - * @param recoveryCallback the callback for recovery (might be null) - * @param context the current retry context - * @throws Exception if the callback does, and if there is no callback and - * the state is null then the last exception from the context - * @throws ExhaustedRetryException if the state is not null and there is no - * recovery callback - */ - protected T handleRetryExhausted(RecoveryCallback recoveryCallback, RetryContext context, RetryState state) - throws Exception { - if (state != null) { - retryContextCache.remove(state.getKey()); - } - if (recoveryCallback != null) { - return recoveryCallback.recover(context); - } - if (state != null) { - logger.debug("Retry exhausted after last attempt with no recovery path."); - throw new ExhaustedRetryException("Retry exhausted after last attempt with no recovery path", context - .getLastThrowable()); - } - throw wrapIfNecessary(context.getLastThrowable()); - } - - /** - * Extension point for subclasses to decide on behaviour after catching an - * exception in a {@link RetryCallback}. Normal stateless behaviour is not - * to rethrow, and if there is state we rethrow. - * - * @param retryPolicy - * @param context the current context - * - * @return true if the state is not null but subclasses might choose - * otherwise - */ - protected boolean shouldRethrow(RetryPolicy retryPolicy, RetryContext context, RetryState state) { - if (state == null) { - return false; - } - else { - return state.rollbackFor(context.getLastThrowable()); - } - } - - private boolean doOpenInterceptors(RetryCallback callback, RetryContext context) { - - boolean result = true; - - for (int i = 0; i < listeners.length; i++) { - result = result && listeners[i].open(context, callback); - } - - return result; - - } - - private void doCloseInterceptors(RetryCallback callback, RetryContext context, Throwable lastException) { - for (int i = listeners.length; i-- > 0;) { - listeners[i].close(context, callback, lastException); - } - } - - private void doOnErrorInterceptors(RetryCallback callback, RetryContext context, Throwable throwable) { - for (int i = listeners.length; i-- > 0;) { - listeners[i].onError(context, callback, throwable); - } - } - - /** - * Re-throws the original throwable if it is unchecked, wraps checked - * exceptions into {@link RepeatException}. - */ - private static Exception wrapIfNecessary(Throwable throwable) { - if (throwable instanceof Error) { - throw (Error) throwable; - } - else if (throwable instanceof Exception) { - return (Exception) throwable; - } - else { - return new RetryException("Exception in batch process", throwable); - } - } - -} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/package.html b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/package.html deleted file mode 100644 index 549ec8289..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-Infrastructure implementations of retry support concerns. -

- - diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/BackToBackPatternClassifierTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/BackToBackPatternClassifierTests.java deleted file mode 100644 index 04b56a622..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/BackToBackPatternClassifierTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import static org.junit.Assert.assertEquals; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.batch.classify.BackToBackPatternClassifier; -import org.springframework.batch.classify.PatternMatchingClassifier; -import org.springframework.batch.support.annotation.Classifier; - -/** - * @author Dave Syer - * - */ -public class BackToBackPatternClassifierTests { - - private BackToBackPatternClassifier classifier = new BackToBackPatternClassifier(); - - private Map map; - - @Before - public void createMap() { - map = new HashMap(); - map.put("foo", "bar"); - map.put("*", "spam"); - } - - @Test(expected=NullPointerException.class) - public void testNoClassifiers() { - classifier.classify("foo"); - } - - @Test - public void testCreateFromConstructor() { - classifier = new BackToBackPatternClassifier(new PatternMatchingClassifier(Collections - .singletonMap("oof", "bucket")), new PatternMatchingClassifier(map)); - assertEquals("spam", classifier.classify("oof")); - } - - @Test - public void testSetRouterDelegate() { - classifier.setRouterDelegate(new Object() { - @SuppressWarnings("unused") - @Classifier - public String convert(String value) { - return "bucket"; - } - }); - classifier.setMatcherMap(map); - assertEquals("spam", classifier.classify("oof")); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/BinaryExceptionClassifierTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/BinaryExceptionClassifierTests.java deleted file mode 100644 index 570501626..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/BinaryExceptionClassifierTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.classify; - -import java.util.Collection; -import java.util.Collections; - -import junit.framework.TestCase; - -public class BinaryExceptionClassifierTests extends TestCase { - - BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(false); - - public void testClassifyNullIsDefault() { - assertFalse(classifier.classify(null)); - } - - public void testFalseIsDefault() { - assertFalse(classifier.getDefault()); - } - - public void testDefaultProvided() { - classifier = new BinaryExceptionClassifier(true); - assertTrue(classifier.getDefault()); - } - - public void testClassifyRandomException() { - assertFalse(classifier.classify(new IllegalStateException("foo"))); - } - - public void testClassifyExactMatch() { - Collection> set = Collections - .> singleton(IllegalStateException.class); - assertTrue(new BinaryExceptionClassifier(set).classify(new IllegalStateException("Foo"))); - } - - public void testTypesProvidedInConstructor() { - classifier = new BinaryExceptionClassifier(Collections - .> singleton(IllegalStateException.class)); - assertTrue(classifier.classify(new IllegalStateException("Foo"))); - } - - public void testTypesProvidedInConstructorWithNonDefault() { - classifier = new BinaryExceptionClassifier(Collections - .> singleton(IllegalStateException.class), false); - assertFalse(classifier.classify(new IllegalStateException("Foo"))); - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/ClassifierAdapterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/ClassifierAdapterTests.java deleted file mode 100644 index 06725dcaf..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/ClassifierAdapterTests.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.springframework.batch.classify.ClassifierAdapter; -import org.springframework.batch.support.annotation.Classifier; - -/** - * @author Dave Syer - * - */ -public class ClassifierAdapterTests { - - private ClassifierAdapter adapter = new ClassifierAdapter(); - - @Test - public void testClassifierAdapterObject() { - adapter = new ClassifierAdapter(new Object() { - @SuppressWarnings("unused") - @Classifier - public Integer getValue(String key) { - return Integer.parseInt(key); - } - - @SuppressWarnings("unused") - public Integer getAnother(String key) { - throw new UnsupportedOperationException("Not allowed"); - } - }); - assertEquals(23, adapter.classify("23").intValue()); - } - - @Test(expected = IllegalStateException.class) - public void testClassifierAdapterObjectWithNoAnnotation() { - adapter = new ClassifierAdapter(new Object() { - @SuppressWarnings("unused") - public Integer getValue(String key) { - return Integer.parseInt(key); - } - - @SuppressWarnings("unused") - public Integer getAnother(String key) { - throw new UnsupportedOperationException("Not allowed"); - } - }); - assertEquals(23, adapter.classify("23").intValue()); - } - - @Test - public void testClassifierAdapterObjectSingleMethodWithNoAnnotation() { - adapter = new ClassifierAdapter(new Object() { - @SuppressWarnings("unused") - public Integer getValue(String key) { - return Integer.parseInt(key); - } - @SuppressWarnings("unused") - public void doNothing(String key) { - } - @SuppressWarnings("unused") - public String doNothing(String key, int value) { - return "foo"; - } - }); - assertEquals(23, adapter.classify("23").intValue()); - } - - @Test - public void testClassifierAdapterClassifier() { - adapter = new ClassifierAdapter( - new org.springframework.batch.classify.Classifier() { - public Integer classify(String classifiable) { - return Integer.valueOf(classifiable); - } - }); - assertEquals(23, adapter.classify("23").intValue()); - } - - @Test - public void testClassifyWithSetter() { - adapter.setDelegate(new Object() { - @SuppressWarnings("unused") - @Classifier - public Integer getValue(String key) { - return Integer.parseInt(key); - } - }); - assertEquals(23, adapter.classify("23").intValue()); - } - - @Test(expected=IllegalArgumentException.class) - public void testClassifyWithWrongType() { - adapter.setDelegate(new Object() { - @SuppressWarnings("unused") - @Classifier - public String getValue(Integer key) { - return key.toString(); - } - }); - assertEquals(23, adapter.classify("23").intValue()); - } - - @Test - public void testClassifyWithClassifier() { - adapter.setDelegate(new org.springframework.batch.classify.Classifier() { - public Integer classify(String classifiable) { - return Integer.valueOf(classifiable); - } - }); - assertEquals(23, adapter.classify("23").intValue()); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/ClassifierSupportTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/ClassifierSupportTests.java deleted file mode 100644 index c7fd1b3b8..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/ClassifierSupportTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.classify; - -import org.springframework.batch.classify.ClassifierSupport; - -import junit.framework.TestCase; - -public class ClassifierSupportTests extends TestCase { - - public void testClassifyNullIsDefault() { - ClassifierSupport classifier = new ClassifierSupport("foo"); - assertEquals(classifier.classify(null), "foo"); - } - - public void testClassifyRandomException() { - ClassifierSupport classifier = new ClassifierSupport("foo"); - assertEquals(classifier.classify(new IllegalStateException("Foo")), classifier.classify(null)); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/PatternMatchingClassifierTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/PatternMatchingClassifierTests.java deleted file mode 100644 index 6c475b982..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/PatternMatchingClassifierTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.classify; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.batch.classify.PatternMatchingClassifier; - -/** - * @author Dave Syer - * - */ -public class PatternMatchingClassifierTests { - - private PatternMatchingClassifier classifier = new PatternMatchingClassifier(); - - private Map map; - - @Before - public void createMap() { - map = new HashMap(); - map.put("foo", "bar"); - map.put("*", "spam"); - } - - @Test - public void testSetPatternMap() { - classifier.setPatternMap(map); - assertEquals("bar", classifier.classify("foo")); - assertEquals("spam", classifier.classify("bucket")); - } - - @Test - public void testCreateFromMap() { - classifier = new PatternMatchingClassifier(map); - assertEquals("bar", classifier.classify("foo")); - assertEquals("spam", classifier.classify("bucket")); - } - -} \ No newline at end of file diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/SubclassExceptionClassifierTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/SubclassExceptionClassifierTests.java deleted file mode 100644 index 696b6caa8..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/classify/SubclassExceptionClassifierTests.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.classify; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.Collections; -import java.util.HashMap; - -import org.junit.Test; -import org.springframework.batch.classify.SubclassClassifier; - -public class SubclassExceptionClassifierTests { - - SubclassClassifier classifier = new SubclassClassifier(); - - @Test - public void testClassifyNullIsDefault() { - assertEquals(classifier.classify(null), classifier.getDefault()); - } - - @Test - public void testClassifyNull() { - assertNull(classifier.classify(null)); - } - - @Test - public void testClassifyNullNonDefault() { - classifier = new SubclassClassifier("foo"); - assertEquals("foo", classifier.classify(null)); - } - - @Test - public void testClassifyRandomException() { - assertNull(classifier.classify(new IllegalStateException("Foo"))); - } - - @Test - public void testClassifyExactMatch() { - classifier.setTypeMap(Collections., String> singletonMap( - IllegalStateException.class, "foo")); - assertEquals("foo", classifier.classify(new IllegalStateException("Foo"))); - } - - @Test - public void testClassifySubclassMatch() { - classifier.setTypeMap(Collections., String> singletonMap(RuntimeException.class, - "foo")); - assertEquals("foo", classifier.classify(new IllegalStateException("Foo"))); - } - - @Test - public void testClassifySuperclassDoesNotMatch() { - classifier.setTypeMap(Collections., String> singletonMap( - IllegalStateException.class, "foo")); - assertEquals(classifier.getDefault(), classifier.classify(new RuntimeException("Foo"))); - } - - @Test - public void testClassifyAncestorMatch() { - classifier.setTypeMap(new HashMap, String>() { - { - put(Exception.class, "foo"); - put(IllegalArgumentException.class, "bar"); - put(RuntimeException.class, "spam"); - } - }); - assertEquals("spam", classifier.classify(new IllegalStateException("Foo"))); - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java index b45ae81ca..ead9b024b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java @@ -16,7 +16,7 @@ package org.springframework.batch.item; -import org.springframework.batch.retry.interceptor.MethodInvocationRecoverer; +import org.springframework.retry.interceptor.MethodInvocationRecoverer; import junit.framework.TestCase; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java index 22b21345b..fb98e624e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; import org.junit.Test; -import org.springframework.batch.classify.PatternMatchingClassifier; +import org.springframework.classify.PatternMatchingClassifier; import org.springframework.batch.item.ItemWriter; /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java index d6174b339..9d82bbdf7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java @@ -23,7 +23,7 @@ import junit.framework.TestCase; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.apache.log4j.WriterAppender; -import org.springframework.batch.classify.ClassifierSupport; +import org.springframework.classify.ClassifierSupport; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.exception.LogOrRethrowExceptionHandler.Level; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/AbstractExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/AbstractExceptionTests.java deleted file mode 100644 index 1112a0ae6..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/AbstractExceptionTests.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import junit.framework.TestCase; - -public abstract class AbstractExceptionTests extends TestCase { - - public void testExceptionString() throws Exception { - Exception exception = getException("foo"); - assertEquals("foo", exception.getMessage()); - } - - public void testExceptionStringThrowable() throws Exception { - Exception exception = getException("foo", new IllegalStateException()); - assertEquals("foo", exception.getMessage().substring(0, 3)); - } - - public abstract Exception getException(String msg) throws Exception; - - public abstract Exception getException(String msg, Throwable t) throws Exception; -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/BackOffInterruptedExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/BackOffInterruptedExceptionTests.java deleted file mode 100644 index 38e283fc1..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/BackOffInterruptedExceptionTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import org.springframework.batch.retry.backoff.BackOffInterruptedException; - -public class BackOffInterruptedExceptionTests extends AbstractExceptionTests { - - public Exception getException(String msg) throws Exception { - return new BackOffInterruptedException(msg); - } - - public Exception getException(String msg, Throwable t) throws Exception { - return new BackOffInterruptedException(msg, t); - } - - public void testNothing() throws Exception { - // fool coverage tools... - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/ExhaustedRetryExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/ExhaustedRetryExceptionTests.java deleted file mode 100644 index ad6023c87..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/ExhaustedRetryExceptionTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import org.springframework.batch.retry.ExhaustedRetryException; - -public class ExhaustedRetryExceptionTests extends AbstractExceptionTests { - - public Exception getException(String msg) throws Exception { - return new ExhaustedRetryException(msg); - } - - public Exception getException(String msg, Throwable t) throws Exception { - return new ExhaustedRetryException(msg, t); - } - - public void testNothing() throws Exception { - // fool coverage tools... - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/RetryExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/RetryExceptionTests.java deleted file mode 100644 index a8187316d..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/RetryExceptionTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import org.springframework.batch.retry.RetryException; - -public class RetryExceptionTests extends AbstractExceptionTests { - - public Exception getException(String msg) throws Exception { - return new RetryException(msg); - } - - public Exception getException(String msg, Throwable t) throws Exception { - return new RetryException(msg, t); - } - - public void testNothing() throws Exception { - // fool coverage tools... - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/TerminatedRetryExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/TerminatedRetryExceptionTests.java deleted file mode 100644 index 02df933a9..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/TerminatedRetryExceptionTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry; - -import org.springframework.batch.retry.TerminatedRetryException; - -public class TerminatedRetryExceptionTests extends AbstractExceptionTests { - - public Exception getException(String msg) throws Exception { - return new TerminatedRetryException(msg); - } - - public Exception getException(String msg, Throwable t) throws Exception { - return new TerminatedRetryException(msg, t); - } - - public void testNothing() throws Exception { - // fool coverage tools... - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/DummySleeper.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/DummySleeper.java deleted file mode 100644 index 277bba9eb..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/DummySleeper.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.backoff; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * Simple {@link Sleeper} implementation that just waits on a local Object. - * - * @author Dave Syer - * - */ -public class DummySleeper implements Sleeper { - - private List backOffs = new ArrayList(); - - /** - * Public getter for the long. - * @return the lastBackOff - */ - public long getLastBackOff() { - return backOffs.get(backOffs.size()-1).longValue(); - } - - public long[] getBackOffs() { - long[] result = new long[backOffs.size()]; - int i = 0; - for (Iterator iterator = backOffs.iterator(); iterator.hasNext();) { - Long value = iterator.next(); - result[i++] =value.longValue(); - } - return result ; - } - - /* - * (non-Javadoc) - * @see org.springframework.batch.retry.backoff.Sleeper#sleep(long) - */ - public void sleep(long backOffPeriod) throws InterruptedException { - this.backOffs.add(Long.valueOf(backOffPeriod)); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicyTests.java deleted file mode 100644 index 558d2bea5..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/ExponentialBackOffPolicyTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -import junit.framework.TestCase; - -/** - * @author Rob Harrop - * @author Dave Syer - */ -public class ExponentialBackOffPolicyTests extends TestCase { - - private DummySleeper sleeper = new DummySleeper(); - - public void testSetMaxInterval() throws Exception { - ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); - strategy.setMaxInterval(1000); - assertTrue(strategy.toString().indexOf("maxInterval=1000") >= 0); - strategy.setMaxInterval(0); - // The minimum value for the max interval is 1 - assertTrue(strategy.toString().indexOf("maxInterval=1") >= 0); - } - - public void testSetInitialInterval() throws Exception { - ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); - strategy.setInitialInterval(10000); - assertTrue(strategy.toString().indexOf("initialInterval=10000,") >= 0); - strategy.setInitialInterval(0); - assertTrue(strategy.toString().indexOf("initialInterval=1,") >= 0); - } - - public void testSetMultiplier() throws Exception { - ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); - strategy.setMultiplier(3.); - assertTrue(strategy.toString().indexOf("multiplier=3.") >= 0); - strategy.setMultiplier(.5); - assertTrue(strategy.toString().indexOf("multiplier=1.") >= 0); - } - - public void testSingleBackOff() throws Exception { - ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); - strategy.setSleeper(sleeper); - BackOffContext context = strategy.start(null); - strategy.backOff(context); - assertEquals(ExponentialBackOffPolicy.DEFAULT_INITIAL_INTERVAL, sleeper.getLastBackOff()); - } - - public void testMaximumBackOff() throws Exception { - ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); - strategy.setMaxInterval(50); - strategy.setSleeper(sleeper); - BackOffContext context = strategy.start(null); - strategy.backOff(context); - assertEquals(50, sleeper.getLastBackOff()); - } - - public void testMultiBackOff() throws Exception { - ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); - long seed = 40; - double multiplier = 1.2; - strategy.setInitialInterval(seed); - strategy.setMultiplier(multiplier); - strategy.setSleeper(sleeper); - BackOffContext context = strategy.start(null); - for (int x = 0; x < 5; x++) { - strategy.backOff(context); - assertEquals(seed, sleeper.getLastBackOff()); - seed *= multiplier; - } - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/FixedBackOffPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/FixedBackOffPolicyTests.java deleted file mode 100644 index dd84843bb..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/FixedBackOffPolicyTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -import junit.framework.TestCase; - -/** - * @author Rob Harrop - * @author Dave Syer - * @since 2.1 - */ -public class FixedBackOffPolicyTests extends TestCase { - - private DummySleeper sleeper = new DummySleeper(); - - public void testSetBackoffPeriodNegative() throws Exception { - FixedBackOffPolicy strategy = new FixedBackOffPolicy(); - strategy.setBackOffPeriod(-1000L); - strategy.setSleeper(sleeper); - strategy.backOff(null); - // We should see a zero backoff if we try to set it negative - assertEquals(1, sleeper.getBackOffs().length); - assertEquals(1, sleeper.getLastBackOff()); - } - - public void testSingleBackOff() throws Exception { - int backOffPeriod = 50; - FixedBackOffPolicy strategy = new FixedBackOffPolicy(); - strategy.setBackOffPeriod(backOffPeriod); - strategy.setSleeper(sleeper); - strategy.backOff(null); - assertEquals(1, sleeper.getBackOffs().length); - assertEquals(backOffPeriod, sleeper.getLastBackOff()); - } - - public void testManyBackOffCalls() throws Exception { - int backOffPeriod = 50; - FixedBackOffPolicy strategy = new FixedBackOffPolicy(); - strategy.setBackOffPeriod(backOffPeriod); - strategy.setSleeper(sleeper); - for (int x = 0; x < 10; x++) { - strategy.backOff(null); - assertEquals(backOffPeriod, sleeper.getLastBackOff()); - } - assertEquals(10, sleeper.getBackOffs().length); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/ObjectWaitSleeperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/ObjectWaitSleeperTests.java deleted file mode 100644 index 6c26511a9..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/backoff/ObjectWaitSleeperTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.backoff; - -import junit.framework.TestCase; - -/** - * @author Dave Syer - */ -public class ObjectWaitSleeperTests extends TestCase { - - public void testSingleBackOff() throws Exception { - long backOffPeriod = 50; - ObjectWaitSleeper strategy = new ObjectWaitSleeper(); - long before = System.currentTimeMillis(); - strategy.sleep(backOffPeriod); - long after = System.currentTimeMillis(); - assertEqualsApprox(backOffPeriod, after - before, 25); - } - - private void assertEqualsApprox(long desired, long actual, long variance) { - long lower = desired - variance; - long upper = desired + 2 * variance; - assertTrue("Expected value to be between '" + lower + "' and '" + upper + "' but was '" + actual + "'", - lower <= actual); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/interceptor/RetryOperationsInterceptorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/interceptor/RetryOperationsInterceptorTests.java deleted file mode 100644 index 8bb3bd300..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/interceptor/RetryOperationsInterceptorTests.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.interceptor; - -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import junit.framework.TestCase; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.framework.Advised; -import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.target.SingletonTargetSource; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; -import org.springframework.batch.retry.support.RetryTemplate; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.transaction.support.TransactionSynchronizationAdapter; -import org.springframework.transaction.support.TransactionSynchronizationManager; -import org.springframework.util.ClassUtils; - -public class RetryOperationsInterceptorTests extends TestCase { - - private RetryOperationsInterceptor interceptor; - - private Service service; - - private ServiceImpl target; - - private static int count; - - private static int transactionCount; - - protected void setUp() throws Exception { - super.setUp(); - interceptor = new RetryOperationsInterceptor(); - target = new ServiceImpl(); - service = (Service) ProxyFactory.getProxy(Service.class, new SingletonTargetSource(target)); - count = 0; - transactionCount = 0; - } - - public void testDefaultInterceptorSunnyDay() throws Exception { - ((Advised) service).addAdvice(interceptor); - service.service(); - assertEquals(2, count); - } - - public void testInterceptorChainWithRetry() throws Exception { - ((Advised) service).addAdvice(interceptor); - final List list = new ArrayList(); - ((Advised) service).addAdvice(new MethodInterceptor() { - public Object invoke(MethodInvocation invocation) throws Throwable { - list.add("chain"); - return invocation.proceed(); - } - }); - RetryTemplate template = new RetryTemplate(); - template.setRetryPolicy(new SimpleRetryPolicy(2, Collections - ., Boolean> singletonMap(Exception.class, true))); - interceptor.setRetryOperations(template); - service.service(); - assertEquals(2, count); - assertEquals(2, list.size()); - } - - public void testRetryExceptionAfterTooManyAttempts() throws Exception { - ((Advised) service).addAdvice(interceptor); - RetryTemplate template = new RetryTemplate(); - template.setRetryPolicy(new NeverRetryPolicy()); - interceptor.setRetryOperations(template); - try { - service.service(); - fail("Expected Exception."); - } - catch (Exception e) { - assertTrue(e.getMessage().startsWith("Not enough calls")); - } - assertEquals(1, count); - } - - public void testOutsideTransaction() throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(ClassUtils - .addResourcePathToPackagePath(getClass(), "retry-transaction-test.xml")); - Object object = context.getBean("bean"); - assertNotNull(object); - assertTrue(object instanceof Service); - Service bean = (Service) object; - bean.doTansactional(); - assertEquals(2, count); - // Expect 2 separate transactions... - assertEquals(2, transactionCount); - } - - public void testIllegalMethodInvocationType() throws Throwable { - try { - interceptor.invoke(new MethodInvocation() { - public Method getMethod() { - return null; - } - - public Object[] getArguments() { - return null; - } - - public AccessibleObject getStaticPart() { - return null; - } - - public Object getThis() { - return null; - } - - public Object proceed() throws Throwable { - return null; - } - }); - fail("IllegalStateException expected"); - } - catch (IllegalStateException e) { - assertTrue("Exception message should contain MethodInvocation: " + e.getMessage(), e.getMessage().indexOf( - "MethodInvocation") >= 0); - } - } - - public static interface Service { - void service() throws Exception; - - void doTansactional() throws Exception; - } - - public static class ServiceImpl implements Service { - - private boolean enteredTransaction = false; - - public void service() throws Exception { - count++; - if (count < 2) { - throw new Exception("Not enough calls: " + count); - } - } - - public void doTansactional() throws Exception { - if (TransactionSynchronizationManager.isActualTransactionActive() && !enteredTransaction) { - transactionCount++; - TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { - public void beforeCompletion() { - enteredTransaction = false; - } - }); - enteredTransaction = true; - } - count++; - if (count == 1) { - throw new RuntimeException("Rollback please"); - } - } - - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/interceptor/StatefulRetryOperationsInterceptorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/interceptor/StatefulRetryOperationsInterceptorTests.java deleted file mode 100644 index 714aaead0..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/interceptor/StatefulRetryOperationsInterceptorTests.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.interceptor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import junit.framework.TestCase; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.framework.Advised; -import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.target.SingletonTargetSource; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.policy.AlwaysRetryPolicy; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; -import org.springframework.batch.retry.support.RetryTemplate; - -/** - * @author Dave Syer - * - */ -public class StatefulRetryOperationsInterceptorTests extends TestCase { - - private StatefulRetryOperationsInterceptor interceptor; - - private RetryTemplate retryTemplate = new RetryTemplate(); - - private Service service; - - private Transformer transformer; - - private static int count; - - public void setUp() throws Exception { - interceptor = new StatefulRetryOperationsInterceptor(); - service = (Service) ProxyFactory.getProxy(Service.class, new SingletonTargetSource(new ServiceImpl())); - transformer = (Transformer) ProxyFactory.getProxy(Transformer.class, new SingletonTargetSource( - new TransformerImpl())); - count = 0; - } - - public void testDefaultInterceptorSunnyDay() throws Exception { - ((Advised) service).addAdvice(interceptor); - try { - service.service("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - } - - public void testDefaultTransformerInterceptorSunnyDay() throws Exception { - ((Advised) transformer).addAdvice(interceptor); - try { - transformer.transform("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - } - - public void testDefaultInterceptorAlwaysRetry() throws Exception { - retryTemplate.setRetryPolicy(new AlwaysRetryPolicy()); - interceptor.setRetryOperations(retryTemplate); - ((Advised) service).addAdvice(interceptor); - try { - service.service("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - } - - public void testInterceptorChainWithRetry() throws Exception { - ((Advised) service).addAdvice(interceptor); - final List list = new ArrayList(); - ((Advised) service).addAdvice(new MethodInterceptor() { - public Object invoke(MethodInvocation invocation) throws Throwable { - list.add("chain"); - return invocation.proceed(); - } - }); - interceptor.setRetryOperations(retryTemplate); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections - ., Boolean> singletonMap(Exception.class, true))); - try { - service.service("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - service.service("foo"); - assertEquals(2, count); - assertEquals(2, list.size()); - } - - public void testTransformerWithSuccessfulRetry() throws Exception { - ((Advised) transformer).addAdvice(interceptor); - interceptor.setRetryOperations(retryTemplate); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections - ., Boolean> singletonMap(Exception.class, true))); - try { - transformer.transform("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - Collection result = transformer.transform("foo"); - assertEquals(2, count); - assertEquals(1, result.size()); - } - - public void testRetryExceptionAfterTooManyAttemptsWithNoRecovery() throws Exception { - ((Advised) service).addAdvice(interceptor); - interceptor.setRetryOperations(retryTemplate); - retryTemplate.setRetryPolicy(new NeverRetryPolicy()); - try { - service.service("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - try { - service.service("foo"); - fail("Expected ExhaustedRetryException"); - } - catch (ExhaustedRetryException e) { - // expected - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Retry was exhausted but there was no recover")); - } - assertEquals(1, count); - } - - public void testRecoveryAfterTooManyAttempts() throws Exception { - ((Advised) service).addAdvice(interceptor); - interceptor.setRetryOperations(retryTemplate); - retryTemplate.setRetryPolicy(new NeverRetryPolicy()); - try { - service.service("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - interceptor.setRecoverer(new MethodInvocationRecoverer() { - public Object recover(Object[] data, Throwable cause) { - count++; - return null; - } - }); - service.service("foo"); - assertEquals(2, count); - } - - public void testTransformerRecoveryAfterTooManyAttempts() throws Exception { - ((Advised) transformer).addAdvice(interceptor); - interceptor.setRetryOperations(retryTemplate); - retryTemplate.setRetryPolicy(new NeverRetryPolicy()); - try { - transformer.transform("foo"); - fail("Expected Exception."); - } - catch (Exception e) { - String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Not enough calls")); - } - assertEquals(1, count); - interceptor.setRecoverer(new MethodInvocationRecoverer>() { - public Collection recover(Object[] data, Throwable cause) { - count++; - return Collections.singleton((String) data[0]); - } - }); - Collection result = transformer.transform("foo"); - assertEquals(2, count); - assertEquals(1, result.size()); - } - - public static interface Service { - void service(String in) throws Exception; - } - - public static class ServiceImpl implements Service { - - public void service(String in) throws Exception { - count++; - if (count < 2) { - throw new Exception("Not enough calls: " + count); - } - } - - } - - public static interface Transformer { - Collection transform(String in) throws Exception; - } - - public static class TransformerImpl implements Transformer { - - public Collection transform(String in) throws Exception { - count++; - if (count < 2) { - throw new Exception("Not enough calls: " + count); - } - return Collections.singleton(in + ":" + count); - } - - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/listener/RetryListenerSupportTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/listener/RetryListenerSupportTests.java deleted file mode 100644 index 142385269..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/listener/RetryListenerSupportTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.listener; - -import junit.framework.TestCase; - -public class RetryListenerSupportTests extends TestCase { - - public void testClose() { - RetryListenerSupport support = new RetryListenerSupport(); - try { - support.close(null, null, null); - } - catch (Exception e) { - fail("Unexpected exception"); - } - } - - public void testOnError() { - RetryListenerSupport support = new RetryListenerSupport(); - try { - support.onError(null, null, null); - } - catch (Exception e) { - fail("Unexpected exception"); - } - } - - public void testOpen() { - RetryListenerSupport support = new RetryListenerSupport(); - assertTrue(support.open(null, null)); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/listener/RetryListenerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/listener/RetryListenerTests.java deleted file mode 100644 index b73edf74b..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/listener/RetryListenerTests.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.listener; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryListener; -import org.springframework.batch.retry.TerminatedRetryException; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.support.RetryTemplate; - -public class RetryListenerTests extends TestCase { - - RetryTemplate template = new RetryTemplate(); - - int count = 0; - - List list = new ArrayList(); - - public void testOpenInterceptors() throws Exception { - template.setListeners(new RetryListener[] { new RetryListenerSupport() { - public boolean open(RetryContext context, RetryCallback callback) { - count++; - list.add("1:" + count); - return true; - } - }, new RetryListenerSupport() { - public boolean open(RetryContext context, RetryCallback callback) { - count++; - list.add("2:" + count); - return true; - } - } }); - template.execute(new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - return null; - } - }); - assertEquals(2, count); - assertEquals(2, list.size()); - assertEquals("1:1", list.get(0)); - } - - public void testOpenCanVetoRetry() throws Exception { - template.registerListener(new RetryListenerSupport() { - public boolean open(RetryContext context, RetryCallback callback) { - list.add("1"); - return false; - } - }); - try { - template.execute(new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - count++; - return null; - } - }); - fail("Expected TerminatedRetryException"); - } - catch (TerminatedRetryException e) { - // expected - } - assertEquals(0, count); - assertEquals(1, list.size()); - assertEquals("1", list.get(0)); - } - - public void testCloseInterceptors() throws Exception { - template.setListeners(new RetryListener[] { new RetryListenerSupport() { - public void close(RetryContext context, RetryCallback callback, Throwable t) { - count++; - list.add("1:" + count); - } - }, new RetryListenerSupport() { - public void close(RetryContext context, RetryCallback callback, Throwable t) { - count++; - list.add("2:" + count); - } - } }); - template.execute(new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - return null; - } - }); - assertEquals(2, count); - assertEquals(2, list.size()); - // interceptors are called in reverse order on close... - assertEquals("2:1", list.get(0)); - } - - public void testOnError() throws Exception { - template.setRetryPolicy(new NeverRetryPolicy()); - template.setListeners(new RetryListener[] { new RetryListenerSupport() { - public void onError(RetryContext context, RetryCallback callback, Throwable throwable) { - list.add("1"); - } - }, new RetryListenerSupport() { - public void onError(RetryContext context, RetryCallback callback, Throwable throwable) { - list.add("2"); - } - } }); - try { - template.execute(new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - count++; - throw new IllegalStateException("foo"); - } - }); - fail("Expected IllegalStateException"); - } - catch (IllegalStateException e) { - assertEquals("foo", e.getMessage()); - } - // never retry so callback is executed once - assertEquals(1, count); - assertEquals(2, list.size()); - // interceptors are called in reverse order on error... - assertEquals("2", list.get(0)); - - } - - public void testCloseInterceptorsAfterRetry() throws Exception { - template.registerListener(new RetryListenerSupport() { - public void close(RetryContext context, RetryCallback callback, Throwable t) { - list.add("" + count); - // The last attempt should have been successful: - assertNull(t); - } - }); - template.execute(new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - if (count++ < 1) - throw new RuntimeException("Retry!"); - return null; - } - }); - assertEquals(2, count); - // The close interceptor was only called once: - assertEquals(1, list.size()); - // We succeeded on the second try: - assertEquals("2", list.get(0)); - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/AlwaysRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/AlwaysRetryPolicyTests.java deleted file mode 100644 index 68735c783..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/AlwaysRetryPolicyTests.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import junit.framework.TestCase; - -import org.springframework.batch.retry.RetryContext; - -public class AlwaysRetryPolicyTests extends TestCase { - - public void testSimpleOperations() throws Exception { - AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - assertTrue(policy.canRetry(context)); - policy.registerThrowable(context, null); - assertTrue(policy.canRetry(context)); - policy.close(context); - assertTrue(policy.canRetry(context)); - } - - public void testRetryCount() throws Exception { - AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.registerThrowable(context, null); - assertEquals(0, context.getRetryCount()); - policy.registerThrowable(context, new RuntimeException("foo")); - assertEquals(1, context.getRetryCount()); - assertEquals("foo", context.getLastThrowable().getMessage()); - } - - public void testParent() throws Exception { - AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null); - RetryContext child = policy.open(context); - assertNotSame(child, context); - assertSame(context, child.getParent()); - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/CompositeRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/CompositeRetryPolicyTests.java deleted file mode 100644 index 99e9d4afd..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/CompositeRetryPolicyTests.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; - -public class CompositeRetryPolicyTests extends TestCase { - - public void testEmptyPolicies() throws Exception { - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - assertTrue(policy.canRetry(context)); - } - - public void testTrivialPolicies() throws Exception { - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() }); - RetryContext context = policy.open(null); - assertNotNull(context); - assertTrue(policy.canRetry(context)); - } - - public void testNonTrivialPolicies() throws Exception { - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() { - public boolean canRetry(RetryContext context) { - return false; - } - } }); - RetryContext context = policy.open(null); - assertNotNull(context); - assertFalse(policy.canRetry(context)); - } - - public void testNonTrivialPoliciesWithThrowable() throws Exception { - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() { - boolean errorRegistered = false; - - public boolean canRetry(RetryContext context) { - return !errorRegistered; - } - - public void registerThrowable(RetryContext context, Throwable throwable) { - errorRegistered = true; - } - } }); - RetryContext context = policy.open(null); - assertNotNull(context); - assertTrue(policy.canRetry(context)); - policy.registerThrowable(context, null); - assertFalse("Should be still able to retry", policy.canRetry(context)); - } - - public void testNonTrivialPoliciesClose() throws Exception { - final List list = new ArrayList(); - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport() { - public void close(RetryContext context) { - list.add("1"); - } - }, new MockRetryPolicySupport() { - public void close(RetryContext context) { - list.add("2"); - } - } }); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.close(context); - assertEquals(2, list.size()); - } - - public void testExceptionOnPoliciesClose() throws Exception { - final List list = new ArrayList(); - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport() { - public void close(RetryContext context) { - list.add("1"); - throw new RuntimeException("Pah!"); - } - }, new MockRetryPolicySupport() { - public void close(RetryContext context) { - list.add("2"); - } - } }); - RetryContext context = policy.open(null); - assertNotNull(context); - try { - policy.close(context); - fail("Expected RuntimeException"); - } catch (RuntimeException e) { - assertEquals("Pah!", e.getMessage()); - } - assertEquals(2, list.size()); - } - - public void testRetryCount() throws Exception { - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() }); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.registerThrowable(context, null); - assertEquals(0, context.getRetryCount()); - policy.registerThrowable(context, new RuntimeException("foo")); - assertEquals(1, context.getRetryCount()); - assertEquals("foo", context.getLastThrowable().getMessage()); - } - - public void testParent() throws Exception { - CompositeRetryPolicy policy = new CompositeRetryPolicy(); - RetryContext context = policy.open(null); - RetryContext child = policy.open(context); - assertNotSame(child, context); - assertSame(context, child.getParent()); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ExceptionClassifierRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ExceptionClassifierRetryPolicyTests.java deleted file mode 100644 index d0edb6d90..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ExceptionClassifierRetryPolicyTests.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import java.util.Collections; -import java.util.HashMap; -import junit.framework.TestCase; - -import org.springframework.batch.classify.Classifier; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryPolicy; - -public class ExceptionClassifierRetryPolicyTests extends TestCase { - - private ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); - - public void testDefaultPolicies() throws Exception { - RetryContext context = policy.open(null); - assertNotNull(context); - } - - public void testTrivialPolicies() throws Exception { - policy.setPolicyMap(Collections., RetryPolicy> singletonMap(Exception.class, - new MockRetryPolicySupport())); - RetryContext context = policy.open(null); - assertNotNull(context); - assertTrue(policy.canRetry(context)); - } - - public void testNullPolicies() throws Exception { - policy.setPolicyMap(new HashMap, RetryPolicy>()); - RetryContext context = policy.open(null); - assertNotNull(context); - } - - public void testNullContext() throws Exception { - policy.setPolicyMap(Collections., RetryPolicy> singletonMap(Exception.class, - new NeverRetryPolicy())); - - RetryContext context = policy.open(null); - assertNotNull(context); - - assertTrue(policy.canRetry(context)); - } - - public void testClassifierOperates() throws Exception { - - RetryContext context = policy.open(null); - assertNotNull(context); - - assertTrue(policy.canRetry(context)); - policy.registerThrowable(context, new IllegalArgumentException()); - assertFalse(policy.canRetry(context)); // NeverRetryPolicy is the - // default - - policy.setExceptionClassifier(new Classifier() { - public RetryPolicy classify(Throwable throwable) { - if (throwable != null) { - return new AlwaysRetryPolicy(); - } - return new NeverRetryPolicy(); - } - }); - - // The context saves the classifier, so changing it now has no effect - assertFalse(policy.canRetry(context)); - policy.registerThrowable(context, new IllegalArgumentException()); - assertFalse(policy.canRetry(context)); - - // But now the classifier will be active in the new context... - context = policy.open(null); - assertTrue(policy.canRetry(context)); - policy.registerThrowable(context, new IllegalArgumentException()); - assertTrue(policy.canRetry(context)); - - } - - int count = 0; - - public void testClose() throws Exception { - policy.setExceptionClassifier(new Classifier() { - public RetryPolicy classify(Throwable throwable) { - return new MockRetryPolicySupport() { - public void close(RetryContext context) { - count++; - } - }; - } - }); - RetryContext context = policy.open(null); - - // The mapped (child) policy hasn't been used yet, so if we close now - // we don't incur the possible expense of creating the child context. - policy.close(context); - assertEquals(0, count); // not classified yet - // This forces a child context to be created and the child policy is - // then closed - policy.registerThrowable(context, new IllegalStateException()); - policy.close(context); - assertEquals(1, count); // now classified - } - - public void testRetryCount() throws Exception { - ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.registerThrowable(context, null); - assertEquals(0, context.getRetryCount()); - policy.registerThrowable(context, new RuntimeException("foo")); - assertEquals(1, context.getRetryCount()); - assertEquals("foo", context.getLastThrowable().getMessage()); - } - - public void testParent() throws Exception { - ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); - RetryContext context = policy.open(null); - RetryContext child = policy.open(context); - assertNotSame(child, context); - assertSame(context, child.getParent()); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/FatalExceptionRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/FatalExceptionRetryPolicyTests.java deleted file mode 100644 index 6650f7d1a..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/FatalExceptionRetryPolicyTests.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.DefaultRetryState; -import org.springframework.batch.retry.support.RetryTemplate; - -public class FatalExceptionRetryPolicyTests extends TestCase { - - public void testFatalExceptionWithoutState() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - callback.setExceptionToThrow(new IllegalArgumentException()); - - RetryTemplate retryTemplate = new RetryTemplate(); - - // Make sure certain exceptions are fatal... - Map, Boolean> map = new HashMap, Boolean>(); - map.put(IllegalArgumentException.class, false); - map.put(IllegalStateException.class, false); - - // ... and allow multiple attempts - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, map); - retryTemplate.setRetryPolicy(policy); - RecoveryCallback recoveryCallback = new RecoveryCallback() { - public String recover(RetryContext context) throws Exception { - return "bar"; - } - }; - - Object result = null; - try { - result = retryTemplate.execute(callback, recoveryCallback); - } - catch (IllegalArgumentException e) { - // We should swallow the exception when recovery is possible - fail("Did not expect IllegalArgumentException"); - } - // Callback is called once: the recovery path should also be called - assertEquals(1, callback.attempts); - assertEquals("bar", result); - } - - public void testFatalExceptionWithState() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - callback.setExceptionToThrow(new IllegalArgumentException()); - - RetryTemplate retryTemplate = new RetryTemplate(); - - Map, Boolean> map = new HashMap, Boolean>(); - map.put(IllegalArgumentException.class, false); - map.put(IllegalStateException.class, false); - - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, map); - retryTemplate.setRetryPolicy(policy); - - RecoveryCallback recoveryCallback = new RecoveryCallback() { - public String recover(RetryContext context) throws Exception { - return "bar"; - } - }; - - Object result = null; - try { - retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState("foo")); - fail("Expected IllegalArgumentException"); - } - catch (IllegalArgumentException e) { - // If stateful we have to always rethrow. Clients who want special - // cases have to implement them in the callback - } - result = retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState("foo")); - // Callback is called once: the recovery path should also be called - assertEquals(1, callback.attempts); - assertEquals("bar", result); - } - - private static class MockRetryCallback implements RetryCallback { - - private int attempts; - - private Exception exceptionToThrow = new Exception(); - - public String doWithRetry(RetryContext context) throws Exception { - this.attempts++; - // Just barf... - throw this.exceptionToThrow; - } - - public void setExceptionToThrow(Exception exceptionToThrow) { - this.exceptionToThrow = exceptionToThrow; - } - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/MapRetryContextCacheTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/MapRetryContextCacheTests.java deleted file mode 100644 index 6315977e4..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/MapRetryContextCacheTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.springframework.batch.retry.context.RetryContextSupport; - -public class MapRetryContextCacheTests { - - MapRetryContextCache cache = new MapRetryContextCache(); - - @Test - public void testPut() { - RetryContextSupport context = new RetryContextSupport(null); - cache.put("foo", context); - assertEquals(context, cache.get("foo")); - } - - @Test(expected=RetryCacheCapacityExceededException.class) - public void testPutOverLimit() { - RetryContextSupport context = new RetryContextSupport(null); - cache.setCapacity(1); - cache.put("foo", context); - cache.put("foo", context); - } - - @Test - public void testRemove() { - assertFalse(cache.containsKey("foo")); - RetryContextSupport context = new RetryContextSupport(null); - cache.put("foo", context); - assertTrue(cache.containsKey("foo")); - cache.remove("foo"); - assertFalse(cache.containsKey("foo")); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/MockRetryPolicySupport.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/MockRetryPolicySupport.java deleted file mode 100644 index c89ce1893..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/MockRetryPolicySupport.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -public class MockRetryPolicySupport extends AlwaysRetryPolicy { - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/NeverRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/NeverRetryPolicyTests.java deleted file mode 100644 index e2ea04ebd..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/NeverRetryPolicyTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import junit.framework.TestCase; - -import org.springframework.batch.retry.RetryContext; - -public class NeverRetryPolicyTests extends TestCase { - - public void testSimpleOperations() throws Exception { - NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - // We can retry until the first exception is registered... - assertTrue(policy.canRetry(context)); - assertTrue(policy.canRetry(context)); - policy.registerThrowable(context, null); - assertFalse(policy.canRetry(context)); - policy.close(context); - assertFalse(policy.canRetry(context)); - } - - public void testRetryCount() throws Exception { - NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.registerThrowable(context, null); - assertEquals(0, context.getRetryCount()); - policy.registerThrowable(context, new RuntimeException("foo")); - assertEquals(1, context.getRetryCount()); - assertEquals("foo", context.getLastThrowable().getMessage()); - } - - public void testParent() throws Exception { - NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null); - RetryContext child = policy.open(context); - assertNotSame(child, context); - assertSame(context, child.getParent()); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SimpleRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SimpleRetryPolicyTests.java deleted file mode 100644 index 3e8bb3db4..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SimpleRetryPolicyTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.springframework.batch.retry.RetryContext; - -public class SimpleRetryPolicyTests { - - @Test - public void testCanRetryIfNoException() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); - assertTrue(policy.canRetry(context)); - } - - @Test - public void testEmptyExceptionsNeverRetry() throws Exception { - - // We can't retry any exceptions... - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, Collections - ., Boolean> emptyMap()); - RetryContext context = policy.open(null); - - // ...so we can't retry this one... - policy.registerThrowable(context, new IllegalStateException()); - assertFalse(policy.canRetry(context)); - } - - @Test - public void testRetryLimitInitialState() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); - assertTrue(policy.canRetry(context)); - policy.setMaxAttempts(0); - context = policy.open(null); - assertFalse(policy.canRetry(context)); - } - - @Test - public void testRetryLimitSubsequentState() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); - policy.setMaxAttempts(2); - assertTrue(policy.canRetry(context)); - policy.registerThrowable(context, new Exception()); - assertTrue(policy.canRetry(context)); - policy.registerThrowable(context, new Exception()); - assertFalse(policy.canRetry(context)); - } - - @Test - public void testRetryCount() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.registerThrowable(context, null); - assertEquals(0, context.getRetryCount()); - policy.registerThrowable(context, new RuntimeException("foo")); - assertEquals(1, context.getRetryCount()); - assertEquals("foo", context.getLastThrowable().getMessage()); - } - - @Test - public void testFatalOverridesRetryable() throws Exception { - Map, Boolean> map = new HashMap, Boolean>(); - map.put(Exception.class, false); - map.put(RuntimeException.class, true); - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, map); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.registerThrowable(context, new RuntimeException("foo")); - assertTrue(policy.canRetry(context)); - } - - @Test - public void testParent() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); - RetryContext child = policy.open(context); - assertNotSame(child, context); - assertSame(context, child.getParent()); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SoftReferenceMapRetryContextCacheTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SoftReferenceMapRetryContextCacheTests.java deleted file mode 100644 index 25dbb0983..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SoftReferenceMapRetryContextCacheTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.springframework.batch.retry.context.RetryContextSupport; - -public class SoftReferenceMapRetryContextCacheTests { - - SoftReferenceMapRetryContextCache cache = new SoftReferenceMapRetryContextCache(); - - @Test - public void testPut() { - RetryContextSupport context = new RetryContextSupport(null); - cache.put("foo", context); - assertEquals(context, cache.get("foo")); - } - - @Test(expected=RetryCacheCapacityExceededException.class) - public void testPutOverLimit() { - RetryContextSupport context = new RetryContextSupport(null); - cache.setCapacity(1); - cache.put("foo", context); - cache.put("foo", context); - } - - @Test - public void testRemove() { - assertFalse(cache.containsKey("foo")); - RetryContextSupport context = new RetryContextSupport(null); - cache.put("foo", context); - assertTrue(cache.containsKey("foo")); - cache.remove("foo"); - assertFalse(cache.containsKey("foo")); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/StatefulRetryIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/StatefulRetryIntegrationTests.java deleted file mode 100644 index 995437d48..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/StatefulRetryIntegrationTests.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.policy; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.Collections; - -import org.junit.Test; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RetryState; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.DefaultRetryState; -import org.springframework.batch.retry.support.RetryTemplate; - -/** - * @author Dave Syer - * - */ -public class StatefulRetryIntegrationTests { - - @Test - public void testExternalRetryWithFailAndNoRetry() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - - RetryState retryState = new DefaultRetryState("foo"); - - RetryTemplate retryTemplate = new RetryTemplate(); - MapRetryContextCache cache = new MapRetryContextCache(); - retryTemplate.setRetryContextCache(cache); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections - ., Boolean> singletonMap(Exception.class, true))); - - assertFalse(cache.containsKey("foo")); - - try { - retryTemplate.execute(callback, retryState); - // The first failed attempt we expect to retry... - fail("Expected RuntimeException"); - } - catch (RuntimeException e) { - assertEquals(null, e.getMessage()); - } - - assertTrue(cache.containsKey("foo")); - - try { - retryTemplate.execute(callback, retryState); - // We don't get a second attempt... - fail("Expected ExhaustedRetryException"); - } - catch (ExhaustedRetryException e) { - // This is now the "exhausted" message: - assertNotNull(e.getMessage()); - } - - assertFalse(cache.containsKey("foo")); - - // Callback is called once: the recovery path should be called in - // handleRetryExhausted (so not in this test)... - assertEquals(1, callback.attempts); - } - - @Test - public void testExternalRetryWithSuccessOnRetry() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - - RetryState retryState = new DefaultRetryState("foo"); - - RetryTemplate retryTemplate = new RetryTemplate(); - MapRetryContextCache cache = new MapRetryContextCache(); - retryTemplate.setRetryContextCache(cache); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections - ., Boolean> singletonMap(Exception.class, true))); - - assertFalse(cache.containsKey("foo")); - - Object result = "start_foo"; - try { - result = retryTemplate.execute(callback, retryState); - // The first failed attempt we expect to retry... - fail("Expected RuntimeException"); - } - catch (RuntimeException e) { - assertNull(e.getMessage()); - } - - assertTrue(cache.containsKey("foo")); - - result = retryTemplate.execute(callback, retryState); - - assertFalse(cache.containsKey("foo")); - - assertEquals(2, callback.attempts); - assertEquals("bar", result); - } - - /** - * @author Dave Syer - * - */ - private static final class MockRetryCallback implements RetryCallback { - int attempts = 0; - - public String doWithRetry(RetryContext context) throws Exception { - attempts++; - if (attempts < 2) { - throw new RuntimeException(); - } - return "bar"; - } - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/TimeoutRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/TimeoutRetryPolicyTests.java deleted file mode 100644 index cce4cb0d4..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/TimeoutRetryPolicyTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.policy; - -import junit.framework.TestCase; - -import org.springframework.batch.retry.RetryContext; - -public class TimeoutRetryPolicyTests extends TestCase { - - public void testTimeoutPreventsRetry() throws Exception { - TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); - policy.setTimeout(100); - RetryContext context = policy.open(null); - policy.registerThrowable(context, new Exception()); - assertTrue(policy.canRetry(context)); - Thread.sleep(200); - assertFalse(policy.canRetry(context)); - policy.close(context); - } - - public void testRetryCount() throws Exception { - TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); - RetryContext context = policy.open(null); - assertNotNull(context); - policy.registerThrowable(context, null); - assertEquals(0, context.getRetryCount()); - policy.registerThrowable(context, new RuntimeException("foo")); - assertEquals(1, context.getRetryCount()); - assertEquals("foo", context.getLastThrowable().getMessage()); - } - - public void testParent() throws Exception { - TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); - RetryContext context = policy.open(null); - RetryContext child = policy.open(context); - assertNotSame(child, context); - assertSame(context, child.getParent()); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/DefaultRetryStateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/DefaultRetryStateTests.java deleted file mode 100644 index 7e745663e..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/DefaultRetryStateTests.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.retry.support; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.springframework.batch.classify.Classifier; - -/** - * @author Dave Syer - * - */ -public class DefaultRetryStateTests { - - /** - * Test method for - * {@link org.springframework.batch.retry.support.DefaultRetryState#DefaultRetryState(java.lang.Object, boolean, org.springframework.batch.classify.Classifier)}. - */ - @Test - public void testDefaultRetryStateObjectBooleanClassifierOfQsuperThrowableBoolean() { - DefaultRetryState state = new DefaultRetryState("foo", true, new Classifier() { - public Boolean classify(Throwable classifiable) { - return false; - } - }); - assertEquals("foo", state.getKey()); - assertTrue(state.isForceRefresh()); - assertFalse(state.rollbackFor(null)); - } - - /** - * Test method for - * {@link org.springframework.batch.retry.support.DefaultRetryState#DefaultRetryState(java.lang.Object, org.springframework.batch.classify.Classifier)}. - */ - @Test - public void testDefaultRetryStateObjectClassifierOfQsuperThrowableBoolean() { - DefaultRetryState state = new DefaultRetryState("foo", new Classifier() { - public Boolean classify(Throwable classifiable) { - return false; - } - }); - assertEquals("foo", state.getKey()); - assertFalse(state.isForceRefresh()); - assertFalse(state.rollbackFor(null)); - } - - /** - * Test method for - * {@link org.springframework.batch.retry.support.DefaultRetryState#DefaultRetryState(java.lang.Object, boolean)}. - */ - @Test - public void testDefaultRetryStateObjectBoolean() { - DefaultRetryState state = new DefaultRetryState("foo", true); - assertEquals("foo", state.getKey()); - assertTrue(state.isForceRefresh()); - assertTrue(state.rollbackFor(null)); - } - - /** - * Test method for - * {@link org.springframework.batch.retry.support.DefaultRetryState#DefaultRetryState(java.lang.Object)}. - */ - @Test - public void testDefaultRetryStateObject() { - DefaultRetryState state = new DefaultRetryState("foo"); - assertEquals("foo", state.getKey()); - assertFalse(state.isForceRefresh()); - assertTrue(state.rollbackFor(null)); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetrySynchronizationManagerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetrySynchronizationManagerTests.java deleted file mode 100644 index 75c721497..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetrySynchronizationManagerTests.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.support; - -import junit.framework.TestCase; - -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.context.RetryContextSupport; - -/** - * @author Dave Syer - */ -public class RetrySynchronizationManagerTests extends TestCase { - - RetryTemplate template = new RetryTemplate(); - - protected void setUp() throws Exception { - super.setUp(); - RetrySynchronizationManagerTests.clearAll(); - RetryContext status = RetrySynchronizationManager.getContext(); - assertNull(status); - } - - public void testStatusIsStoredByTemplate() throws Exception { - - RetryContext status = RetrySynchronizationManager.getContext(); - assertNull(status); - - template.execute(new RetryCallback() { - public Object doWithRetry(RetryContext status) throws Exception { - RetryContext global = RetrySynchronizationManager.getContext(); - assertNotNull(status); - assertEquals(global, status); - return null; - } - }); - - status = RetrySynchronizationManager.getContext(); - assertNull(status); - } - - public void testStatusRegistration() throws Exception { - RetryContext status = new RetryContextSupport(null); - RetryContext value = RetrySynchronizationManager.register(status); - assertNull(value); - value = RetrySynchronizationManager.register(status); - assertEquals(status, value); - } - - public void testClear() throws Exception { - RetryContext status = new RetryContextSupport(null); - RetryContext value = RetrySynchronizationManager.register(status); - assertNull(value); - RetrySynchronizationManager.clear(); - value = RetrySynchronizationManager.register(status); - assertNull(value); - } - - public void testParent() throws Exception { - RetryContext parent = new RetryContextSupport(null); - RetryContext child = new RetryContextSupport(parent); - assertSame(parent, child.getParent()); - } - - /** - * Clear all contexts starting with the current one and continuing until - * {@link RetrySynchronizationManager#clear()} returns null. - */ - public static RetryContext clearAll() { - RetryContext result = null; - RetryContext context = RetrySynchronizationManager.clear(); - while (context != null) { - result = context; - context = RetrySynchronizationManager.clear(); - } - return result; - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java deleted file mode 100644 index 78c23cd4b..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.support; - -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; - -import java.util.Collections; - -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.batch.classify.BinaryExceptionClassifier; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.backoff.BackOffContext; -import org.springframework.batch.retry.backoff.BackOffInterruptedException; -import org.springframework.batch.retry.backoff.BackOffPolicy; -import org.springframework.batch.retry.backoff.StatelessBackOffPolicy; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; - -/** - * @author Rob Harrop - * @author Dave Syer - */ -public class RetryTemplateTests { - - RetryContext context; - - int count = 0; - - @Test - public void testSuccessfulRetry() throws Exception { - for (int x = 1; x <= 10; x++) { - MockRetryCallback callback = new MockRetryCallback(); - callback.setAttemptsBeforeSuccess(x); - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x, Collections - ., Boolean> singletonMap( - Exception.class, true))); - retryTemplate.execute(callback); - assertEquals(x, callback.attempts); - } - } - - @Test - public void testSuccessfulRecovery() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - callback.setAttemptsBeforeSuccess(3); - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections - ., Boolean> singletonMap( - Exception.class, true))); - final Object value = new Object(); - Object result = retryTemplate.execute(callback, - new RecoveryCallback() { - public Object recover(RetryContext context) - throws Exception { - return value; - } - }); - assertEquals(2, callback.attempts); - assertEquals(value, result); - } - - @Test - public void testAlwaysTryAtLeastOnce() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new NeverRetryPolicy()); - retryTemplate.execute(callback); - assertEquals(1, callback.attempts); - } - - @Test - public void testNoSuccessRetry() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - // Something that won't be thrown by JUnit... - callback.setExceptionToThrow(new IllegalArgumentException()); - callback.setAttemptsBeforeSuccess(Integer.MAX_VALUE); - RetryTemplate retryTemplate = new RetryTemplate(); - int retryAttempts = 2; - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(retryAttempts, - Collections., Boolean> singletonMap( - Exception.class, true))); - try { - retryTemplate.execute(callback); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - assertNotNull(e); - assertEquals(retryAttempts, callback.attempts); - return; - } - fail("Expected IllegalArgumentException"); - } - - @Test - public void testDefaultConfigWithExceptionSubclass() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - int attempts = 3; - callback.setAttemptsBeforeSuccess(attempts); - callback.setExceptionToThrow(new IllegalArgumentException()); - - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(attempts, - Collections., Boolean> singletonMap( - Exception.class, true))); - retryTemplate.execute(callback); - assertEquals(attempts, callback.attempts); - } - - @Test - public void testRollbackClassifierOverridesRetryPolicy() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - int attempts = 3; - callback.setAttemptsBeforeSuccess(attempts); - callback.setExceptionToThrow(new IllegalArgumentException()); - - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(attempts, - Collections., Boolean> singletonMap( - Exception.class, true))); - BinaryExceptionClassifier classifier = new BinaryExceptionClassifier( - Collections - .> singleton(IllegalArgumentException.class), - false); - retryTemplate.execute(callback, - new DefaultRetryState("foo", classifier)); - assertEquals(attempts, callback.attempts); - } - - @Test - public void testSetExceptions() throws Exception { - RetryTemplate template = new RetryTemplate(); - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, - Collections., Boolean> singletonMap( - RuntimeException.class, true)); - template.setRetryPolicy(policy); - - int attempts = 3; - - MockRetryCallback callback = new MockRetryCallback(); - callback.setAttemptsBeforeSuccess(attempts); - - try { - template.execute(callback); - } catch (Exception e) { - assertNotNull(e); - assertEquals(1, callback.attempts); - } - callback.setExceptionToThrow(new RuntimeException()); - - template.execute(callback); - assertEquals(attempts, callback.attempts); - } - - @Test - public void testBackOffInvoked() throws Exception { - for (int x = 1; x <= 10; x++) { - MockRetryCallback callback = new MockRetryCallback(); - MockBackOffStrategy backOff = new MockBackOffStrategy(); - callback.setAttemptsBeforeSuccess(x); - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setBackOffPolicy(backOff); - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x, Collections - ., Boolean> singletonMap( - Exception.class, true))); - retryTemplate.execute(callback); - assertEquals(x, callback.attempts); - assertEquals(1, backOff.startCalls); - assertEquals(x - 1, backOff.backOffCalls); - } - } - - @Test - public void testEarlyTermination() throws Exception { - try { - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.execute(new RetryCallback() { - public Object doWithRetry(RetryContext status) throws Exception { - status.setExhaustedOnly(); - throw new IllegalStateException("Retry this operation"); - } - }); - fail("Expected ExhaustedRetryException"); - } catch (ExhaustedRetryException ex) { - // Expected for internal retry policy (external would recover - // gracefully) - assertEquals("Retry this operation", ex.getCause().getMessage()); - } - } - - @Test - public void testNestedContexts() throws Exception { - RetryTemplate outer = new RetryTemplate(); - final RetryTemplate inner = new RetryTemplate(); - outer.execute(new RetryCallback() { - public Object doWithRetry(RetryContext status) throws Exception { - context = status; - count++; - Object result = inner.execute(new RetryCallback() { - public Object doWithRetry(RetryContext status) - throws Exception { - count++; - assertNotNull(context); - assertNotSame(status, context); - assertSame(context, status.getParent()); - assertSame("The context should be the child", status, - RetrySynchronizationManager.getContext()); - return null; - } - }); - assertSame("The context should be restored", status, - RetrySynchronizationManager.getContext()); - return result; - } - }); - assertEquals(2, count); - } - - @Test - public void testRethrowError() throws Exception { - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new NeverRetryPolicy()); - try { - retryTemplate.execute(new RetryCallback() { - public Object doWithRetry(RetryContext context) - throws Exception { - throw new Error("Realllly bad!"); - } - }); - fail("Expected Error"); - } catch (Error e) { - assertEquals("Realllly bad!", e.getMessage()); - } - } - - @Test - public void testBackOffInterrupted() throws Exception { - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setBackOffPolicy(new StatelessBackOffPolicy() { - protected void doBackOff() throws BackOffInterruptedException { - throw new BackOffInterruptedException("foo"); - } - }); - try { - retryTemplate.execute(new RetryCallback() { - public Object doWithRetry(RetryContext context) - throws Exception { - throw new RuntimeException("Bad!"); - } - }); - fail("Expected RuntimeException"); - } catch (BackOffInterruptedException e) { - assertEquals("foo", e.getMessage()); - } - } - - /** - * {@link BackOffPolicy} should apply also for exceptions that are - * re-thrown. - */ - @Test - public void testNoBackOffForRethrownException() throws Exception { - - RetryTemplate tested = new RetryTemplate(); - tested.setRetryPolicy(new SimpleRetryPolicy(1, Collections - ., Boolean> singletonMap( - Exception.class, true))); - - BackOffPolicy bop = createStrictMock(BackOffPolicy.class); - BackOffContext backOffContext = new BackOffContext() { - }; - tested.setBackOffPolicy(bop); - - expect(bop.start(isA(RetryContext.class))).andReturn(backOffContext); - replay(bop); - - DefaultRetryState state = new DefaultRetryState(tested) { - - @Override - public boolean rollbackFor(Throwable exception) { - return true; - } - - }; - - RetryCallback callback = new RetryCallback() { - - public Object doWithRetry(RetryContext context) throws Exception { - throw new Exception("maybe next time!"); - } - - }; - - try { - tested.execute(callback, null, state); - fail(); - } catch (Exception expected) { - assertEquals("maybe next time!", expected.getMessage()); - } - - verify(bop); - } - - /** - * {@link BackOffPolicy} should be saved between invocations for a stateful - * execution. - */ - @Test - @Ignore // TODO: fix for BATCH-1795 - public void testBackOffContextSavedForStatefulRetry() throws Exception { - - RetryTemplate tested = new RetryTemplate(); - tested.setRetryPolicy(new SimpleRetryPolicy(2, Collections - ., Boolean> singletonMap( - Exception.class, true))); - - BackOffPolicy bop = createStrictMock(BackOffPolicy.class); - BackOffContext backOffContext = new BackOffContext() { - }; - tested.setBackOffPolicy(bop); - - expect(bop.start(isA(RetryContext.class))).andReturn(backOffContext).once(); - bop.backOff(backOffContext); - expectLastCall().anyTimes(); - replay(bop); - - DefaultRetryState state = new DefaultRetryState(tested) { - - @Override - public boolean rollbackFor(Throwable exception) { - return true; - } - - }; - - RetryCallback callback = new RetryCallback() { - - public Object doWithRetry(RetryContext context) throws Exception { - throw new Exception("maybe next time!"); - } - - }; - - for (int i = 0; i < 2; i++) { - try { - tested.execute(callback, null, state); - fail(); - } catch (Exception expected) { - assertEquals("maybe next time!", expected.getMessage()); - } - } - - try { - tested.execute(callback, null, state); - fail(); - } catch (ExhaustedRetryException expected) { - assertEquals("maybe next time!", expected.getCause().getMessage()); - } - - verify(bop); - } - - private static class MockRetryCallback implements RetryCallback { - - private int attempts; - - private int attemptsBeforeSuccess; - - private Exception exceptionToThrow = new Exception(); - - public Object doWithRetry(RetryContext status) throws Exception { - this.attempts++; - if (attempts < attemptsBeforeSuccess) { - throw this.exceptionToThrow; - } - return null; - } - - public void setAttemptsBeforeSuccess(int attemptsBeforeSuccess) { - this.attemptsBeforeSuccess = attemptsBeforeSuccess; - } - - public void setExceptionToThrow(Exception exceptionToThrow) { - this.exceptionToThrow = exceptionToThrow; - } - } - - private static class MockBackOffStrategy implements BackOffPolicy { - - public int backOffCalls; - - public int startCalls; - - public BackOffContext start(RetryContext status) { - startCalls++; - return null; - } - - public void backOff(BackOffContext backOffContext) - throws BackOffInterruptedException { - backOffCalls++; - } - } -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/StatefulRecoveryRetryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/StatefulRecoveryRetryTests.java deleted file mode 100644 index a304e8c4b..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/StatefulRecoveryRetryTests.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.retry.support; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.junit.Test; -import org.springframework.batch.classify.BinaryExceptionClassifier; -import org.springframework.batch.repeat.RepeatContext; -import org.springframework.batch.repeat.context.RepeatContextSupport; -import org.springframework.batch.repeat.support.RepeatSynchronizationManager; -import org.springframework.batch.retry.ExhaustedRetryException; -import org.springframework.batch.retry.RetryState; -import org.springframework.batch.retry.RecoveryCallback; -import org.springframework.batch.retry.RetryCallback; -import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.RetryException; -import org.springframework.batch.retry.RetryPolicy; -import org.springframework.batch.retry.policy.MapRetryContextCache; -import org.springframework.batch.retry.policy.NeverRetryPolicy; -import org.springframework.batch.retry.policy.SimpleRetryPolicy; -import org.springframework.dao.DataAccessException; - -public class StatefulRecoveryRetryTests { - - private RetryTemplate retryTemplate = new RetryTemplate(); - - private int count = 0; - - private List list = new ArrayList(); - - @Test - public void testOpenSunnyDay() throws Exception { - RetryContext context = retryTemplate.open(new NeverRetryPolicy(), new DefaultRetryState("foo")); - assertNotNull(context); - // we haven't called the processor yet... - assertEquals(0, count); - } - - @Test - public void testRegisterThrowable() { - NeverRetryPolicy retryPolicy = new NeverRetryPolicy(); - RetryState state = new DefaultRetryState("foo"); - RetryContext context = retryTemplate.open(retryPolicy, state); - assertNotNull(context); - retryTemplate.registerThrowable(retryPolicy, state, context, new Exception()); - assertFalse(retryPolicy.canRetry(context)); - } - - @Test - public void testClose() throws Exception { - NeverRetryPolicy retryPolicy = new NeverRetryPolicy(); - RetryState state = new DefaultRetryState("foo"); - RetryContext context = retryTemplate.open(retryPolicy, state); - assertNotNull(context); - retryTemplate.registerThrowable(retryPolicy, state, context, new Exception()); - assertFalse(retryPolicy.canRetry(context)); - retryTemplate.close(retryPolicy, context, state, true); - // still can't retry, even if policy is closed - // (not that this would happen in practice)... - assertFalse(retryPolicy.canRetry(context)); - } - - @Test - public void testRecoverWithParent() throws Exception { - RepeatContext parent = new RepeatContextSupport(null); - RepeatSynchronizationManager.register(new RepeatContextSupport(parent)); - testRecover(); - assertFalse(parent.isCompleteOnly()); - RepeatSynchronizationManager.clear(); - } - - @Test - public void testRecover() throws Exception { - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections - ., Boolean> singletonMap(Exception.class, true))); - final String input = "foo"; - RetryState state = new DefaultRetryState(input); - RetryCallback callback = new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - throw new RuntimeException("Barf!"); - } - }; - RecoveryCallback recoveryCallback = new RecoveryCallback() { - public String recover(RetryContext context) { - count++; - list.add(input); - return input; - } - }; - Object result = null; - try { - result = retryTemplate.execute(callback, recoveryCallback, state); - fail("Expected exception on first try"); - } - catch (Exception e) { - // expected... - } - // On the second retry, the recovery path is taken... - result = retryTemplate.execute(callback, recoveryCallback, state); - assertEquals(input, result); // default result is the item - assertEquals(1, count); - assertEquals(input, list.get(0)); - } - - @Test - public void testSwitchToStatelessForNoRollback() throws Exception { - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections - ., Boolean> singletonMap(Exception.class, true))); - // Roll back for these: - BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(Collections - .> singleton(DataAccessException.class)); - // ...but not these: - assertFalse(classifier.classify(new RuntimeException())); - final String input = "foo"; - RetryState state = new DefaultRetryState(input, classifier); - RetryCallback callback = new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - throw new RuntimeException("Barf!"); - } - }; - RecoveryCallback recoveryCallback = new RecoveryCallback() { - public String recover(RetryContext context) { - count++; - list.add(input); - return input; - } - }; - Object result = null; - // On the second retry, the recovery path is taken... - result = retryTemplate.execute(callback, recoveryCallback, state); - assertEquals(input, result); // default result is the item - assertEquals(1, count); - assertEquals(input, list.get(0)); - } - - @Test - public void testExhaustedClearsHistoryAfterLastAttempt() throws Exception { - RetryPolicy retryPolicy = new SimpleRetryPolicy(1, Collections - ., Boolean> singletonMap(Exception.class, true)); - retryTemplate.setRetryPolicy(retryPolicy); - - final String input = "foo"; - RetryState state = new DefaultRetryState(input); - RetryCallback callback = new RetryCallback() { - public String doWithRetry(RetryContext context) throws Exception { - throw new RuntimeException("Barf!"); - } - }; - - try { - retryTemplate.execute(callback, state); - fail("Expected ExhaustedRetryException"); - } - catch (RuntimeException e) { - assertEquals("Barf!", e.getMessage()); - } - - try { - retryTemplate.execute(callback, state); - fail("Expected ExhaustedRetryException"); - } - catch (ExhaustedRetryException e) { - // expected - } - - RetryContext context = retryTemplate.open(retryPolicy, state); - // True after exhausted - the history is reset... - assertTrue(retryPolicy.canRetry(context)); - } - - @Test - public void testKeyGeneratorNotConsistentAfterFailure() throws Throwable { - - RetryPolicy retryPolicy = new SimpleRetryPolicy(3, Collections - ., Boolean> singletonMap(Exception.class, true)); - retryTemplate.setRetryPolicy(retryPolicy); - final StringHolder item = new StringHolder("bar"); - RetryState state = new DefaultRetryState(item); - - RetryCallback callback = new RetryCallback() { - public StringHolder doWithRetry(RetryContext context) throws Exception { - // This simulates what happens if someone uses a primary key - // for hashCode and equals and then relies on default key - // generator - ((StringHolder) item).string = ((StringHolder) item).string + (count++); - throw new RuntimeException("Barf!"); - } - }; - - try { - retryTemplate.execute(callback, state); - fail("Expected RuntimeException"); - } - catch (RuntimeException ex) { - String message = ex.getMessage(); - assertEquals("Barf!", message); - } - // Only fails second attempt because the algorithm to detect - // inconsistent has codes relies on the cache having been used for this - // item already... - try { - retryTemplate.execute(callback, state); - fail("Expected RetryException"); - } - catch (RetryException ex) { - String message = ex.getMessage(); - assertTrue("Message doesn't contain 'inconsistent': " + message, message.contains("inconsistent")); - } - - RetryContext context = retryTemplate.open(retryPolicy, state); - // True after exhausted - the history is reset... - assertEquals(0, context.getRetryCount()); - - } - - @Test - public void testCacheCapacity() throws Exception { - - retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections - ., Boolean> singletonMap(Exception.class, true))); - retryTemplate.setRetryContextCache(new MapRetryContextCache(1)); - - RetryCallback callback = new RetryCallback() { - public Object doWithRetry(RetryContext context) throws Exception { - count++; - throw new RuntimeException("Barf!"); - } - }; - - try { - retryTemplate.execute(callback, new DefaultRetryState("foo")); - fail("Expected RuntimeException"); - } - catch (RuntimeException e) { - assertEquals("Barf!", e.getMessage()); - } - - try { - retryTemplate.execute(callback, new DefaultRetryState("bar")); - fail("Expected RetryException"); - } - catch (RetryException e) { - String message = e.getMessage(); - assertTrue("Message does not contain 'capacity': " + message, message.indexOf("capacity") >= 0); - } - } - - @Test - public void testCacheCapacityNotReachedIfRecovered() throws Exception { - - SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(1, Collections - ., Boolean> singletonMap(Exception.class, true)); - retryTemplate.setRetryPolicy(retryPolicy); - retryTemplate.setRetryContextCache(new MapRetryContextCache(2)); - final StringHolder item = new StringHolder("foo"); - RetryState state = new DefaultRetryState(item); - - RetryCallback callback = new RetryCallback() { - public Object doWithRetry(RetryContext context) throws Exception { - count++; - throw new RuntimeException("Barf!"); - } - }; - RecoveryCallback recoveryCallback = new RecoveryCallback() { - public Object recover(RetryContext context) throws Exception { - return null; - } - }; - - try { - retryTemplate.execute(callback, recoveryCallback, state); - fail("Expected RuntimeException"); - } - catch (RuntimeException e) { - assertEquals("Barf!", e.getMessage()); - } - retryTemplate.execute(callback, recoveryCallback, state); - - RetryContext context = retryTemplate.open(retryPolicy, state); - // True after exhausted - the history is reset... - assertEquals(0, context.getRetryCount()); - - } - - private static class StringHolder { - - private String string; - - public StringHolder(String string) { - this.string = string; - } - - public boolean equals(Object obj) { - if (obj == null || !(obj instanceof StringHolder)) { - return false; - } - return string.equals(((StringHolder) obj).string); - } - - public int hashCode() { - return string.hashCode(); - } - - public String toString() { - return "String: " + string + " (hash = " + hashCode() + ")"; - } - - } - -} diff --git a/spring-batch-parent/pom.xml b/spring-batch-parent/pom.xml index d8e1321cb..62ee4e5c3 100644 --- a/spring-batch-parent/pom.xml +++ b/spring-batch-parent/pom.xml @@ -673,6 +673,11 @@ 1.1.2 true + + org.springframework.retry + spring-retry + 1.0.2.RELEASE + org.springframework.amqp spring-amqp