@Async's qualifier works for target class annotations behind a JDK proxy as well
Also optimized AsyncExecutionAspectSupport's Executor-per-Method caching to use a ConcurrentHashMap. Issue: SPR-10274
This commit is contained in:
@@ -66,6 +66,21 @@ public class AsyncExecutionTests {
|
||||
assertEquals("20", future.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncMethodsThroughInterface() throws Exception {
|
||||
originalThreadName = Thread.currentThread().getName();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodBean.class));
|
||||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.refresh();
|
||||
SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
assertEquals("20", future.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncMethodsWithQualifier() throws Exception {
|
||||
originalThreadName = Thread.currentThread().getName();
|
||||
@@ -86,6 +101,26 @@ public class AsyncExecutionTests {
|
||||
assertEquals("30", future2.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncMethodsWithQualifierThroughInterface() throws Exception {
|
||||
originalThreadName = Thread.currentThread().getName();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodWithQualifierBean.class));
|
||||
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
|
||||
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
|
||||
context.registerBeanDefinition("e0", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
|
||||
context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
|
||||
context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
|
||||
context.refresh();
|
||||
SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
|
||||
asyncTest.doNothing(5);
|
||||
asyncTest.doSomething(10);
|
||||
Future<String> future = asyncTest.returnSomething(20);
|
||||
assertEquals("20", future.get());
|
||||
Future<String> future2 = asyncTest.returnSomething2(30);
|
||||
assertEquals("30", future2.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncClass() throws Exception {
|
||||
originalThreadName = Thread.currentThread().getName();
|
||||
@@ -177,6 +212,18 @@ public class AsyncExecutionTests {
|
||||
}
|
||||
|
||||
|
||||
public interface SimpleInterface {
|
||||
|
||||
void doNothing(int i);
|
||||
|
||||
void doSomething(int i);
|
||||
|
||||
Future<String> returnSomething(int i);
|
||||
|
||||
Future<String> returnSomething2(int i);
|
||||
}
|
||||
|
||||
|
||||
public static class AsyncMethodBean {
|
||||
|
||||
public void doNothing(int i) {
|
||||
@@ -196,6 +243,15 @@ public class AsyncExecutionTests {
|
||||
}
|
||||
|
||||
|
||||
public static class SimpleAsyncMethodBean extends AsyncMethodBean implements SimpleInterface {
|
||||
|
||||
@Override
|
||||
public Future<String> returnSomething2(int i) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Async("e0")
|
||||
public static class AsyncMethodWithQualifierBean {
|
||||
|
||||
@@ -224,6 +280,10 @@ public class AsyncExecutionTests {
|
||||
}
|
||||
|
||||
|
||||
public static class SimpleAsyncMethodWithQualifierBean extends AsyncMethodWithQualifierBean implements SimpleInterface {
|
||||
}
|
||||
|
||||
|
||||
@Async("e2")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyAsync {
|
||||
|
||||
Reference in New Issue
Block a user