Search in sources :

Example 11 with MockTracer

use of io.opentracing.mock.MockTracer in project wildfly by wildfly.

the class ResourceTracedTestCase method tracedEndpointYieldsSpan.

@Test
public void tracedEndpointYieldsSpan() throws Exception {
    Assert.assertTrue(tracer instanceof MockTracer);
    MockTracer mockTracer = (MockTracer) tracer;
    performCall("opentracing/traced");
    Assert.assertEquals(1, mockTracer.finishedSpans().size());
    // Expected trace if the http-path configuration is not set
    Assert.assertNotEquals("GET:org.wildfly.test.integration.microprofile.opentracing.application.TracedEndpoint.get", mockTracer.finishedSpans().get(0).operationName());
    Assert.assertEquals("GET:/traced/", mockTracer.finishedSpans().get(0).operationName());
    Assert.assertEquals((servletContext.getContextPath() + ".war").substring(1), servletContext.getAttribute("smallrye.opentracing.serviceName"));
}
Also used : MockTracer(io.opentracing.mock.MockTracer) Test(org.junit.Test)

Example 12 with MockTracer

use of io.opentracing.mock.MockTracer in project wildfly by wildfly.

the class ResourceWithCustomOperationNameNoTopicSetupOverrideForAllMessagesTestCase method customOperationName.

@Test
public void customOperationName() throws Exception {
    Assert.assertTrue(tracer instanceof MockTracer);
    MockTracer mockTracer = (MockTracer) tracer;
    performCall("opentracing/with-custom-operation-name");
    List<MockSpan> spans = mockTracer.finishedSpans();
    IntStream.range(0, spans.size()).forEach(idx -> System.out.println("*** " + idx + ": " + spans.get(idx).toString()));
    Assert.assertEquals(3, spans.size());
    Assert.assertEquals("my-custom-method-operation-name", spans.get(0).operationName());
    Assert.assertEquals("my-custom-class-operation-name", spans.get(1).operationName());
    String opName = spans.get(2).operationName();
    Assert.assertTrue(opName, opName.contains(WithCustomOperationNameEndpoint.class.getName()));
}
Also used : MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 13 with MockTracer

use of io.opentracing.mock.MockTracer in project camel by apache.

the class CamelOpenTracingTestSupport method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    tracer = new MockTracer(Propagator.TEXT_MAP);
    OpenTracingTracer ottracer = new OpenTracingTracer();
    ottracer.setTracer(tracer);
    ottracer.init(context);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) MockTracer(io.opentracing.mock.MockTracer)

Example 14 with MockTracer

use of io.opentracing.mock.MockTracer in project camel by apache.

the class SpringOpenTracingSimpleRouteTest method testRoute.

@Test
public void testRoute() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
    for (int i = 0; i < 5; i++) {
        template.sendBody("seda:dude", "Hello World");
    }
    assertTrue(notify.matches(30, TimeUnit.SECONDS));
    MockTracer tracer = (MockTracer) context().getRegistry().lookupByName("mockTracer");
    // Four spans per invocation, one for client, two for dude route (server and client to), one for car route
    assertEquals(20, tracer.finishedSpans().size());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockTracer(io.opentracing.mock.MockTracer) Test(org.junit.Test)

Example 15 with MockTracer

use of io.opentracing.mock.MockTracer in project camel by apache.

the class AbstractHttpSpanDecoratorTest method testPostResponseCode.

@Test
public void testPostResponseCode() {
    Exchange exchange = Mockito.mock(Exchange.class);
    Message message = Mockito.mock(Message.class);
    Mockito.when(exchange.hasOut()).thenReturn(true);
    Mockito.when(exchange.getOut()).thenReturn(message);
    Mockito.when(message.getHeader(Exchange.HTTP_RESPONSE_CODE)).thenReturn(200);
    SpanDecorator decorator = new AbstractHttpSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.post(span, exchange, null);
    assertEquals(200, span.tags().get(Tags.HTTP_STATUS.getKey()));
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Aggregations

MockTracer (io.opentracing.mock.MockTracer)31 Test (org.junit.Test)23 MockSpan (io.opentracing.mock.MockSpan)17 SpanDecorator (org.apache.camel.opentracing.SpanDecorator)13 Endpoint (org.apache.camel.Endpoint)11 Exchange (org.apache.camel.Exchange)10 Message (org.apache.camel.Message)8 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)2 Response (com.weibo.api.motan.rpc.Response)2 Before (org.junit.Before)2 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)1 Request (com.weibo.api.motan.rpc.Request)1 URL (com.weibo.api.motan.rpc.URL)1 Scope (io.opentracing.Scope)1 Tracer (io.opentracing.Tracer)1 ThreadLocalActiveSpanSource (io.opentracing.util.ThreadLocalActiveSpanSource)1 ThreadLocalScopeManager (io.opentracing.util.ThreadLocalScopeManager)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1