use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class ExceptionClassifierRetryPolicyTests method testNullContext.
@Test
public void testNullContext() throws Exception {
policy.setPolicyMap(Collections.<Class<? extends Throwable>, RetryPolicy>singletonMap(Exception.class, new NeverRetryPolicy()));
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 ExceptionClassifierRetryPolicyTests method testParent.
@Test
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());
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class NeverRetryPolicyTests method testSimpleOperations.
@Test
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));
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class NeverRetryPolicyTests method testRetryCount.
@Test
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());
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class RetryTemplateTests method testBackOffInterrupted.
@Test
public void testBackOffInterrupted() throws Throwable {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setBackOffPolicy(new StatelessBackOffPolicy() {
@Override
protected void doBackOff() throws BackOffInterruptedException {
throw new BackOffInterruptedException("foo");
}
});
try {
retryTemplate.execute(new RetryCallback<Object, Exception>() {
@Override
public Object doWithRetry(RetryContext context) throws Exception {
throw new RuntimeException("Bad!");
}
});
fail("Expected RuntimeException");
} catch (BackOffInterruptedException e) {
assertEquals("foo", e.getMessage());
}
}
Aggregations