diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java index 4f8b2bd40..db4a868ab 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java @@ -170,7 +170,8 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor { () -> new LazyTraceThreadPoolTaskExecutor(this.beanFactory, executor)); } - Supplier createThreadPoolTaskSchedulerProxy(ThreadPoolTaskScheduler executor) { + Supplier createThreadPoolTaskSchedulerProxy( + ThreadPoolTaskScheduler executor) { return () -> new LazyTraceThreadPoolTaskScheduler(this.beanFactory, executor); } @@ -276,8 +277,9 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor { } private static boolean anyFinalMethods(T object, Class 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 implements MethodInterceptor T executor(BeanFactory beanFactory, T executor) { return (T) new LazyTraceExecutor(beanFactory, executor); } + } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java index 39aa16e46..1711f7bc9 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java @@ -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 Future submit(Callable 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); } + } + }