Merge branch '2.2.x'

This commit is contained in:
Adrian Cole
2020-05-18 20:20:40 +08:00
93 changed files with 1043 additions and 1382 deletions

View File

@@ -29,6 +29,7 @@ import java.util.concurrent.ThreadFactory;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.test.TestSpanHandler;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -38,8 +39,6 @@ import rx.plugins.RxJavaObservableExecutionHook;
import rx.plugins.RxJavaPlugins;
import rx.plugins.RxJavaSchedulersHook;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
import static org.assertj.core.api.BDDAssertions.then;
/**
@@ -53,17 +52,17 @@ public class SleuthRxJavaSchedulersHookTests {
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
TestSpanHandler spans = new TestSpanHandler();
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
.spanReporter(this.reporter).build();
.addSpanHandler(this.spans).build();
Tracer tracer = this.tracing.tracer();
@AfterEach
public void clean() {
this.tracing.close();
this.reporter.clear();
this.spans.clear();
this.currentTraceContext.close();
}
@@ -101,7 +100,7 @@ public class SleuthRxJavaSchedulersHookTests {
then(action).isInstanceOf(SleuthRxJavaSchedulersHook.TraceAction.class);
then(caller.toString()).isEqualTo("called_from_schedulers_hook");
then(this.reporter.getSpans()).isNotEmpty();
then(this.spans).isNotEmpty();
then(this.tracer.currentSpan()).isNull();
}
@@ -122,7 +121,7 @@ public class SleuthRxJavaSchedulersHookTests {
hello.get();
then(this.reporter.getSpans()).isEmpty();
then(this.spans).isEmpty();
then(this.tracer.currentSpan()).isNull();
}

View File

@@ -18,7 +18,9 @@ package org.springframework.cloud.sleuth.instrument.rxjava;
import brave.Span;
import brave.Tracer;
import brave.handler.SpanHandler;
import brave.sampler.Sampler;
import brave.test.TestSpanHandler;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -31,7 +33,6 @@ import rx.schedulers.Schedulers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
@@ -45,7 +46,7 @@ import static org.awaitility.Awaitility.await;
public class SleuthRxJavaTests {
@Autowired
ArrayListSpanReporter reporter;
TestSpanHandler spans;
@Autowired
Tracer tracer;
@@ -60,7 +61,7 @@ public class SleuthRxJavaTests {
@BeforeEach
public void clean() {
this.reporter.clear();
this.spans.clear();
}
@Test
@@ -73,11 +74,9 @@ public class SleuthRxJavaTests {
then(this.caller.toString()).isEqualTo("actual_action");
then(this.tracer.currentSpan()).isNull();
await().atMost(5, SECONDS)
.untilAsserted(() -> then(this.reporter.getSpans()).hasSize(1));
then(this.reporter.getSpans()).hasSize(1);
zipkin2.Span span = this.reporter.getSpans().get(0);
then(span.name()).isEqualTo("rxjava");
await().atMost(5, SECONDS).untilAsserted(() -> then(this.spans).hasSize(1));
then(this.spans).hasSize(1);
then(this.spans.get(0).name()).isEqualTo("rxjava");
}
@Test
@@ -97,9 +96,8 @@ public class SleuthRxJavaTests {
then(this.caller.toString()).isEqualTo("actual_action");
then(this.tracer.currentSpan()).isNull();
// making sure here that no new spans were created or reported as closed
then(this.reporter.getSpans()).hasSize(1);
zipkin2.Span span = this.reporter.getSpans().get(0);
then(span.name()).isEqualTo("current_span");
then(this.spans).hasSize(1);
then(this.spans.get(0).name()).isEqualTo("current_span");
}
@Configuration
@@ -112,8 +110,8 @@ public class SleuthRxJavaTests {
}
@Bean
ArrayListSpanReporter spanReporter() {
return new ArrayListSpanReporter();
SpanHandler testSpanHandler() {
return new TestSpanHandler();
}
}