Fixed the broken test
This commit is contained in:
@@ -21,20 +21,19 @@ 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.stereotype.Component;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
import rx.functions.Action0;
|
||||
import rx.plugins.SleuthRxJavaPlugins;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.jayway.awaitility.Awaitility.await;
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = {SleuthRxJavaIntegrationTests.TestConfig.class})
|
||||
@DirtiesContext
|
||||
public class SleuthRxJavaIntegrationTests {
|
||||
|
||||
@Autowired Tracer tracer;
|
||||
@@ -53,27 +52,22 @@ public class SleuthRxJavaIntegrationTests {
|
||||
TestSpanContextHolder.removeCurrentSpan();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
if (!(SleuthRxJavaPlugins.getInstance().getSchedulersHook() instanceof SleuthRxJavaSchedulersHook)) {
|
||||
SleuthRxJavaPlugins.resetPlugins();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@BeforeClass
|
||||
public static void cleanUp() {
|
||||
SleuthRxJavaPlugins.resetPlugins();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_create_new_span_when_rx_java_action_is_executed_and_there_was_no_span() {
|
||||
Observable.create((Subscriber<? super Action0> action) -> {
|
||||
action.onNext((Action0) () -> caller = new StringBuilder("actual_action"));
|
||||
}).subscribeOn(Schedulers.newThread()).subscribe(Action0::call);
|
||||
Observable.defer(() -> Observable.just(
|
||||
(Action0) () -> this.caller = new StringBuilder("actual_action")
|
||||
)).subscribeOn(Schedulers.newThread()).toBlocking()
|
||||
.subscribe(Action0::call);
|
||||
|
||||
await().until(() -> then(caller.toString()).isEqualTo("actual_action"));
|
||||
then(this.caller.toString()).isEqualTo("actual_action");
|
||||
then(this.tracer.getCurrentSpan()).isNull();
|
||||
await().until(() -> then(this.listener.getEvents().size()).isEqualTo(1));
|
||||
then(this.listener.getEvents()).hasSize(1);
|
||||
then(this.listener.getEvents().get(0)).hasNameEqualTo("rxjava");
|
||||
then(this.listener.getEvents().get(0)).hasATag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, "rxjava");
|
||||
then(this.listener.getEvents().get(0)).isALocalComponentSpan();
|
||||
@@ -84,23 +78,23 @@ public class SleuthRxJavaIntegrationTests {
|
||||
Span spanInCurrentThread = this.tracer.createSpan("current_span");
|
||||
this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, "current_span");
|
||||
|
||||
Observable.create((Subscriber<? super Action0> action) -> {
|
||||
action.onNext((Action0) () -> caller = new StringBuilder("actual_action"));
|
||||
}).subscribeOn(Schedulers.newThread()).subscribe(Action0::call);
|
||||
Observable.defer(() -> Observable.just(
|
||||
(Action0) () -> this.caller = new StringBuilder("actual_action")
|
||||
)).subscribeOn(Schedulers.newThread()).toBlocking()
|
||||
.subscribe(Action0::call);
|
||||
|
||||
await().until(() -> then(caller.toString()).isEqualTo("actual_action"));
|
||||
then(this.caller.toString()).isEqualTo("actual_action");
|
||||
then(this.tracer.getCurrentSpan()).isNotNull();
|
||||
//making sure here that no new spans were created or reported as closed
|
||||
await().until(() -> then(this.listener.getEvents().size()).isEqualTo(0));
|
||||
then(this.listener.getEvents()).isEmpty();
|
||||
then(spanInCurrentThread).hasNameEqualTo(spanInCurrentThread.getName());
|
||||
then(spanInCurrentThread).hasATag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, "current_span");
|
||||
then(spanInCurrentThread).isALocalComponentSpan();
|
||||
}
|
||||
|
||||
@Component
|
||||
public static class Listener implements SpanReporter {
|
||||
static class Listener implements SpanReporter {
|
||||
|
||||
List<Span> events = new ArrayList<>();
|
||||
private List<Span> events = new ArrayList<>();
|
||||
|
||||
public List<Span> getEvents() {
|
||||
return this.events;
|
||||
@@ -117,7 +111,7 @@ public class SleuthRxJavaIntegrationTests {
|
||||
public static class TestConfig {
|
||||
|
||||
@Bean
|
||||
Listener listener() {
|
||||
SpanReporter listener() {
|
||||
return new Listener();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user