Search in sources :

Example 26 with RetryContext

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));
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) Test(org.junit.Test)

Example 27 with RetryContext

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());
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) Test(org.junit.Test)

Example 28 with RetryContext

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));
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) Test(org.junit.Test)

Example 29 with RetryContext

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());
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) Test(org.junit.Test)

Example 30 with RetryContext

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());
    }
}
Also used : StatelessBackOffPolicy(cn.taketoday.retry.backoff.StatelessBackOffPolicy) RetryContext(cn.taketoday.retry.RetryContext) BackOffInterruptedException(cn.taketoday.retry.backoff.BackOffInterruptedException) TerminatedRetryException(cn.taketoday.retry.TerminatedRetryException) BackOffInterruptedException(cn.taketoday.retry.backoff.BackOffInterruptedException) Test(org.junit.Test)

Aggregations

RetryContext (cn.taketoday.retry.RetryContext)160 Test (org.junit.Test)140 ExhaustedRetryException (cn.taketoday.retry.ExhaustedRetryException)24 TerminatedRetryException (cn.taketoday.retry.TerminatedRetryException)24 SimpleRetryPolicy (cn.taketoday.retry.policy.SimpleRetryPolicy)24 RetryException (cn.taketoday.retry.RetryException)18 RetryState (cn.taketoday.retry.RetryState)18 NeverRetryPolicy (cn.taketoday.retry.policy.NeverRetryPolicy)18 RetryTemplate (cn.taketoday.retry.support.RetryTemplate)18 DataAccessException (cn.taketoday.dao.DataAccessException)14 RetryCallback (cn.taketoday.retry.RetryCallback)14 RetryListener (cn.taketoday.retry.RetryListener)14 RetryPolicy (cn.taketoday.retry.RetryPolicy)12 BackOffInterruptedException (cn.taketoday.retry.backoff.BackOffInterruptedException)12 RecoveryCallback (cn.taketoday.retry.RecoveryCallback)10 DefaultRetryState (cn.taketoday.retry.support.DefaultRetryState)10 HashMap (java.util.HashMap)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 MethodInvocationRetryCallback (cn.taketoday.retry.interceptor.MethodInvocationRetryCallback)8 Before (org.junit.Before)8