use of cn.taketoday.aop.framework.Advised in project today-framework by TAKETODAY.
the class EnableAsyncTests method customAsyncAnnotationIsPropagated.
@Test
public void customAsyncAnnotationIsPropagated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(CustomAsyncAnnotationConfig.class, CustomAsyncBean.class);
ctx.refresh();
Object bean = ctx.getBean(CustomAsyncBean.class);
assertThat(AopUtils.isAopProxy(bean)).isTrue();
boolean isAsyncAdvised = false;
for (Advisor advisor : ((Advised) bean).getAdvisors()) {
if (advisor instanceof AsyncAnnotationAdvisor) {
isAsyncAdvised = true;
break;
}
}
assertThat(isAsyncAdvised).as("bean was not async advised as expected").isTrue();
ctx.close();
}
use of cn.taketoday.aop.framework.Advised in project today-framework 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-framework 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-framework 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);
}
use of cn.taketoday.aop.framework.Advised in project today-framework by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testInterceptorChainWithRetry.
@Test
public void testInterceptorChainWithRetry() throws Exception {
((Advised) service).addAdvice(interceptor);
final List<String> list = new ArrayList<>();
((Advised) service).addAdvice((MethodInterceptor) invocation -> {
list.add("chain");
return invocation.proceed();
});
interceptor.setRetryOperations(retryTemplate);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2));
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);
service.service("foo");
assertEquals(2, count);
assertEquals(2, list.size());
}
Aggregations