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 index a5acc5bff..ffbbcba15 100644 --- 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 @@ -35,29 +35,20 @@ public interface RetryPolicy { */ boolean canRetry(RetryContext context); - /** - * @param context the current context. - * @return true if the policy determines that the last exception should be - * re-thrown. - */ - boolean shouldRethrow(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 callback the {@link RetryCallback} that will execute the unit of - * work for this retry. * @param parent the parent context if we are in a nested retry. + * * @return a {@link RetryContext} object specific to this manager. * */ - RetryContext open(RetryCallback callback, RetryContext parent); + RetryContext open(RetryContext parent); /** * @param context a retry status created by the - * {@link #open(RetryCallback, RetryContext)} method of this manager. + * {@link #open(RetryContext)} method of this manager. * @param succeeded true if the retry callback succeeded */ void close(RetryContext context, boolean succeeded); @@ -72,16 +63,4 @@ public interface RetryPolicy { */ void registerThrowable(RetryContext context, Exception throwable) throws TerminatedRetryException; - /** - * Handle an exhausted retry. Default will be to throw an exception, but - * implementations may provide recovery path. - * - * @param context the current retry context. - * @return an appropriate value possibly from the callback. - * - * @throws ExhaustedRetryException if there is no recovery path. - * @throws Exception in rare cases where the policy wants to propagate the - * retryable exception - */ - Object handleRetryExhausted(RetryContext context) throws ExhaustedRetryException, Exception; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/AbstractStatelessRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/AbstractStatelessRetryPolicy.java deleted file mode 100644 index 153a38c1b..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/AbstractStatelessRetryPolicy.java +++ /dev/null @@ -1,56 +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; - -/** - * Base class for "normal" retry policies: those that operate in the context of - * a callback that is called repeatedly in a loop until it succeeds, or the - * policy decides to terminate. There is no need for such policies to store - * state outside the context. - * - * @see RetryPolicy#handleRetryExhausted(RetryContext) - * - * @author Dave Syer - * - * @deprecated TODO: remove this base class - * - */ -public abstract class AbstractStatelessRetryPolicy implements RetryPolicy { - - /** - * Just returns the negative of {@link RetryPolicy#canRetry(RetryContext)}, - * i.e. if we cannot retry then the exception should be thrown. - * - * @see org.springframework.batch.retry.RetryPolicy#shouldRethrow(org.springframework.batch.retry.RetryContext) - */ - public boolean shouldRethrow(RetryContext context) { - return !canRetry(context); - } - - /** - * Throw an exception. - * - * @see org.springframework.batch.retry.RetryPolicy#handleRetryExhausted(org.springframework.batch.retry.RetryContext) - */ - public Object handleRetryExhausted(RetryContext context) throws Exception { - throw context.getLastThrowable(); - } - -} 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 index f06c93e2c..18d180659 100644 --- 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 @@ -19,7 +19,6 @@ package org.springframework.batch.retry.policy; import java.util.ArrayList; import java.util.List; -import org.springframework.batch.retry.RetryCallback; import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; @@ -32,7 +31,7 @@ import org.springframework.batch.retry.context.RetryContextSupport; * @author Dave Syer * */ -public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy { +public class CompositeRetryPolicy implements RetryPolicy { RetryPolicy[] policies = new RetryPolicy[0]; @@ -93,13 +92,12 @@ public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy { * 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(org.springframework.batch.retry.RetryCallback, - * RetryContext) + * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) */ - public RetryContext open(RetryCallback callback, RetryContext parent) { + public RetryContext open(RetryContext parent) { List list = new ArrayList(); for (int i = 0; i < policies.length; i++) { - list.add(policies[i].open(callback, parent)); + list.add(policies[i].open(parent)); } return new CompositeRetryContext(parent, list); } 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 index 80405c882..bd7fca922 100644 --- 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 @@ -19,7 +19,6 @@ package org.springframework.batch.retry.policy; import java.util.HashMap; import java.util.Map; -import org.springframework.batch.retry.RetryCallback; import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; @@ -35,7 +34,7 @@ import org.springframework.util.Assert; * @author Dave Syer * */ -public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy { +public class ExceptionClassifierRetryPolicy implements RetryPolicy { private Classifier exceptionClassifier = new ExceptionClassifierSupport(); @@ -92,11 +91,10 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy * Create an active context that proxies a retry policy by chosing a target * from the policy map. * - * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, - * RetryContext) + * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) */ - public RetryContext open(RetryCallback callback, RetryContext parent) { - return new ExceptionClassifierRetryContext(parent, exceptionClassifier).open(callback, parent); + public RetryContext open(RetryContext parent) { + return new ExceptionClassifierRetryContext(parent, exceptionClassifier).open(parent); } /** @@ -121,9 +119,6 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy // Dynamic: depends on the policy: RetryContext context; - // The same for the life of the context: - RetryCallback callback; - Map contexts = new HashMap(); public ExceptionClassifierRetryContext(RetryContext parent, Classifier exceptionClassifier) { @@ -142,10 +137,6 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy return policy.canRetry(this.context); } - public boolean shouldRethrow(RetryContext context) { - return policy.shouldRethrow(context); - } - public void close(RetryContext context, boolean succeeded) { // Only close those policies that have been used (opened): for (RetryPolicy policy : contexts.keySet()) { @@ -153,8 +144,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy } } - public RetryContext open(RetryCallback callback, RetryContext parent) { - this.callback = callback; + public RetryContext open(RetryContext parent) { return this; } @@ -167,7 +157,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy private RetryContext getContext(RetryPolicy policy) { RetryContext context = contexts.get(policy); if (context == null) { - context = policy.open(callback, null); + context = policy.open(null); contexts.put(policy, context); } return context; @@ -179,11 +169,6 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy return result; } - public Object handleRetryExhausted(RetryContext context) throws UnsupportedOperationException { - // Not called... - throw new UnsupportedOperationException("Not supported - this code should be unreachable."); - } - } } 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 index 2d373482d..b2bc02d6a 100644 --- 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 @@ -16,7 +16,6 @@ package org.springframework.batch.retry.policy; -import org.springframework.batch.retry.RetryCallback; import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; @@ -30,7 +29,7 @@ import org.springframework.batch.retry.context.RetryContextSupport; * @author Dave Syer * */ -public class NeverRetryPolicy extends AbstractStatelessRetryPolicy { +public class NeverRetryPolicy implements RetryPolicy { /** * Returns false after the first exception. So there is always one try, and @@ -55,9 +54,9 @@ public class NeverRetryPolicy extends AbstractStatelessRetryPolicy { * Return a context that can respond to early termination requests, but does * nothing else. * - * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext) + * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) */ - public RetryContext open(RetryCallback callback, RetryContext parent) { + public RetryContext open(RetryContext parent) { return new NeverRetryContext(parent); } 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 index f32546fa9..0e5889b87 100644 --- 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 @@ -19,8 +19,8 @@ package org.springframework.batch.retry.policy; import java.util.Collection; import java.util.HashSet; -import org.springframework.batch.retry.RetryCallback; import org.springframework.batch.retry.RetryContext; +import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.context.RetryContextSupport; import org.springframework.batch.support.BinaryExceptionClassifier; @@ -41,7 +41,7 @@ import org.springframework.batch.support.BinaryExceptionClassifier; * @author Rob Harrop * */ -public class SimpleRetryPolicy extends AbstractStatelessRetryPolicy { +public class SimpleRetryPolicy implements RetryPolicy { /** * The default limit to the number of attempts for a new policy. @@ -143,10 +143,9 @@ public class SimpleRetryPolicy extends AbstractStatelessRetryPolicy { * 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(org.springframework.batch.retry.RetryCallback, - * RetryContext) + * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext) */ - public RetryContext open(RetryCallback callback, RetryContext parent) { + public RetryContext open(RetryContext parent) { return new SimpleRetryContext(parent); } 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 index 44e7a7c7b..8673c62d5 100644 --- 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 @@ -16,7 +16,6 @@ package org.springframework.batch.retry.policy; -import org.springframework.batch.retry.RetryCallback; import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; @@ -24,12 +23,12 @@ 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(RetryCallback, RetryContext)}. + * clock is started on a call to {@link #open(RetryContext)}. * * @author Dave Syer * */ -public class TimeoutRetryPolicy extends AbstractStatelessRetryPolicy { +public class TimeoutRetryPolicy implements RetryPolicy { /** * Default value for timeout (milliseconds). @@ -59,7 +58,7 @@ public class TimeoutRetryPolicy extends AbstractStatelessRetryPolicy { public void close(RetryContext context, boolean succeeded) { } - public RetryContext open(RetryCallback callback, RetryContext parent) { + public RetryContext open(RetryContext parent) { return new TimeoutRetryContext(parent, timeout); } 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 index fd99a9756..1ce98e5a5 100644 --- 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 @@ -195,8 +195,7 @@ public class RetryTemplate implements RetryOperations { BackOffPolicy backOffPolicy = this.backOffPolicy; // Allow the retry policy to initialise itself... - // TODO: catch and rethrow abnormal retry exception? - RetryContext context = open(retryCallback, retryPolicy, state); + RetryContext context = open(retryPolicy, state); // Make sure the context is available globally for clients who need // it... @@ -323,21 +322,18 @@ public class RetryTemplate implements RetryOperations { } /** - * @param retryCallback * @param retryPolicy * @return a retry context */ - protected RetryContext open(RetryCallback retryCallback, RetryPolicy retryPolicy, RetryState state) { - - // TODO: we don't need the callback here + protected RetryContext open(RetryPolicy retryPolicy, RetryState state) { if (state == null) { - return doOpenInternal(retryCallback, retryPolicy); + return doOpenInternal(retryPolicy); } Object key = state.getKey(); if (state.isForceRefresh()) { - return doOpenInternal(retryCallback, retryPolicy); + return doOpenInternal(retryPolicy); } else if (retryContextCache.containsKey(key)) { @@ -352,20 +348,19 @@ public class RetryTemplate implements RetryOperations { } else { - // The cache is only ued if there is a failure. - return doOpenInternal(retryCallback, retryPolicy); + // The cache is only used if there is a failure. + return doOpenInternal(retryPolicy); } } /** - * @param retryCallback * @param retryPolicy * @return */ - private RetryContext doOpenInternal(RetryCallback retryCallback, RetryPolicy retryPolicy) { - return retryPolicy.open(retryCallback, RetrySynchronizationManager.getContext()); + private RetryContext doOpenInternal(RetryPolicy retryPolicy) { + return retryPolicy.open(RetrySynchronizationManager.getContext()); } /** 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 index 91e913025..020fe46b1 100644 --- 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 @@ -24,7 +24,7 @@ public class AlwaysRetryPolicyTests extends TestCase { public void testSimpleOperations() throws Exception { AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, null); @@ -35,7 +35,7 @@ public class AlwaysRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -46,8 +46,8 @@ public class AlwaysRetryPolicyTests extends TestCase { public void testParent() throws Exception { AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null, null); - RetryContext child = policy.open(null, context); + 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 index 45db87282..46ca1bdd0 100644 --- 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 @@ -29,7 +29,7 @@ public class CompositeRetryPolicyTests extends TestCase { public void testEmptyPolicies() throws Exception { CompositeRetryPolicy policy = new CompositeRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertTrue(policy.canRetry(context)); } @@ -37,7 +37,7 @@ public class CompositeRetryPolicyTests extends TestCase { public void testTrivialPolicies() throws Exception { CompositeRetryPolicy policy = new CompositeRetryPolicy(); policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() }); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertTrue(policy.canRetry(context)); } @@ -49,7 +49,7 @@ public class CompositeRetryPolicyTests extends TestCase { return false; } } }); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertFalse(policy.canRetry(context)); } @@ -67,7 +67,7 @@ public class CompositeRetryPolicyTests extends TestCase { errorRegistered = true; } } }); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, null); @@ -86,7 +86,7 @@ public class CompositeRetryPolicyTests extends TestCase { list.add("2"); } } }); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.close(context, true); assertEquals(2, list.size()); @@ -105,7 +105,7 @@ public class CompositeRetryPolicyTests extends TestCase { list.add("2"); } } }); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); try { policy.close(context, true); @@ -119,7 +119,7 @@ public class CompositeRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { CompositeRetryPolicy policy = new CompositeRetryPolicy(); policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() }); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -130,8 +130,8 @@ public class CompositeRetryPolicyTests extends TestCase { public void testParent() throws Exception { CompositeRetryPolicy policy = new CompositeRetryPolicy(); - RetryContext context = policy.open(null, null); - RetryContext child = policy.open(null, context); + 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 index b88f81b53..9684146bc 100644 --- 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 @@ -31,14 +31,14 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); public void testDefaultPolicies() throws Exception { - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); } public void testTrivialPolicies() throws Exception { policy.setPolicyMap(Collections.singletonMap(ExceptionClassifierSupport.DEFAULT, (RetryPolicy) new MockRetryPolicySupport())); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertTrue(policy.canRetry(context)); } @@ -46,7 +46,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { public void testNullPolicies() throws Exception { policy.setPolicyMap(new HashMap()); try { - policy.open(null, null); + policy.open(null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { @@ -59,7 +59,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { map.put(ExceptionClassifierSupport.DEFAULT, new NeverRetryPolicy()); policy.setPolicyMap(map); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertTrue(policy.canRetry(context)); @@ -72,7 +72,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { map.put("foo", new NeverRetryPolicy()); policy.setPolicyMap(map); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); assertTrue(policy.canRetry(context)); @@ -94,7 +94,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { assertTrue(policy.canRetry(context)); // But now the classifier will be active in the new context... - context = policy.open(null, null); + context = policy.open(null); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, new IllegalArgumentException()); assertFalse(policy.canRetry(context)); @@ -110,7 +110,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { count++; } })); - RetryContext context = policy.open(null, null); + 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 ceating the child context. @@ -125,7 +125,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -136,8 +136,8 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { public void testParent() throws Exception { ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); - RetryContext context = policy.open(null, null); - RetryContext child = policy.open(null, context); + 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/NeverRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/NeverRetryPolicyTests.java index 221ea71d6..aed27dc9a 100644 --- 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 @@ -24,7 +24,7 @@ public class NeverRetryPolicyTests extends TestCase { public void testSimpleOperations() throws Exception { NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); // We can retry until the first exception is registered... assertTrue(policy.canRetry(context)); @@ -37,7 +37,7 @@ public class NeverRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -48,8 +48,8 @@ public class NeverRetryPolicyTests extends TestCase { public void testParent() throws Exception { NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null, null); - RetryContext child = policy.open(null, context); + 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 index 3032d4d62..f2de38676 100644 --- 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 @@ -28,7 +28,7 @@ public class SimpleRetryPolicyTests extends TestCase { public void testCanRetryIfNoException() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertTrue(policy.canRetry(context)); } @@ -36,7 +36,7 @@ public class SimpleRetryPolicyTests extends TestCase { public void testEmptyExceptionsNeverRetry() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); // We can't retry any exceptions... policy.setRetryableExceptionClasses(Collections.EMPTY_SET); @@ -48,16 +48,16 @@ public class SimpleRetryPolicyTests extends TestCase { public void testRetryLimitInitialState() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertTrue(policy.canRetry(context)); policy.setMaxAttempts(0); - context = policy.open(null, null); + context = policy.open(null); assertFalse(policy.canRetry(context)); } public void testRetryLimitSubsequentState() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); policy.setMaxAttempts(2); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, new Exception()); @@ -68,7 +68,7 @@ public class SimpleRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -81,7 +81,7 @@ public class SimpleRetryPolicyTests extends TestCase { SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setFatalExceptionClasses(getClasses(Exception.class)); policy.setRetryableExceptionClasses(getClasses(RuntimeException.class)); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, new RuntimeException("foo")); assertFalse(policy.canRetry(context)); @@ -99,8 +99,8 @@ public class SimpleRetryPolicyTests extends TestCase { public void testParent() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null, null); - RetryContext child = policy.open(null, context); + 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/TimeoutRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/TimeoutRetryPolicyTests.java index 6b3196f8f..0d380c2ed 100644 --- 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 @@ -25,7 +25,7 @@ public class TimeoutRetryPolicyTests extends TestCase { public void testTimeoutPreventsRetry() throws Exception { TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); policy.setTimeout(100); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); policy.registerThrowable(context, new Exception()); assertTrue(policy.canRetry(context)); Thread.sleep(200); @@ -35,7 +35,7 @@ public class TimeoutRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); - RetryContext context = policy.open(null, null); + RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -46,8 +46,8 @@ public class TimeoutRetryPolicyTests extends TestCase { public void testParent() throws Exception { TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); - RetryContext context = policy.open(null, null); - RetryContext child = policy.open(null, context); + 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/RetryTemplateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java index 0b3e6e7e7..08c3afc55 100644 --- 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 @@ -212,30 +212,6 @@ public class RetryTemplateTests extends TestCase { } } - public void testFallThroughToEndUnsuccessfully() throws Exception { - MockRetryCallback callback = new MockRetryCallback(); - int attempts = 3; - callback.setAttemptsBeforeSuccess(attempts); - callback.setExceptionToThrow(new IllegalArgumentException("exhausted")); - - RetryTemplate retryTemplate = new RetryTemplate(); - retryTemplate.setRetryPolicy(new NeverRetryPolicy() { - public boolean shouldRethrow(RetryContext context) { - // The opposite of normal... - // cause the retry to drop through to the end - // neither throwing exception nor returning successfully. - return false; - } - }); - try { - retryTemplate.execute(callback); - fail("Expected IllegalArgumentException"); - } - catch (IllegalArgumentException e) { - assertTrue(e.getMessage().indexOf("exhausted") >= 0); - } - } - private static class MockRetryCallback implements RetryCallback { private int attempts; 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 index 8b4b8bd64..61dbd8efa 100644 --- 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 @@ -50,17 +50,7 @@ public class StatefulRecoveryRetryTests { @Test public void testOpenSunnyDay() throws Exception { - - final StringHolder item = new StringHolder("foo"); - RetryCallback writer = new RetryCallback() { - public Object doWithRetry(RetryContext context) throws Exception { - count++; - list.add(item.string); - return item; - } - }; - - RetryContext context = retryTemplate.open(writer, new NeverRetryPolicy(), new RetryState("foo")); + RetryContext context = retryTemplate.open(new NeverRetryPolicy(), new RetryState("foo")); assertNotNull(context); // we haven't called the processor yet... assertEquals(0, count); @@ -70,12 +60,7 @@ public class StatefulRecoveryRetryTests { public void testRegisterThrowable() { NeverRetryPolicy retryPolicy = new NeverRetryPolicy(); RetryState state = new RetryState("foo"); - RetryContext context = retryTemplate.open(new RetryCallback() { - public Object doWithRetry(RetryContext context) throws Exception { - count++; - return null; - } - }, retryPolicy, state); + RetryContext context = retryTemplate.open(retryPolicy, state); assertNotNull(context); retryTemplate.registerThrowable(retryPolicy, state, context, new Exception()); assertFalse(retryPolicy.canRetry(context)); @@ -85,12 +70,7 @@ public class StatefulRecoveryRetryTests { public void testClose() throws Exception { NeverRetryPolicy retryPolicy = new NeverRetryPolicy(); RetryState state = new RetryState("foo"); - RetryContext context = retryTemplate.open(new RetryCallback() { - public Object doWithRetry(RetryContext context) throws Exception { - count++; - return null; - } - }, retryPolicy, state); + RetryContext context = retryTemplate.open(retryPolicy, state); assertNotNull(context); retryTemplate.registerThrowable(retryPolicy, state, context, new Exception()); assertFalse(retryPolicy.canRetry(context)); @@ -170,7 +150,7 @@ public class StatefulRecoveryRetryTests { // expected } - RetryContext context = retryTemplate.open(callback, retryPolicy, state); + RetryContext context = retryTemplate.open(retryPolicy, state); // True after exhausted - the history is reset... assertTrue(retryPolicy.canRetry(context)); } @@ -203,7 +183,7 @@ public class StatefulRecoveryRetryTests { assertTrue("Message doesn't contain 'inconsistent': " + message, message.indexOf("inconsistent") >= 0); } - RetryContext context = retryTemplate.open(callback, retryPolicy, state); + RetryContext context = retryTemplate.open(retryPolicy, state); // True after exhausted - the history is reset... assertEquals(0, context.getRetryCount()); @@ -270,7 +250,7 @@ public class StatefulRecoveryRetryTests { } retryTemplate.execute(callback, recoveryCallback, state); - RetryContext context = retryTemplate.open(callback, retryPolicy, state); + RetryContext context = retryTemplate.open(retryPolicy, state); // True after exhausted - the history is reset... assertEquals(0, context.getRetryCount());