Search in sources :

Example 6 with MockTracer

use of io.opentracing.mock.MockTracer in project ballerina by ballerina-lang.

the class BMockTracer method getTracer.

@Override
public Tracer getTracer(String tracerName, Properties configProperties, String serviceName) throws InvalidConfigurationException {
    MockTracer mockTracer = new MockTracer();
    BMockTracer.tracerMap.add(mockTracer);
    return mockTracer;
}
Also used : MockTracer(io.opentracing.mock.MockTracer)

Example 7 with MockTracer

use of io.opentracing.mock.MockTracer in project motan by weibocom.

the class OpenTracingFilterTest method checkMockTracer.

private void checkMockTracer() {
    if (tracer instanceof MockTracer) {
        MockTracer mt = (MockTracer) tracer;
        assertEquals(1, mt.finishedSpans().size());
        MockSpan span = mt.finishedSpans().get(0);
        assertEquals(span.operationName(), "Motan_test_HelloService.sayHello(java.lang.String)");
        assertEquals(span.parentId(), 0);
        assertEquals(span.logEntries().size(), 1);
        assertTrue("request success.".equals(span.logEntries().get(0).fields().get("event")));
        assertTrue(span.tags().containsKey("requestId"));
    }
}
Also used : MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan)

Example 8 with MockTracer

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

the class ResourceNotTracedTestCase method notTracedEndpointYieldsNoSpans.

@Test
public void notTracedEndpointYieldsNoSpans() throws Exception {
    Assert.assertTrue(tracer instanceof MockTracer);
    MockTracer mockTracer = (MockTracer) tracer;
    performCall("opentracing/not-traced");
    Assert.assertEquals(0, mockTracer.finishedSpans().size());
}
Also used : MockTracer(io.opentracing.mock.MockTracer) Test(org.junit.Test)

Example 9 with MockTracer

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

the class ResourceWithCDITestCase method tracedEndpointYieldsSpan.

@Test
public void tracedEndpointYieldsSpan() throws Exception {
    Assert.assertTrue(tracer instanceof MockTracer);
    MockTracer mockTracer = (MockTracer) tracer;
    performCall("opentracing/with-bean");
    Assert.assertEquals(3, mockTracer.finishedSpans().size());
}
Also used : MockTracer(io.opentracing.mock.MockTracer) Test(org.junit.Test)

Example 10 with MockTracer

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

the class SimpleRestClientTestCase method clientRequestSpanJoinsServer.

@Test
public void clientRequestSpanJoinsServer() {
    // sanity checks
    Assert.assertNotNull(tracer);
    Assert.assertTrue(tracer instanceof MockTracer);
    // the first span
    try (Scope ignored = tracer.activateSpan(tracer.buildSpan("existing-span").start())) {
        // the second span is the client request, as a child of `existing-span`
        Client restClient = ClientTracingRegistrar.configure(ClientBuilder.newBuilder()).build();
        // the third span is the traced endpoint, child of the client request
        String targetUrl = url.toString() + "opentracing/traced";
        System.out.println("We are trying to open " + targetUrl);
        WebTarget target = restClient.target(targetUrl);
        try (Response response = target.request().get()) {
            // just a sanity check
            Assert.assertEquals(200, response.getStatus());
        }
        tracer.activeSpan().finish();
    }
    // verify
    MockTracer mockTracer = (MockTracer) tracer;
    List<MockSpan> spans = mockTracer.finishedSpans();
    Assert.assertEquals(3, spans.size());
    long traceId = spans.get(0).context().traceId();
    for (MockSpan span : spans) {
        // they should all belong to the same trace
        Assert.assertEquals(traceId, span.context().traceId());
    }
}
Also used : Response(javax.ws.rs.core.Response) Scope(io.opentracing.Scope) MockTracer(io.opentracing.mock.MockTracer) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) 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