|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
import org.aopalliance.intercept.MethodInterceptor; |
|
|
|
import org.aopalliance.intercept.MethodInterceptor; |
|
|
|
import org.awaitility.Awaitility; |
|
|
|
import org.awaitility.Awaitility; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
@ -51,18 +52,24 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({ "resource", "deprecation" }) |
|
|
|
@SuppressWarnings({ "resource", "deprecation" }) |
|
|
|
public class AsyncExecutionTests { |
|
|
|
class AsyncExecutionTests { |
|
|
|
|
|
|
|
|
|
|
|
private static String originalThreadName; |
|
|
|
private static String originalThreadName; |
|
|
|
|
|
|
|
|
|
|
|
private static int listenerCalled = 0; |
|
|
|
private static volatile int listenerCalled = 0; |
|
|
|
|
|
|
|
|
|
|
|
private static int listenerConstructed = 0; |
|
|
|
private static int listenerConstructed = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@BeforeEach |
|
|
|
public void asyncMethods() throws Exception { |
|
|
|
void setUp() { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
listenerCalled = 0; |
|
|
|
|
|
|
|
listenerConstructed = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void asyncMethods() throws Exception { |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -101,8 +108,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncMethodsThroughInterface() throws Exception { |
|
|
|
void asyncMethodsThroughInterface() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -117,8 +123,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncMethodsWithQualifier() throws Exception { |
|
|
|
void asyncMethodsWithQualifier() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodWithQualifierBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodWithQualifierBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -138,8 +143,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncMethodsWithQualifierThroughInterface() throws Exception { |
|
|
|
void asyncMethodsWithQualifierThroughInterface() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodWithQualifierBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodWithQualifierBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -159,8 +163,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncClass() throws Exception { |
|
|
|
void asyncClass() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -190,8 +193,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncClassWithPostProcessor() throws Exception { |
|
|
|
void asyncClassWithPostProcessor() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBean.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
@ -204,8 +206,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncClassWithInterface() throws Exception { |
|
|
|
void asyncClassWithInterface() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -219,8 +220,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncClassWithInterfaceAndPostProcessor() throws Exception { |
|
|
|
void asyncClassWithInterfaceAndPostProcessor() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassBeanWithInterface.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
@ -233,8 +233,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncInterface() throws Exception { |
|
|
|
void asyncInterface() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -248,8 +247,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncInterfaceWithPostProcessor() throws Exception { |
|
|
|
void asyncInterfaceWithPostProcessor() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
@ -262,8 +260,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void dynamicAsyncInterface() throws Exception { |
|
|
|
void dynamicAsyncInterface() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -277,8 +274,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void dynamicAsyncInterfaceWithPostProcessor() throws Exception { |
|
|
|
void dynamicAsyncInterfaceWithPostProcessor() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
@ -291,8 +287,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncMethodsInInterface() throws Exception { |
|
|
|
void asyncMethodsInInterface() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -307,8 +302,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncMethodsInInterfaceWithPostProcessor() throws Exception { |
|
|
|
void asyncMethodsInInterfaceWithPostProcessor() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
@ -322,8 +316,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void dynamicAsyncMethodsInInterfaceWithPostProcessor() throws Exception { |
|
|
|
void dynamicAsyncMethodsInInterfaceWithPostProcessor() throws Exception { |
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncMethodsInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(DynamicAsyncMethodsInterfaceBean.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
|
context.registerBeanDefinition("asyncProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); |
|
|
@ -336,10 +329,8 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncMethodListener() throws Exception { |
|
|
|
void asyncMethodListener() throws Exception { |
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
listenerCalled = 0; |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodListener.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodListener.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -355,11 +346,8 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncClassListener() throws Exception { |
|
|
|
void asyncClassListener() throws Exception { |
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
listenerCalled = 0; |
|
|
|
|
|
|
|
listenerConstructed = 0; |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassListener.class)); |
|
|
|
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassListener.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
|
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class)); |
|
|
@ -376,11 +364,8 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void asyncPrototypeClassListener() throws Exception { |
|
|
|
void asyncPrototypeClassListener() throws Exception { |
|
|
|
// Arrange
|
|
|
|
// Arrange
|
|
|
|
originalThreadName = Thread.currentThread().getName(); |
|
|
|
|
|
|
|
listenerCalled = 0; |
|
|
|
|
|
|
|
listenerConstructed = 0; |
|
|
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
RootBeanDefinition listenerDef = new RootBeanDefinition(AsyncClassListener.class); |
|
|
|
RootBeanDefinition listenerDef = new RootBeanDefinition(AsyncClassListener.class); |
|
|
|
listenerDef.setScope(BeanDefinition.SCOPE_PROTOTYPE); |
|
|
|
listenerDef.setScope(BeanDefinition.SCOPE_PROTOTYPE); |
|
|
@ -414,19 +399,17 @@ public class AsyncExecutionTests { |
|
|
|
public static class AsyncMethodBean { |
|
|
|
public static class AsyncMethodBean { |
|
|
|
|
|
|
|
|
|
|
|
public void doNothing(int i) { |
|
|
|
public void doNothing(int i) { |
|
|
|
assertThat(Thread.currentThread().getName().equals(originalThreadName)).isTrue(); |
|
|
|
assertThat(Thread.currentThread().getName()).isEqualTo(originalThreadName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
@Async |
|
|
|
public void doSomething(int i) { |
|
|
|
public void doSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
@Async |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
} |
|
|
|
} |
|
|
@ -438,8 +421,7 @@ public class AsyncExecutionTests { |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
@Async |
|
|
|
public ListenableFuture<String> returnSomethingListenable(int i) { |
|
|
|
public ListenableFuture<String> returnSomethingListenable(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
} |
|
|
|
} |
|
|
@ -451,8 +433,7 @@ public class AsyncExecutionTests { |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
@Async |
|
|
|
public CompletableFuture<String> returnSomethingCompletable(int i) { |
|
|
|
public CompletableFuture<String> returnSomethingCompletable(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
} |
|
|
|
} |
|
|
@ -474,28 +455,25 @@ public class AsyncExecutionTests { |
|
|
|
public static class AsyncMethodWithQualifierBean { |
|
|
|
public static class AsyncMethodWithQualifierBean { |
|
|
|
|
|
|
|
|
|
|
|
public void doNothing(int i) { |
|
|
|
public void doNothing(int i) { |
|
|
|
assertThat(Thread.currentThread().getName().equals(originalThreadName)).isTrue(); |
|
|
|
assertThat(Thread.currentThread().getName()).isEqualTo(originalThreadName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Async("e1") |
|
|
|
@Async("e1") |
|
|
|
public void doSomething(int i) { |
|
|
|
public void doSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(Thread.currentThread().getName()).startsWith("e1-"); |
|
|
|
assertThat(Thread.currentThread().getName().startsWith("e1-")).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@MyAsync |
|
|
|
@MyAsync |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(Thread.currentThread().getName()).startsWith("e2-"); |
|
|
|
assertThat(Thread.currentThread().getName().startsWith("e2-")).isTrue(); |
|
|
|
|
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Future<String> returnSomething2(int i) { |
|
|
|
public Future<String> returnSomething2(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(Thread.currentThread().getName()).startsWith("e0-"); |
|
|
|
assertThat(Thread.currentThread().getName().startsWith("e0-")).isTrue(); |
|
|
|
|
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -516,13 +494,11 @@ public class AsyncExecutionTests { |
|
|
|
public static class AsyncClassBean implements Serializable, DisposableBean { |
|
|
|
public static class AsyncClassBean implements Serializable, DisposableBean { |
|
|
|
|
|
|
|
|
|
|
|
public void doSomething(int i) { |
|
|
|
public void doSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
} |
|
|
|
} |
|
|
@ -530,8 +506,7 @@ public class AsyncExecutionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ListenableFuture<String> returnSomethingListenable(int i) { |
|
|
|
public ListenableFuture<String> returnSomethingListenable(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
} |
|
|
|
} |
|
|
@ -540,8 +515,7 @@ public class AsyncExecutionTests { |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
@Async |
|
|
|
public CompletableFuture<String> returnSomethingCompletable(int i) { |
|
|
|
public CompletableFuture<String> returnSomethingCompletable(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
throw new IllegalArgumentException(); |
|
|
|
} |
|
|
|
} |
|
|
@ -567,14 +541,12 @@ public class AsyncExecutionTests { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void doSomething(int i) { |
|
|
|
public void doSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -593,14 +565,12 @@ public class AsyncExecutionTests { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void doSomething(int i) { |
|
|
|
public void doSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -613,8 +583,7 @@ public class AsyncExecutionTests { |
|
|
|
public DynamicAsyncInterfaceBean() { |
|
|
|
public DynamicAsyncInterfaceBean() { |
|
|
|
ProxyFactory pf = new ProxyFactory(new HashMap<>()); |
|
|
|
ProxyFactory pf = new ProxyFactory(new HashMap<>()); |
|
|
|
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> { |
|
|
|
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (Future.class.equals(invocation.getMethod().getReturnType())) { |
|
|
|
if (Future.class.equals(invocation.getMethod().getReturnType())) { |
|
|
|
return new AsyncResult<>(invocation.getArguments()[0].toString()); |
|
|
|
return new AsyncResult<>(invocation.getArguments()[0].toString()); |
|
|
|
} |
|
|
|
} |
|
|
@ -658,19 +627,17 @@ public class AsyncExecutionTests { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void doNothing(int i) { |
|
|
|
public void doNothing(int i) { |
|
|
|
assertThat(Thread.currentThread().getName().equals(originalThreadName)).isTrue(); |
|
|
|
assertThat(Thread.currentThread().getName()).isEqualTo(originalThreadName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void doSomething(int i) { |
|
|
|
public void doSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
public Future<String> returnSomething(int i) { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
return new AsyncResult<>(Integer.toString(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -683,8 +650,7 @@ public class AsyncExecutionTests { |
|
|
|
public DynamicAsyncMethodsInterfaceBean() { |
|
|
|
public DynamicAsyncMethodsInterfaceBean() { |
|
|
|
ProxyFactory pf = new ProxyFactory(new HashMap<>()); |
|
|
|
ProxyFactory pf = new ProxyFactory(new HashMap<>()); |
|
|
|
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> { |
|
|
|
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> { |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
if (Future.class.equals(invocation.getMethod().getReturnType())) { |
|
|
|
if (Future.class.equals(invocation.getMethod().getReturnType())) { |
|
|
|
return new AsyncResult<>(invocation.getArguments()[0].toString()); |
|
|
|
return new AsyncResult<>(invocation.getArguments()[0].toString()); |
|
|
|
} |
|
|
|
} |
|
|
@ -718,8 +684,7 @@ public class AsyncExecutionTests { |
|
|
|
@Async |
|
|
|
@Async |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
listenerCalled++; |
|
|
|
listenerCalled++; |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -734,8 +699,7 @@ public class AsyncExecutionTests { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
listenerCalled++; |
|
|
|
listenerCalled++; |
|
|
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName); |
|
|
|
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|