Search in sources :

Example 16 with MockTracer

use of io.opentracing.mock.MockTracer 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 17 with MockTracer

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

Example 18 with MockTracer

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

the class AbstractSpanDecoratorTest method testPostExchangeFailed.

@Test
public void testPostExchangeFailed() {
    Exchange exchange = Mockito.mock(Exchange.class);
    Mockito.when(exchange.isFailed()).thenReturn(true);
    Exception e = new Exception("Test Message");
    Mockito.when(exchange.getException()).thenReturn(e);
    SpanDecorator decorator = new AbstractSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.post(span, exchange, null);
    assertEquals(true, span.tags().get(Tags.ERROR.getKey()));
    assertEquals(1, span.logEntries().size());
    assertEquals("error", span.logEntries().get(0).fields().get("event"));
    assertEquals("Exception", span.logEntries().get(0).fields().get("error.kind"));
    assertEquals(e.getMessage(), span.logEntries().get(0).fields().get("message"));
}
Also used : Exchange(org.apache.camel.Exchange) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) MockTracer(io.opentracing.mock.MockTracer) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 19 with MockTracer

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

the class CqlSpanDecoratorTest method testPreCqlFromUri.

@Test
public void testPreCqlFromUri() {
    String cql = "select%20*%20from%20users";
    String keyspace = "test";
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Exchange exchange = Mockito.mock(Exchange.class);
    Message message = Mockito.mock(Message.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("cql://host1,host2:8080/" + keyspace + "?cql=" + cql + "&consistencyLevel=quorum");
    Mockito.when(exchange.getIn()).thenReturn(message);
    SpanDecorator decorator = new CqlSpanDecorator();
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.pre(span, exchange, endpoint);
    assertEquals(CqlSpanDecorator.CASSANDRA_DB_TYPE, span.tags().get(Tags.DB_TYPE.getKey()));
    assertEquals(cql, span.tags().get(Tags.DB_STATEMENT.getKey()));
    assertEquals(keyspace, span.tags().get(Tags.DB_INSTANCE.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 20 with MockTracer

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

the class ElasticsearchSpanDecoratorTest method testPre.

@Test
public void testPre() {
    String indexName = "twitter";
    String cluster = "local";
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Exchange exchange = Mockito.mock(Exchange.class);
    Message message = Mockito.mock(Message.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("elasticsearch://" + cluster + "?operation=INDEX&indexName=" + indexName + "&indexType=tweet");
    Mockito.when(exchange.getIn()).thenReturn(message);
    SpanDecorator decorator = new ElasticsearchSpanDecorator();
    MockTracer tracer = new MockTracer();
    MockSpan span = tracer.buildSpan("TestSpan").start();
    decorator.pre(span, exchange, endpoint);
    assertEquals(ElasticsearchSpanDecorator.ELASTICSEARCH_DB_TYPE, span.tags().get(Tags.DB_TYPE.getKey()));
    assertEquals(indexName, span.tags().get(Tags.DB_INSTANCE.getKey()));
    assertEquals(cluster, span.tags().get(ElasticsearchSpanDecorator.ELASTICSEARCH_CLUSTER_TAG));
}
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)

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