Fixed some tests
This commit is contained in:
@@ -16,25 +16,16 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.metric;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration}
|
||||
@@ -44,7 +35,7 @@ import io.micrometer.core.instrument.MeterRegistry;
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Configuration
|
||||
@Conditional(TraceMetricsAutoConfiguration.PickMetricIfMetricsIsMissing.class)
|
||||
@ConditionalOnProperty(value = "spring.sleuth.metric.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties
|
||||
public class TraceMetricsAutoConfiguration {
|
||||
|
||||
@@ -55,11 +46,11 @@ public class TraceMetricsAutoConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(Counter.class)
|
||||
@ConditionalOnClass(MeterRegistry.class)
|
||||
@ConditionalOnMissingBean(SpanMetricReporter.class)
|
||||
protected static class CounterServiceSpanReporterConfig {
|
||||
@Bean
|
||||
@ConditionalOnBean(Counter.class)
|
||||
@ConditionalOnBean(MeterRegistry.class)
|
||||
public SpanMetricReporter spanReporterCounterService(SleuthMetricProperties sleuthMetricProperties,
|
||||
MeterRegistry meterRegistry) {
|
||||
Counter acceptedSpansCounter = Counter.builder(
|
||||
@@ -70,47 +61,16 @@ public class TraceMetricsAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(Counter.class)
|
||||
@ConditionalOnMissingBean(MeterRegistry.class)
|
||||
public SpanMetricReporter noOpSpanReporterCounterService() {
|
||||
return new NoOpSpanMetricReporter();
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingClass("org.springframework.boot.actuate.metrics.CounterService")
|
||||
@ConditionalOnMissingClass("io.micrometer.core.instrument.MeterRegistry")
|
||||
@ConditionalOnMissingBean(SpanMetricReporter.class)
|
||||
public SpanMetricReporter noOpSpanReporterCounterService() {
|
||||
return new NoOpSpanMetricReporter();
|
||||
}
|
||||
|
||||
// TODO: Remove this
|
||||
static class PickMetricIfMetricsIsMissing extends SpringBootCondition {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass());
|
||||
|
||||
static final String DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED = "spring.sleuth.metrics.enabled";
|
||||
static final String SPRING_SLEUTH_METRIC_ENABLED = "spring.sleuth.metric.enabled";
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
Boolean oldValue = context.getEnvironment().getProperty(DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED, Boolean.class);
|
||||
Boolean newValue = context.getEnvironment().getProperty(SPRING_SLEUTH_METRIC_ENABLED, Boolean.class);
|
||||
if (oldValue != null) {
|
||||
log.warn("You're using an old version of the metrics property. Instead of using [" +
|
||||
DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED + "] please use [" + SPRING_SLEUTH_METRIC_ENABLED + "]");
|
||||
return matchCondition(oldValue, DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED);
|
||||
}
|
||||
if (newValue != null) {
|
||||
return matchCondition(newValue, SPRING_SLEUTH_METRIC_ENABLED);
|
||||
}
|
||||
return ConditionOutcome.match("No property was passed - assuming that metrics are enabled.");
|
||||
}
|
||||
|
||||
private ConditionOutcome matchCondition(Boolean value, String property) {
|
||||
if (Boolean.TRUE.equals(value)) {
|
||||
return ConditionOutcome.match();
|
||||
}
|
||||
return ConditionOutcome.noMatch("Property [" + property + "] is set to false.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,12 @@ import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfigurati
|
||||
import org.springframework.cloud.sleuth.instrument.messaging.TraceSpringIntegrationAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.instrument.messaging.websocket.TraceWebSocketAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@EnableAutoConfiguration(exclude = { LoadBalancerAutoConfiguration.class,
|
||||
JmxAutoConfiguration.class, TraceSpringIntegrationAutoConfiguration.class,
|
||||
TraceWebSocketAutoConfiguration.class })
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
@Configuration
|
||||
public @interface DefaultTestAutoConfiguration {
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.cloud.sleuth.instrument.scheduling;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,6 +29,7 @@ import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.TestSpanContextHolder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -46,40 +46,49 @@ public class TracingOnScheduledTests {
|
||||
@Autowired
|
||||
TestBeanWithScheduledMethodToBeIgnored beanWithScheduledMethodToBeIgnored;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.beanWithScheduledMethod.clear();
|
||||
this.beanWithScheduledMethodToBeIgnored.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_have_span_set_after_scheduled_method_has_been_executed() {
|
||||
await().atMost(5, SECONDS).untilAsserted(this::spanIsSetOnAScheduledMethod);
|
||||
await().atMost( 10, SECONDS).untilAsserted(() -> {
|
||||
then(this.beanWithScheduledMethod.isExecuted()).isTrue();
|
||||
spanIsSetOnAScheduledMethod();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_have_a_new_span_set_each_time_a_scheduled_method_has_been_executed() {
|
||||
final Span firstSpan = this.beanWithScheduledMethod.getSpan();
|
||||
await().atMost(5, SECONDS).untilAsserted(() -> differentSpanHasBeenSetThan(firstSpan));
|
||||
await().atMost(5, SECONDS).untilAsserted(() -> {
|
||||
then(this.beanWithScheduledMethod.isExecuted()).isTrue();
|
||||
differentSpanHasBeenSetThan(firstSpan);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Fix this
|
||||
@Test
|
||||
@Ignore("doesn't work with Boot 2.0")
|
||||
public void should_not_span_in_the_scheduled_class_that_matches_skip_pattern()
|
||||
public void should_not_create_span_in_the_scheduled_class_that_matches_skip_pattern()
|
||||
throws Exception {
|
||||
await().atMost(5, SECONDS).untilAtomic(
|
||||
this.beanWithScheduledMethodToBeIgnored.isExecuted(), Matchers.is(true));
|
||||
then(this.beanWithScheduledMethodToBeIgnored.getSpan()).isNull();
|
||||
await().atMost(5, SECONDS).untilAsserted(() -> {
|
||||
then(this.beanWithScheduledMethodToBeIgnored.isExecuted()).isTrue();
|
||||
then(this.beanWithScheduledMethodToBeIgnored.getSpan()).isNull();
|
||||
});
|
||||
}
|
||||
|
||||
private Runnable spanIsSetOnAScheduledMethod() {
|
||||
return () -> {
|
||||
Span storedSpan = TracingOnScheduledTests.this.beanWithScheduledMethod
|
||||
.getSpan();
|
||||
then(storedSpan).isNotNull();
|
||||
then(storedSpan.getTraceId()).isNotNull();
|
||||
then(storedSpan).hasATag("class", "TestBeanWithScheduledMethod");
|
||||
then(storedSpan).hasATag("method", "scheduledMethod");
|
||||
};
|
||||
private void spanIsSetOnAScheduledMethod() {
|
||||
Span storedSpan = TracingOnScheduledTests.this.beanWithScheduledMethod
|
||||
.getSpan();
|
||||
then(storedSpan).isNotNull();
|
||||
then(storedSpan.getTraceId()).isNotNull();
|
||||
then(storedSpan).hasATag("class", "TestBeanWithScheduledMethod");
|
||||
then(storedSpan).hasATag("method", "scheduledMethod");
|
||||
}
|
||||
|
||||
private Runnable differentSpanHasBeenSetThan(final Span spanToCompare) {
|
||||
return () -> then(TracingOnScheduledTests.this.beanWithScheduledMethod.getSpan())
|
||||
private void differentSpanHasBeenSetThan(final Span spanToCompare) {
|
||||
then(TracingOnScheduledTests.this.beanWithScheduledMethod.getSpan())
|
||||
.isNotEqualTo(spanToCompare);
|
||||
}
|
||||
|
||||
@@ -87,6 +96,7 @@ public class TracingOnScheduledTests {
|
||||
|
||||
@Configuration
|
||||
@DefaultTestAutoConfiguration
|
||||
@EnableScheduling
|
||||
class ScheduledTestConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -110,14 +120,25 @@ class TestBeanWithScheduledMethod {
|
||||
|
||||
Span span;
|
||||
|
||||
AtomicBoolean executed = new AtomicBoolean(false);
|
||||
|
||||
@Scheduled(fixedDelay = 1L)
|
||||
public void scheduledMethod() {
|
||||
this.span = TestSpanContextHolder.getCurrentSpan();
|
||||
this.executed.set(true);
|
||||
}
|
||||
|
||||
public Span getSpan() {
|
||||
return this.span;
|
||||
}
|
||||
|
||||
public AtomicBoolean isExecuted() {
|
||||
return this.executed;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.executed.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
class TestBeanWithScheduledMethodToBeIgnored {
|
||||
@@ -138,4 +159,8 @@ class TestBeanWithScheduledMethodToBeIgnored {
|
||||
public AtomicBoolean isExecuted() {
|
||||
return this.executed;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.executed.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
@@ -57,12 +58,10 @@ import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
// TODO: Fix this
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ReservationServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
@ActiveProfiles("data")
|
||||
@Ignore("doesn't work with Boot 2.0")
|
||||
public class SpringDataInstrumentationTests {
|
||||
|
||||
@Autowired
|
||||
@@ -108,7 +107,7 @@ public class SpringDataInstrumentationTests {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
|
||||
@EntityScan(basePackageClasses = Reservation.class)
|
||||
class ReservationServiceApplication {
|
||||
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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.metric;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.cloud.sleuth.metric.TraceMetricsAutoConfiguration.PickMetricIfMetricsIsMissing;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.cloud.sleuth.metric.TraceMetricsAutoConfiguration.PickMetricIfMetricsIsMissing.DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED;
|
||||
import static org.springframework.cloud.sleuth.metric.TraceMetricsAutoConfiguration.PickMetricIfMetricsIsMissing.SPRING_SLEUTH_METRIC_ENABLED;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TraceMetricsAutoConfigurationTests {
|
||||
|
||||
@Mock ConditionContext conditionContext;
|
||||
@Mock AnnotatedTypeMetadata annotatedTypeMetadata;
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
|
||||
PickMetricIfMetricsIsMissing condition = new PickMetricIfMetricsIsMissing();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
BDDMockito.given(this.conditionContext.getEnvironment()).willReturn(this.mockEnvironment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_turn_on_the_feature_when_no_explicit_one_was_provided() {
|
||||
ConditionOutcome outcome = this.condition.getMatchOutcome(this.conditionContext, this.annotatedTypeMetadata);
|
||||
|
||||
then(outcome.isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_turn_on_the_feature_when_deprecated_property_is_enabled() {
|
||||
this.mockEnvironment.setProperty(DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED, "true");
|
||||
|
||||
ConditionOutcome outcome = this.condition.getMatchOutcome(this.conditionContext, this.annotatedTypeMetadata);
|
||||
|
||||
then(outcome.isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_turn_off_the_feature_when_deprecated_property_is_disabled() {
|
||||
this.mockEnvironment.setProperty(DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED, "false");
|
||||
|
||||
ConditionOutcome outcome = this.condition.getMatchOutcome(this.conditionContext, this.annotatedTypeMetadata);
|
||||
|
||||
then(outcome.isMatch()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_turn_on_the_feature_when_property_is_enabled() {
|
||||
this.mockEnvironment.setProperty(SPRING_SLEUTH_METRIC_ENABLED, "true");
|
||||
|
||||
ConditionOutcome outcome = this.condition.getMatchOutcome(this.conditionContext, this.annotatedTypeMetadata);
|
||||
|
||||
then(outcome.isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_turn_off_the_feature_when_property_is_disabled() {
|
||||
this.mockEnvironment.setProperty(SPRING_SLEUTH_METRIC_ENABLED, "false");
|
||||
|
||||
ConditionOutcome outcome = this.condition.getMatchOutcome(this.conditionContext, this.annotatedTypeMetadata);
|
||||
|
||||
then(outcome.isMatch()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_turn_on_the_feature_when_new_property_is_disabled_and_old_is_enabled() {
|
||||
this.mockEnvironment.setProperty(DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED, "true");
|
||||
this.mockEnvironment.setProperty(SPRING_SLEUTH_METRIC_ENABLED, "false");
|
||||
|
||||
ConditionOutcome outcome = this.condition.getMatchOutcome(this.conditionContext, this.annotatedTypeMetadata);
|
||||
|
||||
then(outcome.isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_turn_off_the_feature_when_new_property_is_disabled_and_old_is_enabled() {
|
||||
this.mockEnvironment.setProperty(DEPRECATED_SPRING_SLEUTH_METRICS_ENABLED, "false");
|
||||
this.mockEnvironment.setProperty(SPRING_SLEUTH_METRIC_ENABLED, "true");
|
||||
|
||||
ConditionOutcome outcome = this.condition.getMatchOutcome(this.conditionContext, this.annotatedTypeMetadata);
|
||||
|
||||
then(outcome.isMatch()).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
|
||||
@EnableAsync
|
||||
@IntegrationComponentScan
|
||||
@RestController
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
|
||||
@EnableAsync
|
||||
public class SampleSleuthApplication {
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import zipkin2.reporter.Reporter;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
|
||||
@EnableAsync
|
||||
public class SampleZipkinApplication {
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
|
||||
@EnableAsync
|
||||
public class SampleSleuthApplication {
|
||||
|
||||
|
||||
@@ -67,6 +67,11 @@
|
||||
<artifactId>awaitility</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -16,20 +16,17 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
@@ -59,14 +56,18 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
// TODO: Fix me
|
||||
@SpringBootTest(classes = TestConfiguration.class, webEnvironment = WebEnvironment.NONE)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@Ignore
|
||||
public class StreamSpanListenerTests {
|
||||
|
||||
@Autowired
|
||||
@@ -78,9 +79,9 @@ public class StreamSpanListenerTests {
|
||||
@Autowired
|
||||
StreamSpanReporter listener;
|
||||
@Autowired
|
||||
Counter counter;
|
||||
@Autowired
|
||||
SpanReporter spanReporter;
|
||||
@Autowired
|
||||
MeterRegistry meterRegistry;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
@@ -139,7 +140,10 @@ public class StreamSpanListenerTests {
|
||||
this.tracer.close(context);
|
||||
this.listener.poll();
|
||||
|
||||
verify(this.counter, atLeastOnce()).increment();
|
||||
Optional<Counter> counter = this.meterRegistry.find("counter.span.accepted")
|
||||
.counter();
|
||||
then(counter.isPresent()).isTrue();
|
||||
then(counter.get().count()).isGreaterThan(0d);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,8 +212,8 @@ public class StreamSpanListenerTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
Counter counter() {
|
||||
return Mockito.mock(Counter.class);
|
||||
public MeterRegistry testMeterRegistry() {
|
||||
return new SimpleMeterRegistry();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -13,16 +12,15 @@ import org.springframework.context.annotation.Configuration;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Matcin Wielgus
|
||||
* @author Marcin Wielgus
|
||||
*/
|
||||
//TODO: Fix me
|
||||
@Ignore
|
||||
public class DiscoveryClientEndpointLocatorConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void endpointLocatorShouldDefaultToServerPropertiesEndpointLocator() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
EmptyConfiguration.class).run("--spring.jmx.enabled=false");
|
||||
EmptyConfiguration.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.cloud.discovery.client.composite-indicator.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isInstanceOf(ServerPropertiesEndpointLocator.class);
|
||||
ctxt.close();
|
||||
@@ -31,7 +29,8 @@ public class DiscoveryClientEndpointLocatorConfigurationTest {
|
||||
@Test
|
||||
public void endpointLocatorShouldDefaultToServerPropertiesEndpointLocatorEvenWhenDiscoveryClientPresent() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithDiscoveryClient.class).run("--spring.jmx.enabled=false");
|
||||
ConfigurationWithDiscoveryClient.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.cloud.discovery.client.composite-indicator.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isInstanceOf(ServerPropertiesEndpointLocator.class);
|
||||
ctxt.close();
|
||||
@@ -40,7 +39,8 @@ public class DiscoveryClientEndpointLocatorConfigurationTest {
|
||||
@Test
|
||||
public void endpointLocatorShouldRespectExistingEndpointLocator() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithCustomLocator.class).run("--spring.jmx.enabled=false");
|
||||
ConfigurationWithCustomLocator.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.cloud.discovery.client.composite-indicator.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isSameAs(ConfigurationWithCustomLocator.locator);
|
||||
ctxt.close();
|
||||
@@ -50,7 +50,8 @@ public class DiscoveryClientEndpointLocatorConfigurationTest {
|
||||
public void endpointLocatorShouldBeFallbackHavingEndpointLocatorWhenAskedTo() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithDiscoveryClient.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.zipkin.locator.discovery.enabled=true");
|
||||
"--spring.zipkin.locator.discovery.enabled=true",
|
||||
"--spring.cloud.discovery.client.composite-indicator.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isInstanceOf(FallbackHavingEndpointLocator.class);
|
||||
ctxt.close();
|
||||
@@ -61,7 +62,8 @@ public class DiscoveryClientEndpointLocatorConfigurationTest {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithDiscoveryClient.class,
|
||||
ConfigurationWithCustomLocator.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.zipkin.locator.discovery.enabled=true");
|
||||
"--spring.zipkin.locator.discovery.enabled=true",
|
||||
"--spring.cloud.discovery.client.composite-indicator.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isSameAs(ConfigurationWithCustomLocator.locator);
|
||||
ctxt.close();
|
||||
|
||||
@@ -31,11 +31,10 @@ import org.springframework.util.SocketUtils;
|
||||
|
||||
import zipkin.junit.ZipkinRule;
|
||||
|
||||
// TODO: Fix me
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ZipkinDiscoveryClientTests.Config.class,
|
||||
properties = "spring.zipkin.baseUrl=http://zipkin/")
|
||||
@Ignore
|
||||
@SpringBootTest(classes = ZipkinDiscoveryClientTests.Config.class, properties = {
|
||||
"spring.zipkin.baseUrl=http://zipkin/",
|
||||
"spring.cloud.discovery.client.composite-indicator.enabled=false" })
|
||||
public class ZipkinDiscoveryClientTests {
|
||||
|
||||
@ClassRule public static ZipkinRule ZIPKIN_RULE = new ZipkinRule();
|
||||
|
||||
Reference in New Issue
Block a user