diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpanMessagingAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpanMessagingAutoConfiguration.java index 30a0470eb..d72b2be80 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpanMessagingAutoConfiguration.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpanMessagingAutoConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.cloud.sleuth.SpanExtractor; import org.springframework.cloud.sleuth.SpanInjector; import org.springframework.cloud.sleuth.TraceKeys; +import org.springframework.cloud.sleuth.Tracer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.Message; @@ -37,7 +38,7 @@ import org.springframework.messaging.support.MessageBuilder; */ @Configuration @ConditionalOnClass(Message.class) -@ConditionalOnBean({ TraceKeys.class, Random.class }) +@ConditionalOnBean(Tracer.class) public class TraceSpanMessagingAutoConfiguration { @Bean diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/DefaultSpanNamerTest.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/DefaultSpanNamerTests.java similarity index 97% rename from spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/DefaultSpanNamerTest.java rename to spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/DefaultSpanNamerTests.java index 0c86fabac..87c967674 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/DefaultSpanNamerTest.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/DefaultSpanNamerTests.java @@ -23,7 +23,7 @@ import static org.assertj.core.api.BDDAssertions.then; /** * @author Marcin Grzejszczak */ -public class DefaultSpanNamerTest { +public class DefaultSpanNamerTests { DefaultSpanNamer defaultSpanNamer = new DefaultSpanNamer(); diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/LogTest.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/LogTests.java similarity index 98% rename from spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/LogTest.java rename to spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/LogTests.java index 3e66c0a2d..c830c9e20 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/LogTest.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/LogTests.java @@ -30,7 +30,7 @@ import static org.assertj.core.api.BDDAssertions.then; /** * @author Adrian Cole */ -public class LogTest { +public class LogTests { @Rule public ExpectedException thrown = ExpectedException.none(); diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTest.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTest.java deleted file mode 100644 index 389760318..000000000 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright 2015-2016 The OpenZipkin Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.springframework.cloud.sleuth.autoconfig; - -import org.junit.After; -import org.junit.Test; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; -import org.springframework.cloud.sleuth.Span; -import org.springframework.cloud.sleuth.Tracer; -import org.springframework.cloud.sleuth.log.SleuthLogAutoConfiguration; -import org.springframework.cloud.sleuth.sampler.NeverSampler; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.EnvironmentTestUtils.addEnvironment; - -public class TraceAutoConfigurationTest { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @After - public void close() { - context.close(); - } - - @Test - public void defaultsTo64BitTraceId() { - context = new AnnotationConfigApplicationContext(); - context.register( - PropertyPlaceholderAutoConfiguration.class, - SleuthLogAutoConfiguration.class, - TraceAutoConfiguration.class - ); - context.refresh(); - Tracer tracer = context.getBean(Tracer.class); - - Span span = null; - try { - span = tracer.createSpan("foo", NeverSampler.INSTANCE); - assertThat(span.getTraceIdHigh()).isEqualTo(0L); - assertThat(span.getTraceId()).isNotEqualTo(0L); - } finally { - if (span != null){ - tracer.close(span); - } - } - } - - @Test - public void optInto128BitTraceId() { - addEnvironment(context, "spring.sleuth.traceId128:true"); - context.register( - PropertyPlaceholderAutoConfiguration.class, - SleuthLogAutoConfiguration.class, - TraceAutoConfiguration.class - ); - context.refresh(); - Tracer tracer = context.getBean(Tracer.class); - - Span span = null; - try { - span = tracer.createSpan("foo", NeverSampler.INSTANCE); - assertThat(span.getTraceIdHigh()).isNotEqualTo(0L); - assertThat(span.getTraceId()).isNotEqualTo(0L); - } finally { - if (span != null){ - tracer.close(span); - } - } - } -} diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTests.java new file mode 100644 index 000000000..65eca35d3 --- /dev/null +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationTests.java @@ -0,0 +1,75 @@ +/** + * Copyright 2015-2016 The OpenZipkin Authors + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.springframework.cloud.sleuth.autoconfig;
+
+import org.junit.After;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
+import org.springframework.cloud.sleuth.Span;
+import org.springframework.cloud.sleuth.Tracer;
+import org.springframework.cloud.sleuth.log.SleuthLogAutoConfiguration;
+import org.springframework.cloud.sleuth.sampler.NeverSampler;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.boot.test.EnvironmentTestUtils.addEnvironment;
+
+public class TraceAutoConfigurationTests {
+
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+
+ @After public void close() {
+ context.close();
+ }
+
+ @Test public void defaultsTo64BitTraceId() {
+ context = new AnnotationConfigApplicationContext();
+ context.register(PropertyPlaceholderAutoConfiguration.class,
+ SleuthLogAutoConfiguration.class, TraceAutoConfiguration.class);
+ context.refresh();
+ Tracer tracer = context.getBean(Tracer.class);
+
+ Span span = null;
+ try {
+ span = tracer.createSpan("foo", NeverSampler.INSTANCE);
+ assertThat(span.getTraceIdHigh()).isEqualTo(0L);
+ assertThat(span.getTraceId()).isNotEqualTo(0L);
+ }
+ finally {
+ if (span != null) {
+ tracer.close(span);
+ }
+ }
+ }
+
+ @Test public void optInto128BitTraceId() {
+ addEnvironment(context, "spring.sleuth.traceId128:true");
+ context.register(PropertyPlaceholderAutoConfiguration.class,
+ SleuthLogAutoConfiguration.class, TraceAutoConfiguration.class);
+ context.refresh();
+ Tracer tracer = context.getBean(Tracer.class);
+
+ Span span = null;
+ try {
+ span = tracer.createSpan("foo", NeverSampler.INSTANCE);
+ assertThat(span.getTraceIdHigh()).isNotEqualTo(0L);
+ assertThat(span.getTraceId()).isNotEqualTo(0L);
+ }
+ finally {
+ if (span != null) {
+ tracer.close(span);
+ }
+ }
+ }
+}
diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationWithDisabledSleuthTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationWithDisabledSleuthTests.java
new file mode 100644
index 000000000..415c7392a
--- /dev/null
+++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationWithDisabledSleuthTests.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2013-2016 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.cloud.sleuth.autoconfig;
+
+import java.security.SecureRandom;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = TraceAutoConfigurationWithDisabledSleuthTests.Config.class)
+@TestPropertySource(properties = "spring.sleuth.enabled=false")
+public class TraceAutoConfigurationWithDisabledSleuthTests {
+
+ @Test
+ public void shouldStartContext(){
+
+ }
+
+ @EnableAutoConfiguration
+ static class Config {
+ @Bean
+ public FactoryBean