use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class SimpleRetryPolicyTests method testRetryLimitInitialState.
@Test
public void testRetryLimitInitialState() throws Exception {
SimpleRetryPolicy policy = new SimpleRetryPolicy();
RetryContext context = policy.open(null);
assertTrue(policy.canRetry(context));
policy.setMaxAttempts(0);
context = policy.open(null);
assertFalse(policy.canRetry(context));
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class SimpleRetryPolicyTests method testRetryableWithCause.
@Test
public void testRetryableWithCause() throws Exception {
Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>();
map.put(RuntimeException.class, true);
SimpleRetryPolicy policy = new SimpleRetryPolicy(3, map, true);
RetryContext context = policy.open(null);
assertNotNull(context);
policy.registerThrowable(context, new Exception(new RuntimeException("foo")));
assertTrue(policy.canRetry(context));
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class RetryOperationsInterceptorTests method testDefaultInterceptorWithRetryListenerInspectingTheMethodInvocation.
@Test
public void testDefaultInterceptorWithRetryListenerInspectingTheMethodInvocation() throws Exception {
final String label = "FOO";
final String classTagName = "class";
final String methodTagName = "method";
final String labelTagName = "label";
final Map<String, String> monitoringTags = new HashMap<String, String>();
RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(new SimpleRetryPolicy(2));
template.registerListener(new MethodInvocationRetryListenerSupport() {
@Override
protected <T, E extends Throwable> void doClose(RetryContext context, MethodInvocationRetryCallback<T, E> callback, Throwable throwable) {
monitoringTags.put(labelTagName, callback.getLabel());
Method method = callback.getInvocation().getMethod();
monitoringTags.put(classTagName, method.getDeclaringClass().getSimpleName());
monitoringTags.put(methodTagName, method.getName());
}
});
this.interceptor.setLabel(label);
this.interceptor.setRetryOperations(template);
((Advised) this.service).addAdvice(this.interceptor);
this.service.service();
assertEquals(2, count);
assertEquals(3, monitoringTags.entrySet().size());
assertThat(monitoringTags.get(labelTagName), equalTo(label));
assertThat(monitoringTags.get(classTagName), equalTo(Service.class.getSimpleName()));
assertThat(monitoringTags.get(methodTagName), equalTo("service"));
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class MethodInvocationRetryListenerSupportTests method testCloseWithRetryCallbackShouldntCallDoCloseMethod.
@Test
public void testCloseWithRetryCallbackShouldntCallDoCloseMethod() {
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);
RetryCallback callback = mock(RetryCallback.class);
support.close(context, callback, null);
assertEquals(0, callsOnDoCloseMethod.get());
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class MethodInvocationRetryListenerSupportTests method testOpenWithMethodInvocationRetryCallbackShouldCallDoCloseMethod.
@Test
public void testOpenWithMethodInvocationRetryCallbackShouldCallDoCloseMethod() {
final AtomicInteger callsOnDoOpenMethod = new AtomicInteger(0);
MethodInvocationRetryListenerSupport support = new MethodInvocationRetryListenerSupport() {
@Override
protected <T, E extends Throwable> boolean doOpen(RetryContext context, MethodInvocationRetryCallback<T, E> callback) {
callsOnDoOpenMethod.incrementAndGet();
return true;
}
};
RetryContext context = mock(RetryContext.class);
MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
assertTrue(support.open(context, callback));
assertEquals(1, callsOnDoOpenMethod.get());
}
Aggregations