Search in sources :

Example 6 with SpanDecorator

use of org.apache.camel.opentracing.SpanDecorator in project camel by apache.

the class AbstractHttpSpanDecoratorTest method testPreUri.

@Test
public void testPreUri() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Exchange exchange = Mockito.mock(Exchange.class);
    Message message = Mockito.mock(Message.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn(TEST_URI);
    Mockito.when(exchange.getIn()).thenReturn(message);
    Mockito.when(message.getHeader(Exchange.HTTP_URI)).thenReturn(TEST_URI);
    SpanDecorator decorator = new AbstractHttpSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.pre(span, exchange, endpoint);
    assertEquals(TEST_URI, span.tags().get(Tags.HTTP_URL.getKey()));
    assertTrue(span.tags().containsKey(Tags.HTTP_METHOD.getKey()));
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) 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 7 with SpanDecorator

use of org.apache.camel.opentracing.SpanDecorator in project camel by apache.

the class AbstractMessagingSpanDecoratorTest method testOperationName.

@Test
public void testOperationName() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("jms://MyQueue?hello=world");
    SpanDecorator decorator = new AbstractMessagingSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    assertEquals("MyQueue", decorator.getOperationName(null, endpoint));
}
Also used : Endpoint(org.apache.camel.Endpoint) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) Test(org.junit.Test)

Example 8 with SpanDecorator

use of org.apache.camel.opentracing.SpanDecorator in project camel by apache.

the class AbstractMessagingSpanDecoratorTest method testPreMessageBusDestination.

@Test
public void testPreMessageBusDestination() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("jms://MyQueue?hello=world");
    SpanDecorator decorator = new AbstractMessagingSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.pre(span, null, endpoint);
    assertEquals("MyQueue", span.tags().get(Tags.MESSAGE_BUS_DESTINATION.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)

Example 9 with SpanDecorator

use of org.apache.camel.opentracing.SpanDecorator 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 10 with SpanDecorator

use of org.apache.camel.opentracing.SpanDecorator 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

SpanDecorator (org.apache.camel.opentracing.SpanDecorator)18 Test (org.junit.Test)18 Endpoint (org.apache.camel.Endpoint)15 MockSpan (io.opentracing.mock.MockSpan)13 MockTracer (io.opentracing.mock.MockTracer)13 Exchange (org.apache.camel.Exchange)11 Message (org.apache.camel.Message)8