Search in sources :

Example 1 with ArrayListSpanReporter

use of org.springframework.cloud.sleuth.util.ArrayListSpanReporter in project spring-cloud-sleuth by spring-cloud.

the class FactoryUser method should_work_with_flat_maps.

@Test
public void should_work_with_flat_maps() {
    // given
    ConfigurableApplicationContext context = new SpringApplicationBuilder(FlatMapTests.TestConfiguration.class, Issue866Configuration.class).web(WebApplicationType.REACTIVE).properties("server.port=0", "spring.jmx.enabled=false", "spring.application.name=TraceWebFluxTests", "security.basic.enabled=false", "management.security.enabled=false").run();
    ArrayListSpanReporter accumulator = context.getBean(ArrayListSpanReporter.class);
    int port = context.getBean(Environment.class).getProperty("local.server.port", Integer.class);
    RequestSender sender = context.getBean(RequestSender.class);
    TestConfiguration config = context.getBean(TestConfiguration.class);
    FactoryUser factoryUser = context.getBean(FactoryUser.class);
    sender.port = port;
    accumulator.clear();
    Awaitility.await().untilAsserted(() -> {
        // when
        accumulator.clear();
        String firstTraceId = flatMapTraceId(accumulator, callFlatMap(port).block());
        // then
        thenAllWebClientCallsHaveSameTraceId(firstTraceId, sender);
        thenSpanInFooHasSameTraceId(firstTraceId, config);
        accumulator.clear();
        // when
        String secondTraceId = flatMapTraceId(accumulator, callFlatMap(port).block());
        // then
        then(firstTraceId).as("Id will not be reused between calls").isNotEqualTo(secondTraceId);
        thenSpanInFooHasSameTraceId(secondTraceId, config);
        // and
        then(Arrays.stream(capture.toString().split("\n")).filter(s -> s.contains("Received a request to uri")).map(s -> s.split(",")[1]).collect(Collectors.toList())).as("TraceFilter should not have any trace when receiving a request").containsOnly("");
        // and #866
        then(factoryUser.wasSchedulerWrapped).isTrue();
    });
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Arrays(java.util.Arrays) ReactiveUserDetailsServiceAutoConfiguration(org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) WebClient(org.springframework.web.reactive.function.client.WebClient) Hooks(reactor.core.publisher.Hooks) Span(zipkin2.Span) Scheduler(reactor.core.scheduler.Scheduler) Sampler(brave.sampler.Sampler) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Schedulers(reactor.core.scheduler.Schedulers) Issue866Configuration(org.springframework.cloud.sleuth.instrument.reactor.Issue866Configuration) OutputCapture(org.springframework.boot.test.rule.OutputCapture) RouterFunctions.route(org.springframework.web.reactive.function.server.RouterFunctions.route) ReactiveSecurityAutoConfiguration(org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration) AfterClass(org.junit.AfterClass) ClientResponse(org.springframework.web.reactive.function.client.ClientResponse) Tracer(brave.Tracer) Logger(org.slf4j.Logger) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Import(org.springframework.context.annotation.Import) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) List(java.util.List) Rule(org.junit.Rule) RouterFunction(org.springframework.web.reactive.function.server.RouterFunction) Environment(org.springframework.core.env.Environment) ServerResponse(org.springframework.web.reactive.function.server.ServerResponse) WebApplicationType(org.springframework.boot.WebApplicationType) GET(org.springframework.web.reactive.function.server.RequestPredicates.GET) Bean(org.springframework.context.annotation.Bean) Awaitility(org.awaitility.Awaitility) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.core.env.Environment) Issue866Configuration(org.springframework.cloud.sleuth.instrument.reactor.Issue866Configuration) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) Test(org.junit.Test)

Example 2 with ArrayListSpanReporter

use of org.springframework.cloud.sleuth.util.ArrayListSpanReporter in project spring-cloud-sleuth by spring-cloud.

the class TraceWebFluxTests method should_instrument_web_filter.

@Test
public void should_instrument_web_filter() throws Exception {
    // setup
    ConfigurableApplicationContext context = new SpringApplicationBuilder(TraceWebFluxTests.Config.class).web(WebApplicationType.REACTIVE).properties("server.port=0", "spring.jmx.enabled=false", "spring.sleuth.web.skipPattern=/skipped", "spring.application.name=TraceWebFluxTests", "security.basic.enabled=false", "management.security.enabled=false").run();
    ArrayListSpanReporter accumulator = context.getBean(ArrayListSpanReporter.class);
    int port = context.getBean(Environment.class).getProperty("local.server.port", Integer.class);
    Controller2 controller2 = context.getBean(Controller2.class);
    clean(accumulator, controller2);
    // when
    ClientResponse response = whenRequestIsSent(port);
    // then
    thenSpanWasReportedWithTags(accumulator, response);
    clean(accumulator, controller2);
    // when
    ClientResponse nonSampledResponse = whenNonSampledRequestIsSent(port);
    // then
    thenNoSpanWasReported(accumulator, nonSampledResponse, controller2);
    // when
    ClientResponse skippedPatternResponse = whenRequestIsSentToSkippedPattern(port);
    // then
    thenNoSpanWasReported(accumulator, skippedPatternResponse, controller2);
    // cleanup
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClientResponse(org.springframework.web.reactive.function.client.ClientResponse) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.core.env.Environment) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)2 ArrayListSpanReporter (org.springframework.cloud.sleuth.util.ArrayListSpanReporter)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 Environment (org.springframework.core.env.Environment)2 ClientResponse (org.springframework.web.reactive.function.client.ClientResponse)2 Tracer (brave.Tracer)1 Sampler (brave.sampler.Sampler)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 BDDAssertions.then (org.assertj.core.api.BDDAssertions.then)1 Awaitility (org.awaitility.Awaitility)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 Rule (org.junit.Rule)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 WebApplicationType (org.springframework.boot.WebApplicationType)1 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)1