Search in sources :

Example 6 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients.

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", new BraveClientProvider(brave));
    // The intention is to make a calls one after another, not in parallel, to ensure the
    // thread have trace contexts cleared out.
    IntStream.range(0, 4).mapToObj(index -> client.get()).forEach(r -> assertEquals(Status.OK.getStatusCode(), r.getStatus()));
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(12));
    IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
        assertThat(TestSpanReporter.getAllSpans().get(index).name(), equalTo("get books"));
        assertThat(TestSpanReporter.getAllSpans().get(index + 1).name(), equalTo("get /bookstore/books"));
        assertThat(TestSpanReporter.getAllSpans().get(index + 2).name(), equalTo("get " + client.getCurrentURI()));
    });
}
Also used : Arrays(java.util.Arrays) SPAN_ID_NAME(org.apache.cxf.systest.brave.BraveTestSupport.SPAN_ID_NAME) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) BraveFeature(org.apache.cxf.tracing.brave.jaxrs.BraveFeature) TimeoutException(java.util.concurrent.TimeoutException) Span(brave.Span) AbstractClientServerTestBase(org.apache.cxf.testutil.common.AbstractClientServerTestBase) AbstractTestServerBase(org.apache.cxf.testutil.common.AbstractTestServerBase) SpanId(org.apache.cxf.systest.brave.BraveTestSupport.SpanId) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) TRACE_ID_NAME(org.apache.cxf.systest.brave.BraveTestSupport.TRACE_ID_NAME) Sampler(brave.sampler.Sampler) TraceScope(org.apache.cxf.tracing.brave.TraceScope) Duration(java.time.Duration) NullPointerExceptionMapper(org.apache.cxf.systest.jaxrs.tracing.NullPointerExceptionMapper) After(org.junit.After) IsMapContaining.hasEntry(org.hamcrest.collection.IsMapContaining.hasEntry) Awaitility.await(org.awaitility.Awaitility.await) IsMapContaining.hasKey(org.hamcrest.collection.IsMapContaining.hasKey) PARENT_SPAN_ID_NAME(org.apache.cxf.systest.brave.BraveTestSupport.PARENT_SPAN_ID_NAME) Response(javax.ws.rs.core.Response) Assert.assertFalse(org.junit.Assert.assertFalse) ProcessingException(javax.ws.rs.ProcessingException) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan) IntStream(java.util.stream.IntStream) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) BookStore(org.apache.cxf.systest.jaxrs.tracing.BookStore) SAMPLED_NAME(org.apache.cxf.systest.brave.BraveTestSupport.SAMPLED_NAME) IsAnnotationContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.brave.IsAnnotationContaining.hasItem) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Status(javax.ws.rs.core.Response.Status) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) SpanInScope(brave.Tracer.SpanInScope) Tracing(brave.Tracing) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) MalformedURLException(java.net.MalformedURLException) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) Rule(org.junit.Rule) BraveClientFeature(org.apache.cxf.tracing.brave.BraveClientFeature) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 7 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method testThatNoSpansAreRecordedWhenNotSampled.

@Test
public void testThatNoSpansAreRecordedWhenNotSampled() {
    final Tracing never = Tracing.newBuilder().spanReporter(new TestSpanReporter()).sampler(Sampler.NEVER_SAMPLE).build();
    final Response r = createWebClient("/bookstore/books", new BraveClientProvider(never)).get();
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(0));
}
Also used : Response(javax.ws.rs.core.Response) Tracing(brave.Tracing) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) Test(org.junit.Test)

Example 8 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients.

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", new BraveClientProvider(brave));
    // The intention is to make a calls one after another, not in parallel, to ensure the
    // thread have trace contexts cleared out.
    IntStream.range(0, 4).mapToObj(index -> client.async().get()).map(this::get).forEach(r -> assertEquals(Status.OK.getStatusCode(), r.getStatus()));
    assertThat(TestSpanReporter.getAllSpans().toString(), TestSpanReporter.getAllSpans().size(), equalTo(12));
    IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
        assertThat(TestSpanReporter.getAllSpans().get(index).name(), equalTo("get books"));
        assertThat(TestSpanReporter.getAllSpans().get(index + 1).name(), equalTo("get /bookstore/books"));
        assertThat(TestSpanReporter.getAllSpans().get(index + 2).name(), equalTo("get " + client.getCurrentURI()));
    });
}
Also used : Arrays(java.util.Arrays) SPAN_ID_NAME(org.apache.cxf.systest.brave.BraveTestSupport.SPAN_ID_NAME) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) BraveFeature(org.apache.cxf.tracing.brave.jaxrs.BraveFeature) TimeoutException(java.util.concurrent.TimeoutException) Span(brave.Span) AbstractClientServerTestBase(org.apache.cxf.testutil.common.AbstractClientServerTestBase) AbstractTestServerBase(org.apache.cxf.testutil.common.AbstractTestServerBase) SpanId(org.apache.cxf.systest.brave.BraveTestSupport.SpanId) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) TRACE_ID_NAME(org.apache.cxf.systest.brave.BraveTestSupport.TRACE_ID_NAME) Sampler(brave.sampler.Sampler) TraceScope(org.apache.cxf.tracing.brave.TraceScope) Duration(java.time.Duration) NullPointerExceptionMapper(org.apache.cxf.systest.jaxrs.tracing.NullPointerExceptionMapper) After(org.junit.After) IsMapContaining.hasEntry(org.hamcrest.collection.IsMapContaining.hasEntry) Awaitility.await(org.awaitility.Awaitility.await) IsMapContaining.hasKey(org.hamcrest.collection.IsMapContaining.hasKey) PARENT_SPAN_ID_NAME(org.apache.cxf.systest.brave.BraveTestSupport.PARENT_SPAN_ID_NAME) Response(javax.ws.rs.core.Response) Assert.assertFalse(org.junit.Assert.assertFalse) ProcessingException(javax.ws.rs.ProcessingException) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan) IntStream(java.util.stream.IntStream) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) BookStore(org.apache.cxf.systest.jaxrs.tracing.BookStore) SAMPLED_NAME(org.apache.cxf.systest.brave.BraveTestSupport.SAMPLED_NAME) IsAnnotationContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.brave.IsAnnotationContaining.hasItem) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Status(javax.ws.rs.core.Response.Status) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) SpanInScope(brave.Tracer.SpanInScope) Tracing(brave.Tracing) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) MalformedURLException(java.net.MalformedURLException) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) Rule(org.junit.Rule) BraveClientFeature(org.apache.cxf.tracing.brave.BraveClientFeature) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 9 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient.

@Test
public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", new BraveClientProvider(brave));
    final Future<Response> f = client.async().get();
    final Response r = f.get(1, TimeUnit.SECONDS);
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
    assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
    assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
    assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
}
Also used : Response(javax.ws.rs.core.Response) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

BraveClientProvider (org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider)9 Response (javax.ws.rs.core.Response)7 Test (org.junit.Test)7 WebClient (org.apache.cxf.jaxrs.client.WebClient)5 Span (brave.Span)4 SpanInScope (brave.Tracer.SpanInScope)4 TestSpanReporter (org.apache.cxf.systest.brave.TestSpanReporter)4 HasSpan.hasSpan (org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan)4 Tracing (brave.Tracing)3 Sampler (brave.sampler.Sampler)2 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 MalformedURLException (java.net.MalformedURLException)2 Duration (java.time.Duration)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 TimeUnit (java.util.concurrent.TimeUnit)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2