Search in sources :

Example 6 with RetryContext

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

the class MethodInvocationRetryListenerSupportTests method testCloseWithMethodInvocationRetryCallbackShouldCallDoCloseMethod.

@Test
public void testCloseWithMethodInvocationRetryCallbackShouldCallDoCloseMethod() {
    final AtomicInteger callsOnDoCloseMethod = new AtomicInteger(0);
    MethodInvocationRetryListenerSupport support = new MethodInvocationRetryListenerSupport() {

        @Override
        protected <T, E extends Throwable> void doClose(RetryContext context, MethodInvocationRetryCallback<T, E> callback, Throwable throwable) {
            callsOnDoCloseMethod.incrementAndGet();
        }
    };
    RetryContext context = mock(RetryContext.class);
    MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
    support.close(context, callback, null);
    assertEquals(1, callsOnDoCloseMethod.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryContext(cn.taketoday.retry.RetryContext) MethodInvocationRetryCallback(cn.taketoday.retry.interceptor.MethodInvocationRetryCallback) Test(org.junit.Test)

Example 7 with RetryContext

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

the class StatefulRetryOperationsInterceptorTests method setUp.

@BeforeEach
public void setUp() throws Exception {
    interceptor = new StatefulRetryOperationsInterceptor();
    retryTemplate.registerListener(new RetryListener() {

        @Override
        public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
            StatefulRetryOperationsInterceptorTests.this.context = context;
        }
    });
    interceptor.setRetryOperations(retryTemplate);
    service = ProxyFactory.getProxy(Service.class, new SingletonTargetSource(new ServiceImpl()));
    transformer = ProxyFactory.getProxy(Transformer.class, new SingletonTargetSource(new TransformerImpl()));
    count = 0;
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) RetryListener(cn.taketoday.retry.RetryListener) SingletonTargetSource(cn.taketoday.aop.target.SingletonTargetSource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with RetryContext

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

the class AlwaysRetryPolicyTests method testSimpleOperations.

@Test
public void testSimpleOperations() throws Exception {
    AlwaysRetryPolicy policy = new AlwaysRetryPolicy();
    RetryContext context = policy.open(null);
    assertNotNull(context);
    assertTrue(policy.canRetry(context));
    policy.registerThrowable(context, null);
    assertTrue(policy.canRetry(context));
    policy.close(context);
    assertTrue(policy.canRetry(context));
}
Also used : RetryContext(cn.taketoday.retry.RetryContext) Test(org.junit.Test)

Example 9 with RetryContext

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

the class AlwaysRetryPolicyTests method testRetryCount.

@Test
public void testRetryCount() throws Exception {
    AlwaysRetryPolicy policy = new AlwaysRetryPolicy();
    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 10 with RetryContext

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

the class CompositeRetryPolicyTests method testRetryCount.

@Test
public void testRetryCount() throws Exception {
    CompositeRetryPolicy policy = new CompositeRetryPolicy();
    policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() });
    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)

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