OPEN - issue BATCH-777: Parametrise RetryCallback and related interfaces
Extend RetryOperations to include recovery case
This commit is contained in:
@@ -116,7 +116,7 @@ public class RecoveryRetryCallbackTests extends TestCase {
|
||||
});
|
||||
assertEquals(0, calls.size());
|
||||
template.setRetryPolicy(new NeverRetryPolicy() {
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
|
||||
public void registerThrowable(RetryContext context, Exception throwable) throws TerminatedRetryException {
|
||||
// ...register the failed item
|
||||
calls.add("item=" + callback.getKey());
|
||||
// Call the base class method so that the next attempt is a
|
||||
|
||||
@@ -125,7 +125,7 @@ public class RetryListenerTests extends TestCase {
|
||||
throw new IllegalStateException("foo");
|
||||
}
|
||||
});
|
||||
fail("Expected TerminatedRetryException");
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertEquals("foo", e.getMessage());
|
||||
|
||||
@@ -63,7 +63,7 @@ public class CompositeRetryPolicyTests extends TestCase {
|
||||
return !errorRegistered;
|
||||
}
|
||||
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
|
||||
public void registerThrowable(RetryContext context, Exception throwable) throws TerminatedRetryException {
|
||||
errorRegistered = true;
|
||||
}
|
||||
} });
|
||||
|
||||
@@ -201,7 +201,7 @@ public class ExternalRetryPolicyTests extends TestCase {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
|
||||
public void registerThrowable(RetryContext context, Exception throwable) throws TerminatedRetryException {
|
||||
((RetryContextSupport) context).registerThrowable(throwable);
|
||||
attempts++;
|
||||
}
|
||||
|
||||
@@ -77,14 +77,6 @@ public class SimpleRetryPolicyTests extends TestCase {
|
||||
assertEquals("foo", context.getLastThrowable().getMessage());
|
||||
}
|
||||
|
||||
public void testDefaultFatal() throws Exception {
|
||||
SimpleRetryPolicy policy = new SimpleRetryPolicy();
|
||||
RetryContext context = policy.open(null, null);
|
||||
assertNotNull(context);
|
||||
policy.registerThrowable(context, new Error("foo"));
|
||||
assertFalse(policy.canRetry(context));
|
||||
}
|
||||
|
||||
public void testFatalOverridesRetryable() throws Exception {
|
||||
SimpleRetryPolicy policy = new SimpleRetryPolicy();
|
||||
policy.setFatalExceptionClasses(getClasses(Exception.class));
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.batch.retry.support.RetryTemplate;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ExternalRetryIntergrationTests {
|
||||
public class StatefulRetryIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testExternalRetryWithFailAndNoRetry() throws Exception {
|
||||
@@ -64,12 +64,12 @@ public class ExternalRetryIntergrationTests {
|
||||
result = retryTemplate.execute(recoveryCallback);
|
||||
// We always get a second attempt...
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (RuntimeException e) {
|
||||
// This is now the "exhausted" message:
|
||||
assertNotNull(e.getMessage());
|
||||
// But if template is external we should
|
||||
// swallow the exception when retry is impossible.
|
||||
fail("Did not expect IllegalArgumentException");
|
||||
fail("Did not expect RuntimeException: "+e);
|
||||
}
|
||||
|
||||
assertFalse(cache.containsKey("foo"));
|
||||
@@ -61,7 +61,7 @@ public class RetryTemplateTests extends TestCase {
|
||||
|
||||
public void testNoSuccessRetry() throws Exception {
|
||||
MockRetryCallback callback = new MockRetryCallback();
|
||||
// Somthing that won't be thrwon by JUnit...
|
||||
// Something that won't be thrown by JUnit...
|
||||
callback.setExceptionToThrow(new IllegalArgumentException());
|
||||
callback.setAttemptsBeforeSuccess(Integer.MAX_VALUE);
|
||||
RetryTemplate retryTemplate = new RetryTemplate();
|
||||
@@ -143,7 +143,7 @@ public class RetryTemplateTests extends TestCase {
|
||||
throw new IllegalStateException("Retry this operation");
|
||||
}
|
||||
});
|
||||
fail("Expected TerminatedRetryException");
|
||||
fail("Expected ExhaustedRetryException");
|
||||
}
|
||||
catch (ExhaustedRetryException ex) {
|
||||
// Expected for internal retry policy (external would recover
|
||||
@@ -216,7 +216,7 @@ public class RetryTemplateTests extends TestCase {
|
||||
MockRetryCallback callback = new MockRetryCallback();
|
||||
int attempts = 3;
|
||||
callback.setAttemptsBeforeSuccess(attempts);
|
||||
callback.setExceptionToThrow(new IllegalArgumentException());
|
||||
callback.setExceptionToThrow(new IllegalArgumentException("exhausted"));
|
||||
|
||||
RetryTemplate retryTemplate = new RetryTemplate();
|
||||
retryTemplate.setRetryPolicy(new NeverRetryPolicy() {
|
||||
@@ -229,9 +229,9 @@ public class RetryTemplateTests extends TestCase {
|
||||
});
|
||||
try {
|
||||
retryTemplate.execute(callback);
|
||||
fail("Expected ExhaustedRetryException");
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (ExhaustedRetryException e) {
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(e.getMessage().indexOf("exhausted") >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user