Search in sources :

Example 51 with RetryTemplate

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

the class RetryOperationsInterceptorTests method testDefaultInterceptorWithRecovery.

@Test
public void testDefaultInterceptorWithRecovery() throws Exception {
    RetryTemplate template = new RetryTemplate();
    template.setRetryPolicy(new SimpleRetryPolicy(1));
    this.interceptor.setRetryOperations(template);
    this.interceptor.setRecoverer(new MethodInvocationRecoverer<Void>() {

        @Override
        public Void recover(Object[] args, Throwable cause) {
            return null;
        }
    });
    ((Advised) this.service).addAdvice(this.interceptor);
    this.service.service();
    assertEquals(1, count);
}
Also used : RetryTemplate(cn.taketoday.retry.support.RetryTemplate) Advised(cn.taketoday.aop.framework.Advised) SimpleRetryPolicy(cn.taketoday.retry.policy.SimpleRetryPolicy) AccessibleObject(java.lang.reflect.AccessibleObject) Test(org.junit.Test)

Example 52 with RetryTemplate

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

the class RetryOperationsInterceptorTests method testInterceptorChainWithRetry.

@Test
public void testInterceptorChainWithRetry() throws Exception {
    ((Advised) this.service).addAdvice(this.interceptor);
    final List<String> list = new ArrayList<String>();
    ((Advised) this.service).addAdvice(new MethodInterceptor() {

        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            list.add("chain");
            return invocation.proceed();
        }
    });
    RetryTemplate template = new RetryTemplate();
    template.setRetryPolicy(new SimpleRetryPolicy(2));
    this.interceptor.setRetryOperations(template);
    this.service.service();
    assertEquals(2, count);
    assertEquals(2, list.size());
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) RetryTemplate(cn.taketoday.retry.support.RetryTemplate) Advised(cn.taketoday.aop.framework.Advised) ArrayList(java.util.ArrayList) SimpleRetryPolicy(cn.taketoday.retry.policy.SimpleRetryPolicy) MethodInvocation(org.aopalliance.intercept.MethodInvocation) AccessibleObject(java.lang.reflect.AccessibleObject) Test(org.junit.Test)

Aggregations

RetryTemplate (cn.taketoday.retry.support.RetryTemplate)52 Test (org.junit.Test)38 SimpleRetryPolicy (cn.taketoday.retry.policy.SimpleRetryPolicy)26 DefaultRetryState (cn.taketoday.retry.support.DefaultRetryState)26 RetryContext (cn.taketoday.retry.RetryContext)22 RetryState (cn.taketoday.retry.RetryState)16 Advised (cn.taketoday.aop.framework.Advised)12 RetryStatistics (cn.taketoday.retry.RetryStatistics)12 ExhaustedRetryException (cn.taketoday.retry.ExhaustedRetryException)10 RecoveryCallback (cn.taketoday.retry.RecoveryCallback)8 ArrayList (java.util.ArrayList)8 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)8 SingletonTargetSource (cn.taketoday.aop.target.SingletonTargetSource)6 RetryListener (cn.taketoday.retry.RetryListener)6 RetryOperations (cn.taketoday.retry.RetryOperations)6 NeverRetryPolicy (cn.taketoday.retry.policy.NeverRetryPolicy)6 HashMap (java.util.HashMap)6 MethodInvocation (org.aopalliance.intercept.MethodInvocation)6 Before (org.junit.Before)5 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)4