Merge branch '2.1.x'

This commit is contained in:
Marcin Grzejszczak
2019-07-02 10:18:02 +02:00
2 changed files with 36 additions and 18 deletions

View File

@@ -170,7 +170,8 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor {
() -> new LazyTraceThreadPoolTaskExecutor(this.beanFactory, executor));
}
Supplier<Executor> createThreadPoolTaskSchedulerProxy(ThreadPoolTaskScheduler executor) {
Supplier<Executor> createThreadPoolTaskSchedulerProxy(
ThreadPoolTaskScheduler executor) {
return () -> new LazyTraceThreadPoolTaskScheduler(this.beanFactory, executor);
}
@@ -276,8 +277,9 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor {
}
private static <T> boolean anyFinalMethods(T object, Class<T> iface) {
for (Method method : ReflectionUtils.getDeclaredMethods(iface)) {
Method m = ReflectionUtils.findMethod(object.getClass(), method.getName(), method.getParameterTypes());
for (Method method : ReflectionUtils.getAllDeclaredMethods(iface)) {
Method m = ReflectionUtils.findMethod(object.getClass(), method.getName(),
method.getParameterTypes());
if (m != null && Modifier.isFinal(m.getModifiers())) {
return true;
}
@@ -330,4 +332,5 @@ class ExecutorMethodInterceptor<T extends Executor> implements MethodInterceptor
T executor(BeanFactory beanFactory, T executor) {
return (T) new LazyTraceExecutor(beanFactory, executor);
}
}

View File

@@ -323,25 +323,31 @@ public class ExecutorBeanPostProcessorTests {
@Test
public void should_use_jdk_proxy_when_executor_has_final_methods() {
ExecutorBeanPostProcessor beanPostProcessor = new ExecutorBeanPostProcessor(this.beanFactory);
ExecutorBeanPostProcessor beanPostProcessor = new ExecutorBeanPostProcessor(
this.beanFactory);
Executor executor = Runnable::run;
Executor wrappedExecutor = (Executor) beanPostProcessor.postProcessAfterInitialization(
executor, "executor");
Executor wrappedExecutor = (Executor) beanPostProcessor
.postProcessAfterInitialization(executor, "executor");
then(AopUtils.isJdkDynamicProxy(wrappedExecutor)).isTrue();
then(AopUtils.isCglibProxy(wrappedExecutor)).isFalse();
AtomicBoolean wasCalled = new AtomicBoolean(false);
wrappedExecutor.execute(() -> { wasCalled.set(true); });
wrappedExecutor.execute(() -> {
wasCalled.set(true);
});
then(wasCalled).isTrue();
}
@Test
public void should_use_jdk_proxy_when_executor_service_has_final_methods() throws Exception {
ExecutorBeanPostProcessor beanPostProcessor = new ExecutorBeanPostProcessor(this.beanFactory);
ExecutorService executorService = new DelegatingSecurityContextExecutorService(Executors.newSingleThreadExecutor());
ExecutorService wrappedExecutor = (ExecutorService) beanPostProcessor.postProcessAfterInitialization(
executorService, "executorService");
public void should_use_jdk_proxy_when_executor_service_has_final_methods()
throws Exception {
ExecutorBeanPostProcessor beanPostProcessor = new ExecutorBeanPostProcessor(
this.beanFactory);
ExecutorService executorService = new DelegatingSecurityContextExecutorService(
Executors.newSingleThreadExecutor());
ExecutorService wrappedExecutor = (ExecutorService) beanPostProcessor
.postProcessAfterInitialization(executorService, "executorService");
then(AopUtils.isJdkDynamicProxy(wrappedExecutor)).isTrue();
then(AopUtils.isCglibProxy(wrappedExecutor)).isFalse();
@@ -350,11 +356,13 @@ public class ExecutorBeanPostProcessorTests {
}
@Test
public void should_use_jdk_proxy_when_async_task_executor_has_final_methods() throws Exception {
ExecutorBeanPostProcessor beanPostProcessor = new ExecutorBeanPostProcessor(this.beanFactory);
public void should_use_jdk_proxy_when_async_task_executor_has_final_methods()
throws Exception {
ExecutorBeanPostProcessor beanPostProcessor = new ExecutorBeanPostProcessor(
this.beanFactory);
AsyncTaskExecutor wrappedExecutor = (AsyncTaskExecutor) beanPostProcessor.postProcessAfterInitialization(
new DirectTaskExecutor(), "taskExecutor");
AsyncTaskExecutor wrappedExecutor = (AsyncTaskExecutor) beanPostProcessor
.postProcessAfterInitialization(new DirectTaskExecutor(), "taskExecutor");
then(AopUtils.isJdkDynamicProxy(wrappedExecutor)).isTrue();
then(AopUtils.isCglibProxy(wrappedExecutor)).isFalse();
@@ -363,11 +371,13 @@ public class ExecutorBeanPostProcessorTests {
@Test
public void should_fallback_to_sleuth_impl_when_thread_pool_task_executor_has_final_methods() {
ExecutorBeanPostProcessor postProcessor = new ExecutorBeanPostProcessor(this.beanFactory);
ExecutorBeanPostProcessor postProcessor = new ExecutorBeanPostProcessor(
this.beanFactory);
ThreadPoolTaskExecutor threadPoolTaskExecutor = new PoolTaskExecutor();
ThreadPoolTaskExecutor wrappedTaskExecutor = (ThreadPoolTaskExecutor) postProcessor
.postProcessAfterInitialization(threadPoolTaskExecutor, "threadPoolTaskExecutor");
.postProcessAfterInitialization(threadPoolTaskExecutor,
"threadPoolTaskExecutor");
then(wrappedTaskExecutor).isInstanceOf(LazyTraceThreadPoolTaskExecutor.class);
then(AopUtils.isCglibProxy(wrappedTaskExecutor)).isFalse();
@@ -442,6 +452,7 @@ public class ExecutorBeanPostProcessorTests {
}
static class DirectTaskExecutor extends SimpleAsyncTaskExecutor {
@Override
public final <T> Future<T> submit(Callable<T> callable) {
return super.submit(callable);
@@ -451,12 +462,16 @@ public class ExecutorBeanPostProcessorTests {
protected void doExecute(Runnable task) {
task.run();
}
}
static class PoolTaskExecutor extends ThreadPoolTaskExecutor {
@Override
public final void execute(Runnable task, long startTimeout) {
super.execute(task, startTimeout);
}
}
}