Search in sources :

Example 96 with RetryContext

use of cn.taketoday.retry.RetryContext in project today-framework by TAKETODAY.

the class SimpleRetryPolicyTests method testFatalOverridesRetryable.

@Test
public void testFatalOverridesRetryable() throws Exception {
    Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>();
    map.put(Exception.class, false);
    map.put(RuntimeException.class, true);
    SimpleRetryPolicy policy = new SimpleRetryPolicy(3, map);
    RetryContext context = policy.open(null);
    assertNotNull(context);
    policy.registerThrowable(context, new RuntimeException("foo"));
    assertTrue(policy.canRetry(context));
}
Also used : HashMap(java.util.HashMap) RetryContext(cn.taketoday.retry.RetryContext) Test(org.junit.Test)

Example 97 with RetryContext

use of cn.taketoday.retry.RetryContext in project today-framework by TAKETODAY.

the class RetrySynchronizationManagerTests method setUp.

@Before
public void setUp() throws Exception {
    RetrySynchronizationManagerTests.clearAll();
    RetryContext status = RetrySynchronizationManager.getContext();
    assertNull(status);
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) Before(org.junit.Before)

Example 98 with RetryContext

use of cn.taketoday.retry.RetryContext in project today-framework by TAKETODAY.

the class RetrySynchronizationManagerTests method testStatusRegistration.

@Test
public void testStatusRegistration() throws Exception {
    RetryContext status = new RetryContextSupport(null);
    RetryContext value = RetrySynchronizationManager.register(status);
    assertNull(value);
    value = RetrySynchronizationManager.register(status);
    assertEquals(status, value);
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) RetryContextSupport(cn.taketoday.retry.context.RetryContextSupport) Test(org.junit.Test)

Example 99 with RetryContext

use of cn.taketoday.retry.RetryContext in project today-framework by TAKETODAY.

the class RetrySynchronizationManagerTests method testParent.

@Test
public void testParent() throws Exception {
    RetryContext parent = new RetryContextSupport(null);
    RetryContext child = new RetryContextSupport(parent);
    assertSame(parent, child.getParent());
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) RetryContextSupport(cn.taketoday.retry.context.RetryContextSupport) Test(org.junit.Test)

Example 100 with RetryContext

use of cn.taketoday.retry.RetryContext in project today-framework by TAKETODAY.

the class RetryTemplateTests method testFailedPolicy.

@SuppressWarnings("serial")
@Test
public void testFailedPolicy() throws Throwable {
    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(new NeverRetryPolicy() {

        @Override
        public void registerThrowable(RetryContext context, Throwable throwable) {
            throw new RuntimeException("Planned");
        }
    });
    try {
        retryTemplate.execute(new RetryCallback<Object, Exception>() {

            @Override
            public Object doWithRetry(RetryContext context) throws Exception {
                throw new RuntimeException("Realllly bad!");
            }
        });
        fail("Expected Error");
    } catch (TerminatedRetryException e) {
        assertEquals("Planned", e.getCause().getMessage());
    }
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) NeverRetryPolicy(cn.taketoday.retry.policy.NeverRetryPolicy) TerminatedRetryException(cn.taketoday.retry.TerminatedRetryException) BackOffInterruptedException(cn.taketoday.retry.backoff.BackOffInterruptedException) TerminatedRetryException(cn.taketoday.retry.TerminatedRetryException) 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