Polished docs, fixed the build

This commit is contained in:
Marcin Grzejszczak
2018-07-25 11:04:23 +02:00
parent ed1f3afc8e
commit 32cacb629e
6 changed files with 28 additions and 21 deletions

View File

@@ -29,6 +29,6 @@ import org.springframework.scheduling.annotation.AsyncConfigurer;
*/
@Configuration
@EnableConfigurationProperties(AsyncProperties.class)
@EnableConfigurationProperties(SleuthAsyncProperties.class)
public class AsyncAutoConfiguration {
}

View File

@@ -47,7 +47,7 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor {
ExecutorBeanPostProcessor.class);
private final BeanFactory beanFactory;
private AsyncProperties asyncProperties;
private SleuthAsyncProperties sleuthAsyncProperties;
ExecutorBeanPostProcessor(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
@@ -93,8 +93,8 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor {
}
boolean isProxyNeeded(String beanName) {
AsyncProperties asyncProperties = asyncConfigurationProperties();
return !asyncProperties.getIgnoredBeans().contains(beanName);
SleuthAsyncProperties sleuthAsyncProperties = asyncConfigurationProperties();
return !sleuthAsyncProperties.getIgnoredBeans().contains(beanName);
}
Object createThreadPoolTaskExecutorProxy(Object bean, boolean cglibProxy,
@@ -119,11 +119,11 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor {
return factory.getObject();
}
private AsyncProperties asyncConfigurationProperties() {
if (this.asyncProperties == null) {
this.asyncProperties = this.beanFactory.getBean(AsyncProperties.class);
private SleuthAsyncProperties asyncConfigurationProperties() {
if (this.sleuthAsyncProperties == null) {
this.sleuthAsyncProperties = this.beanFactory.getBean(SleuthAsyncProperties.class);
}
return this.asyncProperties;
return this.sleuthAsyncProperties;
}
}

View File

@@ -29,13 +29,18 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*/
@ConfigurationProperties(prefix = "spring.sleuth.async")
public class AsyncProperties {
public class SleuthAsyncProperties {
/**
* List of {@link java.util.concurrent.Executor} bean names that should
* be ignored and not wrapped in a trace representation
*/
private List<String> ignoredBeans = Collections.emptyList();
public List<String> getIgnoredBeans() {
return this.ignoredBeans;
}
public void setIgnoredBeans(List<String> ignoredBeans) {
this.ignoredBeans = ignoredBeans;
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.sleuth.instrument.async;
import java.util.Collections;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -31,9 +32,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.ClassUtils;
import com.google.common.collect.ImmutableList;
import static org.junit.Assert.*;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
@@ -44,12 +42,12 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
public class ExecutorBeanPostProcessorTests {
@Mock BeanFactory beanFactory;
private AsyncProperties asyncProperties;
private SleuthAsyncProperties sleuthAsyncProperties;
@Before
public void setup() {
this.asyncProperties = new AsyncProperties();
Mockito.when(beanFactory.getBean(AsyncProperties.class)).thenReturn(this.asyncProperties);
this.sleuthAsyncProperties = new SleuthAsyncProperties();
Mockito.when(beanFactory.getBean(SleuthAsyncProperties.class)).thenReturn(this.sleuthAsyncProperties);
}
@Test
@@ -124,23 +122,23 @@ public class ExecutorBeanPostProcessorTests {
@Test
public void proxy_is_not_needed() throws Exception {
this.asyncProperties.setIgnoredBeans(ImmutableList.of("fooExecutor"));
this.sleuthAsyncProperties.setIgnoredBeans(Collections.singletonList("fooExecutor"));
boolean isProxyNeeded = new ExecutorBeanPostProcessor(this.beanFactory).isProxyNeeded("fooExecutor");
assertFalse(isProxyNeeded);
then(isProxyNeeded).isFalse();
}
@Test
public void proxy_is_needed() throws Exception {
boolean isProxyNeeded = new ExecutorBeanPostProcessor(this.beanFactory).isProxyNeeded("fooExecutor");
assertTrue(isProxyNeeded);
then(isProxyNeeded).isTrue();
}
@Test
public void should_not_create_proxy() throws Exception {
this.asyncProperties.setIgnoredBeans(ImmutableList.of("fooExecutor"));
this.sleuthAsyncProperties.setIgnoredBeans(Collections.singletonList("fooExecutor"));
Object o = new ExecutorBeanPostProcessor(this.beanFactory)
.postProcessAfterInitialization(new ThreadPoolTaskExecutor(), "fooExecutor");