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 d26f985d6..d4c4254b5 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 @@ -104,7 +104,7 @@ public class SimpleRetryExceptionHandlerTests extends TestCase { SimpleRetryExceptionHandler handler = new SimpleRetryExceptionHandler(retryPolicy, new SimpleLimitExceptionHandler(0)); // Simulate a failed retry... - RetryContext retryContext = retryPolicy.open(null); + RetryContext retryContext = retryPolicy.open(null, null); retryPolicy.registerThrowable(retryContext, ex); handler.close(retryContext, null, ex); return handler; 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 f8072df2f..3b12930e4 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 @@ -50,13 +50,14 @@ public interface RetryPolicy { * * @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 open(RetryCallback callback, RetryContext parent); /** - * @param status a retry status created by the {@link #open(RetryCallback)} + * @param status a retry status created by the {@link #open(RetryCallback, RetryContext)} * method of this manager. */ void close(RetryContext context); 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 93df8396e..9b51765c5 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 @@ -24,7 +24,6 @@ import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.batch.retry.support.RetrySynchronizationManager; /** * A {@link RetryPolicy} that composes a list of other policies and delegates @@ -84,14 +83,14 @@ 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) + * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext) */ - public RetryContext open(RetryCallback callback) { + public RetryContext open(RetryCallback callback, RetryContext parent) { List list = new ArrayList(); for (int i = 0; i < policies.length; i++) { - list.add(policies[i].open(callback)); + list.add(policies[i].open(callback, parent)); } - return new CompositeRetryContext(list); + return new CompositeRetryContext(parent, list); } /** @@ -114,8 +113,8 @@ public class CompositeRetryPolicy extends AbstractStatelessRetryPolicy { RetryPolicy[] policies; - public CompositeRetryContext(List contexts) { - super(RetrySynchronizationManager.getContext()); + public CompositeRetryContext(RetryContext parent, List contexts) { + super(parent); this.contexts = (RetryContext[]) 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 index d206cab70..dd819fabf 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 @@ -25,7 +25,6 @@ import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.batch.retry.support.RetrySynchronizationManager; import org.springframework.batch.support.ExceptionClassifier; import org.springframework.batch.support.ExceptionClassifierSupport; import org.springframework.util.Assert; @@ -94,10 +93,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) + * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext) */ - public RetryContext open(RetryCallback callback) { - return new ExceptionClassifierRetryContext(exceptionClassifier).open(callback); + public RetryContext open(RetryCallback callback, RetryContext parent) { + return new ExceptionClassifierRetryContext(parent, exceptionClassifier).open(callback, parent); } /** @@ -127,8 +126,8 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy Map contexts = new HashMap(); - public ExceptionClassifierRetryContext(ExceptionClassifier exceptionClassifier) { - super(RetrySynchronizationManager.getContext()); + public ExceptionClassifierRetryContext(RetryContext parent, ExceptionClassifier exceptionClassifier) { + super(parent); this.exceptionClassifier = exceptionClassifier; Object key = exceptionClassifier.getDefault(); policy = getPolicy(key); @@ -151,7 +150,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy } } - public RetryContext open(RetryCallback callback) { + public RetryContext open(RetryCallback callback, RetryContext parent) { this.callback = callback; return this; } @@ -165,7 +164,7 @@ public class ExceptionClassifierRetryPolicy extends AbstractStatelessRetryPolicy private RetryContext getContext(RetryPolicy policy) { RetryContext context = (RetryContext) contexts.get(policy); if (context == null) { - context = policy.open(callback); + context = policy.open(callback, null); contexts.put(policy, context); } return context; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicy.java index adf93b41f..5cc3ef6be 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicy.java @@ -29,7 +29,6 @@ import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; import org.springframework.batch.retry.callback.ItemReaderRetryCallback; import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.batch.retry.support.RetrySynchronizationManager; import org.springframework.util.Assert; /** @@ -100,15 +99,15 @@ public class ItemReaderRetryPolicy extends AbstractStatefulRetryPolicy { * Create a new context for the execution of the callback, which must be an * instance of {@link ItemReaderRetryCallback}. * - * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback) + * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext) * * @throws IllegalStateException if the callback is not of the required * type. */ - public RetryContext open(RetryCallback callback) { + public RetryContext open(RetryCallback callback, RetryContext parent) { Assert.state(callback instanceof ItemReaderRetryCallback, "Callback must be ItemProviderRetryCallback"); - ItemReaderRetryContext context = new ItemReaderRetryContext((ItemReaderRetryCallback) callback); - context.open(callback); + ItemReaderRetryContext context = new ItemReaderRetryContext((ItemReaderRetryCallback) callback, parent); + context.open(callback, null); return context; } @@ -146,8 +145,8 @@ public class ItemReaderRetryPolicy extends AbstractStatefulRetryPolicy { private ItemKeyGenerator keyGenerator; - public ItemReaderRetryContext(ItemReaderRetryCallback callback) { - super(RetrySynchronizationManager.getContext()); + public ItemReaderRetryContext(ItemReaderRetryCallback callback, RetryContext parent) { + super(parent); item = callback.next(this); this.reader = callback.getReader(); this.recoverer = callback.getRecoverer(); @@ -162,14 +161,14 @@ public class ItemReaderRetryPolicy extends AbstractStatefulRetryPolicy { delegate.close(this.delegateContext); } - public RetryContext open(RetryCallback callback) { + public RetryContext open(RetryCallback callback, RetryContext parent) { if (hasFailed(reader, keyGenerator, item)) { this.delegateContext = retryContextCache.get(keyGenerator.getKey(item)); } if (this.delegateContext == null) { // Only create a new context if we don't know the history of // this item: - this.delegateContext = delegate.open(callback); + this.delegateContext = delegate.open(callback, null); } // The return value shouldn't be used... return null; 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 39b4c9fe7..d661bfead 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 @@ -21,7 +21,6 @@ import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.batch.retry.support.RetrySynchronizationManager; /** * A {@link RetryPolicy} that allows the first attempt but never permits a @@ -56,10 +55,10 @@ 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) + * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext) */ - public RetryContext open(RetryCallback callback) { - return new NeverRetryContext(RetrySynchronizationManager.getContext()); + public RetryContext open(RetryCallback callback, 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 a1c66a86e..1f5a78049 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 @@ -20,7 +20,6 @@ import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.retry.RetryCallback; import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.batch.retry.support.RetrySynchronizationManager; import org.springframework.batch.support.BinaryExceptionClassifier; /** @@ -127,23 +126,16 @@ 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) + * @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback, RetryContext) */ - public RetryContext open(RetryCallback callback) { - return new SimpleRetryContext(); + public RetryContext open(RetryCallback callback, RetryContext parent) { + return new SimpleRetryContext(parent); } private static class SimpleRetryContext extends RetryContextSupport { - - public SimpleRetryContext() { - this(RetrySynchronizationManager.getContext()); - - } - public SimpleRetryContext(RetryContext parent) { super(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 7f93599bc..8d3df6cb0 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 @@ -21,11 +21,10 @@ import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; import org.springframework.batch.retry.context.RetryContextSupport; -import org.springframework.batch.retry.support.RetrySynchronizationManager; /** * 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)}. + * clock is started on a call to {@link #open(RetryCallback, RetryContext)}. * * @author Dave Syer * @@ -60,8 +59,8 @@ public class TimeoutRetryPolicy extends AbstractStatelessRetryPolicy { public void close(RetryContext context) { } - public RetryContext open(RetryCallback callback) { - return new TimeoutRetryContext(timeout); + public RetryContext open(RetryCallback callback, RetryContext parent) { + return new TimeoutRetryContext(parent, timeout); } public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException { @@ -74,8 +73,8 @@ public class TimeoutRetryPolicy extends AbstractStatelessRetryPolicy { private long start; - public TimeoutRetryContext(long timeout) { - super(RetrySynchronizationManager.getContext()); + public TimeoutRetryContext(RetryContext parent, long timeout) { + super(parent); this.start = System.currentTimeMillis(); this.timeout = 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 eb0c22244..d0af039f4 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 @@ -132,7 +132,7 @@ public class RetryTemplate implements RetryOperations { // Allow the retry policy to initialise itself... // TODO: catch and rethrow abnormal retry exception? - RetryContext context = retryPolicy.open(callback); + RetryContext context = retryPolicy.open(callback, RetrySynchronizationManager.getContext()); // Make sure the context is available globally for clients who need // it... 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 cf9f56db9..48ae1615e 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 @@ -19,13 +19,12 @@ package org.springframework.batch.retry.policy; import junit.framework.TestCase; import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.RetrySynchronizationManager; public class AlwaysRetryPolicyTests extends TestCase { public void testSimpleOperations() throws Exception { AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, null); @@ -36,7 +35,7 @@ public class AlwaysRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -47,9 +46,8 @@ public class AlwaysRetryPolicyTests extends TestCase { public void testParent() throws Exception { AlwaysRetryPolicy policy = new AlwaysRetryPolicy(); - RetryContext context = policy.open(null); - RetrySynchronizationManager.register(context); - RetryContext child = policy.open(null); + RetryContext context = policy.open(null, null); + RetryContext child = policy.open(null, 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 2eeb77fd5..e12f434bf 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 @@ -24,13 +24,12 @@ import junit.framework.TestCase; import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.TerminatedRetryException; -import org.springframework.batch.retry.support.RetrySynchronizationManager; public class CompositeRetryPolicyTests extends TestCase { public void testEmptyPolicies() throws Exception { CompositeRetryPolicy policy = new CompositeRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); assertTrue(policy.canRetry(context)); } @@ -38,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); + RetryContext context = policy.open(null, null); assertNotNull(context); assertTrue(policy.canRetry(context)); } @@ -50,7 +49,7 @@ public class CompositeRetryPolicyTests extends TestCase { return false; } } }); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); assertFalse(policy.canRetry(context)); } @@ -68,7 +67,7 @@ public class CompositeRetryPolicyTests extends TestCase { errorRegistered = true; } } }); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, null); @@ -90,7 +89,7 @@ public class CompositeRetryPolicyTests extends TestCase { list.add("2"); } } }); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); policy.close(context); assertEquals(2, list.size()); @@ -99,7 +98,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); + RetryContext context = policy.open(null, null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -110,9 +109,8 @@ public class CompositeRetryPolicyTests extends TestCase { public void testParent() throws Exception { CompositeRetryPolicy policy = new CompositeRetryPolicy(); - RetryContext context = policy.open(null); - RetrySynchronizationManager.register(context); - RetryContext child = policy.open(null); + RetryContext context = policy.open(null, null); + RetryContext child = policy.open(null, 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 0526c9f24..3ce22f222 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 @@ -23,7 +23,6 @@ import java.util.Map; import junit.framework.TestCase; import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.RetrySynchronizationManager; import org.springframework.batch.support.ExceptionClassifierSupport; public class ExceptionClassifierRetryPolicyTests extends TestCase { @@ -31,13 +30,13 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); public void testDefaultPolicies() throws Exception { - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); } public void testTrivialPolicies() throws Exception { policy.setPolicyMap(Collections.singletonMap(ExceptionClassifierSupport.DEFAULT, new MockRetryPolicySupport())); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); assertTrue(policy.canRetry(context)); } @@ -45,7 +44,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { public void testNullPolicies() throws Exception { policy.setPolicyMap(new HashMap()); try { - policy.open(null); + policy.open(null, null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { @@ -60,7 +59,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { map.put("foo", new NeverRetryPolicy()); policy.setPolicyMap(map); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); assertTrue(policy.canRetry(context)); @@ -82,7 +81,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); + context = policy.open(null, null); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, new IllegalArgumentException()); assertFalse(policy.canRetry(context)); @@ -97,7 +96,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { count++; } })); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, 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. @@ -112,7 +111,7 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -123,9 +122,8 @@ public class ExceptionClassifierRetryPolicyTests extends TestCase { public void testParent() throws Exception { ExceptionClassifierRetryPolicy policy = new ExceptionClassifierRetryPolicy(); - RetryContext context = policy.open(null); - RetrySynchronizationManager.register(context); - RetryContext child = policy.open(null); + RetryContext context = policy.open(null, null); + RetryContext child = policy.open(null, context); assertNotSame(child, context); assertSame(context, child.getParent()); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ExternalRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ExternalRetryPolicyTests.java index 7283069ee..aedc22e03 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ExternalRetryPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ExternalRetryPolicyTests.java @@ -196,7 +196,7 @@ public class ExternalRetryPolicyTests extends TestCase { // do nothing } - public RetryContext open(RetryCallback callback) { + public RetryContext open(RetryCallback callback, RetryContext parent) { RetryContextSupport context = new RetryContextSupport(null); context.setAttribute(MockRetryCallback.EXHAUSTED, Boolean.valueOf(!canRetry(context))); return context; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicyTests.java index 3618f3409..7f74632a6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/ItemReaderRetryPolicyTests.java @@ -73,7 +73,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { count++; list.add(data); } - })); + }), null); assertNotNull(context); // we haven't called the processor yet... assertEquals(0, count); @@ -88,7 +88,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { public Object doWithRetry(RetryContext context) throws Throwable { return null; } - }); + }, null); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { @@ -103,7 +103,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { public void write(Object data) { count++; } - })); + }), null); assertNotNull(context); // We can always retry if delegate says so... @@ -117,7 +117,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { count++; list.add(data); } - })); + }), null); assertNotNull(context); policy.registerThrowable(context, new Exception()); assertFalse(policy.canRetry(context)); @@ -130,7 +130,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { count++; list.add(data); } - })); + }), null); assertNotNull(context); policy.registerThrowable(context, new Exception()); assertFalse(policy.canRetry(context)); @@ -153,14 +153,14 @@ public class ItemReaderRetryPolicyTests extends TestCase { policy.setDelegate(new SimpleRetryPolicy(2)); // First call... - RetryContext context = policy.open(callback); + RetryContext context = policy.open(callback, null); assertNotNull(context); policy.registerThrowable(context, new Exception()); assertTrue(policy.canRetry(context)); policy.close(context); // Second call... - context = policy.open(callback); + context = policy.open(callback, null); assertNotNull(context); policy.registerThrowable(context, new Exception()); assertFalse(policy.canRetry(context)); @@ -179,13 +179,13 @@ public class ItemReaderRetryPolicyTests extends TestCase { public void write(Object data) { } }); - RetryContext context = policy.open(callback); + RetryContext context = policy.open(callback, null); assertNotNull(context); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, new Exception()); assertFalse(policy.canRetry(context)); assertEquals(0, count); - context = policy.open(callback); + context = policy.open(callback, null); // On the second retry, the recovery path is taken... Object result = policy.handleRetryExhausted(context); assertNotNull(result); // default result is null @@ -207,7 +207,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { policy.setDelegate(new SimpleRetryPolicy(1)); MockFailedItemProvider provider = new MockFailedItemProvider(Collections.EMPTY_LIST); ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, null); - policy.open(callback); + policy.open(callback, null); assertEquals(1, provider.hasFailedCount); } @@ -245,7 +245,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { }); policy.setDelegate(new SimpleRetryPolicy(1)); - RetryContext context = policy.open(callback); + RetryContext context = policy.open(callback, null); assertNotNull(context); assertEquals(0, count); @@ -257,7 +257,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { Object result = policy.handleRetryExhausted(context); assertEquals("foo", result); // default result is last item - context = policy.open(callback); + context = policy.open(callback, null); // True after exhausted - the history is reset... assertTrue(policy.canRetry(context)); } @@ -270,7 +270,7 @@ public class ItemReaderRetryPolicyTests extends TestCase { count++; list.add(data); } - })); + }), null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -289,11 +289,11 @@ public class ItemReaderRetryPolicyTests extends TestCase { policy = new ItemReaderRetryPolicy(); policy.setDelegate(new SimpleRetryPolicy(1)); - RetryContext context = policy.open(callback); + RetryContext context = policy.open(callback, null); assertNotNull(context); policy.registerThrowable(context, new RuntimeException("foo")); assertEquals(1, context.getRetryCount()); - context = policy.open(callback); + context = policy.open(callback, null); assertEquals(1, context.getRetryCount()); policy.registerThrowable(context, new RuntimeException("foo")); assertEquals(2, context.getRetryCount()); 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 0af10b2dd..2c1be6d30 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 @@ -19,13 +19,12 @@ package org.springframework.batch.retry.policy; import junit.framework.TestCase; import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.RetrySynchronizationManager; public class NeverRetryPolicyTests extends TestCase { public void testSimpleOperations() throws Exception { NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); // We can retry until the first exception is registered... assertTrue(policy.canRetry(context)); @@ -38,7 +37,7 @@ public class NeverRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -49,9 +48,8 @@ public class NeverRetryPolicyTests extends TestCase { public void testParent() throws Exception { NeverRetryPolicy policy = new NeverRetryPolicy(); - RetryContext context = policy.open(null); - RetrySynchronizationManager.register(context); - RetryContext child = policy.open(null); + RetryContext context = policy.open(null, null); + RetryContext child = policy.open(null, 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 3a47680f5..6e95525fa 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 @@ -19,7 +19,6 @@ package org.springframework.batch.retry.policy; import junit.framework.TestCase; import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.RetrySynchronizationManager; public class SimpleRetryPolicyTests extends TestCase { @@ -35,14 +34,14 @@ public class SimpleRetryPolicyTests extends TestCase { public void testCanRetryIfNoException() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertTrue(policy.canRetry(context)); } public void testEmptyExceptionsNeverRetry() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); // We can't retry any exceptions... policy.setRetryableExceptionClasses(new Class[0]); @@ -54,16 +53,16 @@ public class SimpleRetryPolicyTests extends TestCase { public void testRetryLimitInitialState() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertTrue(policy.canRetry(context)); policy.setMaxAttempts(0); - context = policy.open(null); + context = policy.open(null, null); assertFalse(policy.canRetry(context)); } public void testRetryLimitSubsequentState() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); policy.setMaxAttempts(2); assertTrue(policy.canRetry(context)); policy.registerThrowable(context, new Exception()); @@ -74,7 +73,7 @@ public class SimpleRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -85,9 +84,8 @@ public class SimpleRetryPolicyTests extends TestCase { public void testParent() throws Exception { SimpleRetryPolicy policy = new SimpleRetryPolicy(); - RetryContext context = policy.open(null); - RetrySynchronizationManager.register(context); - RetryContext child = policy.open(null); + RetryContext context = policy.open(null, null); + RetryContext child = policy.open(null, 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 1b71c4ff4..ac1f2f91f 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 @@ -19,14 +19,13 @@ package org.springframework.batch.retry.policy; import junit.framework.TestCase; import org.springframework.batch.retry.RetryContext; -import org.springframework.batch.retry.support.RetrySynchronizationManager; public class TimeoutRetryPolicyTests extends TestCase { public void testTimeoutPreventsRetry() throws Exception { TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); policy.setTimeout(100); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); policy.registerThrowable(context, new Exception()); assertTrue(policy.canRetry(context)); Thread.sleep(200); @@ -36,7 +35,7 @@ public class TimeoutRetryPolicyTests extends TestCase { public void testRetryCount() throws Exception { TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); - RetryContext context = policy.open(null); + RetryContext context = policy.open(null, null); assertNotNull(context); policy.registerThrowable(context, null); assertEquals(0, context.getRetryCount()); @@ -47,9 +46,8 @@ public class TimeoutRetryPolicyTests extends TestCase { public void testParent() throws Exception { TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); - RetryContext context = policy.open(null); - RetrySynchronizationManager.register(context); - RetryContext child = policy.open(null); + RetryContext context = policy.open(null, null); + RetryContext child = policy.open(null, context); assertNotSame(child, context); assertSame(context, child.getParent()); }