Search in sources :

Example 6 with BookStore

use of org.apache.cxf.systest.jaxrs.tracing.BookStore in project cxf by apache.

the class OpenTracingTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients.

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", new OpenTracingClientProvider(tracer));
    // 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(REPORTER.getSpans().size(), equalTo(12));
    IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
        assertThat(REPORTER.getSpans().get(index).getOperationName(), equalTo("Get Books"));
        assertThat(REPORTER.getSpans().get(index + 1).getOperationName(), equalTo("GET /bookstore/books"));
        assertThat(REPORTER.getSpans().get(index + 2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
    });
}
Also used : Arrays(java.util.Arrays) IsLogContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.opentracing.IsLogContaining.hasItem) TimeoutException(java.util.concurrent.TimeoutException) Builtin(io.opentracing.propagation.Format.Builtin) AbstractClientServerTestBase(org.apache.cxf.testutil.common.AbstractClientServerTestBase) AbstractTestServerBase(org.apache.cxf.testutil.common.AbstractTestServerBase) Tags(io.opentracing.tag.Tags) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) Duration(java.time.Duration) NullPointerExceptionMapper(org.apache.cxf.systest.jaxrs.tracing.NullPointerExceptionMapper) After(org.junit.After) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) IsTagContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.opentracing.IsTagContaining.hasItem) OpenTracingFeature(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingFeature) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Awaitility.await(org.awaitility.Awaitility.await) Response(javax.ws.rs.core.Response) TextMap(io.opentracing.propagation.TextMap) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.opentracing.HasSpan.hasSpan) Entry(java.util.Map.Entry) ProcessingException(javax.ws.rs.ProcessingException) Span(io.opentracing.Span) Scope(io.opentracing.Scope) JaegerTracer(io.jaegertracing.internal.JaegerTracer) IntStream(java.util.stream.IntStream) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) OpenTracingClientProvider(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider) 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) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Status(javax.ws.rs.core.Response.Status) ExpectedException(org.junit.rules.ExpectedException) Matchers.empty(org.hamcrest.Matchers.empty) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Iterator(java.util.Iterator) Tracer(io.opentracing.Tracer) MalformedURLException(java.net.MalformedURLException) OpenTracingClientFeature(org.apache.cxf.tracing.opentracing.OpenTracingClientFeature) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) 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) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) OpenTracingClientProvider(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)6 MalformedURLException (java.net.MalformedURLException)6 Arrays (java.util.Arrays)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6 TimeUnit (java.util.concurrent.TimeUnit)6 TimeoutException (java.util.concurrent.TimeoutException)6 IntStream (java.util.stream.IntStream)6 MediaType (javax.ws.rs.core.MediaType)6 Response (javax.ws.rs.core.Response)6 Status (javax.ws.rs.core.Response.Status)6 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)6 WebClient (org.apache.cxf.jaxrs.client.WebClient)6 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)6 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)6 BookStore (org.apache.cxf.systest.jaxrs.tracing.BookStore)6 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)6 BeforeClass (org.junit.BeforeClass)6 Test (org.junit.Test)6 Duration (java.time.Duration)4