Search in sources :

Example 21 with MockSpan

use of io.opentracing.mock.MockSpan 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 22 with MockSpan

use of io.opentracing.mock.MockSpan 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)

Example 23 with MockSpan

use of io.opentracing.mock.MockSpan 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 24 with MockSpan

use of io.opentracing.mock.MockSpan 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)

Example 25 with MockSpan

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

the class AbstractMessagingSpanDecoratorTest method testPreMessageId.

@Test
public void testPreMessageId() {
    String messageId = "abcd";
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Exchange exchange = Mockito.mock(Exchange.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("test");
    SpanDecorator decorator = new AbstractMessagingSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }

        @Override
        public String getMessageId(Exchange exchange) {
            return messageId;
        }
    };
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.pre(span, exchange, endpoint);
    assertEquals(messageId, span.tags().get(AwsSqsSpanDecorator.MESSAGE_BUS_ID));
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Aggregations

MockSpan (io.opentracing.mock.MockSpan)51 Test (org.junit.Test)50 MockTracer (io.opentracing.mock.MockTracer)17 Matchers.anyString (org.mockito.Matchers.anyString)14 SpanDecorator (org.apache.camel.opentracing.SpanDecorator)13 Endpoint (org.apache.camel.Endpoint)11 Scope (io.opentracing.Scope)10 Exchange (org.apache.camel.Exchange)10 Message (org.apache.camel.Message)8 Span (io.opentracing.Span)2 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)1 Response (com.weibo.api.motan.rpc.Response)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1