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());
}
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;
}
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));
}
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());
}
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());
}
Aggregations