Search in sources :

Example 1 with HTraceClientProvider

use of org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider in project cxf by apache.

the class HTraceTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients.

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", htraceClientProvider);
    // The intention is to make a calls one after another, not in parallel, to ensure the
    // thread have trace contexts cleared out.
    final Collection<Response> responses = IntStream.range(0, 4).mapToObj(index -> client.async().get()).map(this::get).collect(Collectors.toList());
    for (final Response r : responses) {
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
        assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_SPAN_ID));
    }
    assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(12));
    IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
        assertThat(TestSpanReceiver.getAllSpans().get(index).getDescription(), equalTo("Get Books"));
        assertThat(TestSpanReceiver.getAllSpans().get(index + 1).getDescription(), equalTo("GET bookstore/books"));
        assertThat(TestSpanReceiver.getAllSpans().get(index + 2).getDescription(), equalTo("GET " + client.getCurrentURI()));
    });
}
Also used : Response(javax.ws.rs.core.Response) IntStream(java.util.stream.IntStream) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) IsTimelineContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.htrace.IsTimelineContaining.hasItem) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) TimeoutException(java.util.concurrent.TimeoutException) IsTimelineEmpty.empty(org.apache.cxf.systest.jaxrs.tracing.htrace.IsTimelineEmpty.empty) HashMap(java.util.HashMap) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TestSpanReceiver(org.apache.cxf.systest.htrace.TestSpanReceiver) TracerHeaders(org.apache.cxf.tracing.TracerHeaders) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) BookStore(org.apache.cxf.systest.jaxrs.tracing.BookStore) HTraceConfiguration(org.apache.htrace.core.HTraceConfiguration) Map(java.util.Map) Tracer(org.apache.htrace.core.Tracer) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) AlwaysSampler(org.apache.htrace.core.AlwaysSampler) Status(javax.ws.rs.core.Response.Status) HTraceClientProvider(org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider) Before(org.junit.Before) StandardOutSpanReceiver(org.apache.htrace.core.StandardOutSpanReceiver) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.htrace.HasSpan.hasSpan) MalformedURLException(java.net.MalformedURLException) WebClient(org.apache.cxf.jaxrs.client.WebClient) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TraceScope(org.apache.htrace.core.TraceScope) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) HTraceFeature(org.apache.cxf.tracing.htrace.jaxrs.HTraceFeature) Response(javax.ws.rs.core.Response) Ignore(org.junit.Ignore) AbstractBusTestServerBase(org.apache.cxf.testutil.common.AbstractBusTestServerBase) SpanId(org.apache.htrace.core.SpanId) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 2 with HTraceClientProvider

use of org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider in project cxf by apache.

the class HTraceTracingCustomHeadersTest method setUp.

@Before
public void setUp() {
    final Map<String, String> properties = new HashMap<>();
    properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, StandardOutSpanReceiver.class.getName());
    properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
    tracer = new Tracer.Builder("tracer").conf(HTraceConfiguration.fromMap(properties)).build();
    htraceClientProvider = new HTraceClientProvider(tracer);
}
Also used : StandardOutSpanReceiver(org.apache.htrace.core.StandardOutSpanReceiver) AlwaysSampler(org.apache.htrace.core.AlwaysSampler) HashMap(java.util.HashMap) Tracer(org.apache.htrace.core.Tracer) HTraceClientProvider(org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider) Before(org.junit.Before)

Example 3 with HTraceClientProvider

use of org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider in project cxf by apache.

the class HTraceTracingTest method setUp.

@Before
public void setUp() {
    TestSpanReceiver.clear();
    final Map<String, String> properties = new HashMap<>();
    properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, StandardOutSpanReceiver.class.getName());
    properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
    tracer = new Tracer.Builder("tracer").conf(HTraceConfiguration.fromMap(properties)).build();
    htraceClientProvider = new HTraceClientProvider(tracer);
}
Also used : StandardOutSpanReceiver(org.apache.htrace.core.StandardOutSpanReceiver) AlwaysSampler(org.apache.htrace.core.AlwaysSampler) HashMap(java.util.HashMap) Tracer(org.apache.htrace.core.Tracer) HTraceClientProvider(org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider) Before(org.junit.Before)

Example 4 with HTraceClientProvider

use of org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider in project cxf by apache.

the class HTraceTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients.

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", htraceClientProvider);
    // The intention is to make a calls one after another, not in parallel, to ensure the
    // thread have trace contexts cleared out.
    final Collection<Response> responses = IntStream.range(0, 4).mapToObj(index -> client.get()).collect(Collectors.toList());
    for (final Response r : responses) {
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
        assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_SPAN_ID));
    }
    assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(12));
    IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
        assertThat(TestSpanReceiver.getAllSpans().get(index).getDescription(), equalTo("Get Books"));
        assertThat(TestSpanReceiver.getAllSpans().get(index + 1).getDescription(), equalTo("GET bookstore/books"));
        assertThat(TestSpanReceiver.getAllSpans().get(index + 2).getDescription(), equalTo("GET " + client.getCurrentURI()));
    });
}
Also used : Response(javax.ws.rs.core.Response) IntStream(java.util.stream.IntStream) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) IsTimelineContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.htrace.IsTimelineContaining.hasItem) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) TimeoutException(java.util.concurrent.TimeoutException) IsTimelineEmpty.empty(org.apache.cxf.systest.jaxrs.tracing.htrace.IsTimelineEmpty.empty) HashMap(java.util.HashMap) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TestSpanReceiver(org.apache.cxf.systest.htrace.TestSpanReceiver) TracerHeaders(org.apache.cxf.tracing.TracerHeaders) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) BookStore(org.apache.cxf.systest.jaxrs.tracing.BookStore) HTraceConfiguration(org.apache.htrace.core.HTraceConfiguration) Map(java.util.Map) Tracer(org.apache.htrace.core.Tracer) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) AlwaysSampler(org.apache.htrace.core.AlwaysSampler) Status(javax.ws.rs.core.Response.Status) HTraceClientProvider(org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider) Before(org.junit.Before) StandardOutSpanReceiver(org.apache.htrace.core.StandardOutSpanReceiver) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.htrace.HasSpan.hasSpan) MalformedURLException(java.net.MalformedURLException) WebClient(org.apache.cxf.jaxrs.client.WebClient) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TraceScope(org.apache.htrace.core.TraceScope) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) HTraceFeature(org.apache.cxf.tracing.htrace.jaxrs.HTraceFeature) Response(javax.ws.rs.core.Response) Ignore(org.junit.Ignore) AbstractBusTestServerBase(org.apache.cxf.testutil.common.AbstractBusTestServerBase) SpanId(org.apache.htrace.core.SpanId) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)4 HTraceClientProvider (org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider)4 AlwaysSampler (org.apache.htrace.core.AlwaysSampler)4 StandardOutSpanReceiver (org.apache.htrace.core.StandardOutSpanReceiver)4 Tracer (org.apache.htrace.core.Tracer)4 Before (org.junit.Before)4 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 MalformedURLException (java.net.MalformedURLException)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Map (java.util.Map)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 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2 Status (javax.ws.rs.core.Response.Status)2