use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class CompositeRetryPolicyTests method testEmptyPolicies.
@Test
public void testEmptyPolicies() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
RetryContext context = policy.open(null);
assertNotNull(context);
assertTrue(policy.canRetry(context));
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class CompositeRetryPolicyTests method testOptimistic.
@SuppressWarnings("serial")
@Test
public void testOptimistic() throws Exception {
CompositeRetryPolicy policy = new CompositeRetryPolicy();
policy.setOptimistic(true);
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport() {
public boolean canRetry(RetryContext context) {
return false;
}
}, new MockRetryPolicySupport() });
RetryContext context = policy.open(null);
assertNotNull(context);
assertTrue(policy.canRetry(context));
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class CompositeRetryPolicyTests method testNonTrivialPoliciesWithThrowable.
@SuppressWarnings("serial")
@Test
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));
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class FatalExceptionRetryPolicyTests method testFatalExceptionWithoutState.
@Test
public void testFatalExceptionWithoutState() throws Throwable {
MockRetryCallback callback = new MockRetryCallback();
callback.setExceptionToThrow(new IllegalArgumentException());
RetryTemplate retryTemplate = new RetryTemplate();
// Make sure certain exceptions are fatal...
Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, 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<String> recoveryCallback = new RecoveryCallback<String>() {
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);
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class SimpleRetryPolicyTests method testEmptyExceptionsNeverRetry.
@Test
public void testEmptyExceptionsNeverRetry() throws Exception {
// We can't retry any exceptions...
SimpleRetryPolicy policy = new SimpleRetryPolicy(3, Collections.<Class<? extends Throwable>, Boolean>emptyMap());
RetryContext context = policy.open(null);
// ...so we can't retry this one...
policy.registerThrowable(context, new IllegalStateException());
assertFalse(policy.canRetry(context));
}
Aggregations