Search in sources :

Example 6 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 7 with MockSpan

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

the class OpenTracingFilterTest method testException.

@Test
public void testException() {
    response.setException(new RuntimeException("in test"));
    Response res = OTFilter.filter(refer, request);
    assertEquals(response, res);
    if (tracer instanceof MockTracer) {
        MockSpan span = ((MockTracer) tracer).finishedSpans().get(0);
        assertEquals(span.logEntries().size(), 1);
        assertTrue("request fail.in test".equals(span.logEntries().get(0).fields().get("event")));
    }
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Response(com.weibo.api.motan.rpc.Response) MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 8 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 9 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)

Example 10 with MockSpan

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

the class AbstractSpanDecoratorTest method testPre.

@Test
public void testPre() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn(TEST_URI);
    SpanDecorator decorator = new AbstractSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.pre(span, null, endpoint);
    assertEquals("camel-test", span.tags().get(Tags.COMPONENT.getKey()));
}
Also used : 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)15 MockTracer (io.opentracing.mock.MockTracer)15 Test (org.junit.Test)14 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)1 Response (com.weibo.api.motan.rpc.Response)1