use of cn.taketoday.aop.framework.Advised 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.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class RetryOperationsInterceptorTests method testRetryExceptionAfterTooManyAttempts.
@Test
public void testRetryExceptionAfterTooManyAttempts() throws Exception {
((Advised) this.service).addAdvice(this.interceptor);
RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(new NeverRetryPolicy());
this.interceptor.setRetryOperations(template);
try {
this.service.service();
fail("Expected Exception.");
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Not enough calls"));
}
assertEquals(1, count);
}
use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testRetryExceptionAfterTooManyAttemptsWithNoRecovery.
@Test
public void testRetryExceptionAfterTooManyAttemptsWithNoRecovery() throws Exception {
((Advised) service).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
try {
service.service("foo");
fail("Expected Exception.");
} catch (Exception e) {
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.startsWith("Not enough calls"));
}
assertEquals(1, count);
try {
service.service("foo");
fail("Expected ExhaustedRetryException");
} catch (ExhaustedRetryException e) {
// expected
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.startsWith("Retry exhausted"));
}
assertEquals(1, count);
}
use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testTransformerRecoveryAfterTooManyAttempts.
@Test
public void testTransformerRecoveryAfterTooManyAttempts() throws Exception {
((Advised) transformer).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
try {
transformer.transform("foo");
fail("Expected Exception.");
} catch (Exception e) {
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.startsWith("Not enough calls"));
}
assertEquals(1, count);
interceptor.setRecoverer((MethodInvocationRecoverer<Collection<String>>) (data, cause) -> {
count++;
return Collections.singleton((String) data[0]);
});
Collection<String> result = transformer.transform("foo");
assertEquals(2, count);
assertEquals(1, result.size());
}
use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testDefaultInterceptorAlwaysRetry.
@Test
public void testDefaultInterceptorAlwaysRetry() throws Exception {
retryTemplate.setRetryPolicy(new AlwaysRetryPolicy());
interceptor.setRetryOperations(retryTemplate);
((Advised) service).addAdvice(interceptor);
try {
service.service("foo");
fail("Expected Exception.");
} catch (Exception e) {
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.startsWith("Not enough calls"));
}
assertEquals(1, count);
}
Aggregations