Search in sources :

Example 1 with MockSpan

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

the class CqlSpanDecoratorTest method testPreCqlFromHeader.

@Test
public void testPreCqlFromHeader() {
    String cql = "select * from users";
    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?consistencyLevel=quorum");
    Mockito.when(exchange.getIn()).thenReturn(message);
    Mockito.when(message.getHeader(CqlSpanDecorator.CAMEL_CQL_QUERY)).thenReturn(cql);
    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()));
    assertNull(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 2 with MockSpan

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

the class KafkaSpanDecoratorTest method testPre.

@Test
public void testPre() {
    String testKey = "TestKey";
    String testOffset = "TestOffset";
    String testPartition = "TestPartition";
    String testPartitionKey = "TestPartitionKey";
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Exchange exchange = Mockito.mock(Exchange.class);
    Message message = Mockito.mock(Message.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("test");
    Mockito.when(exchange.getIn()).thenReturn(message);
    Mockito.when(message.getHeader(KafkaSpanDecorator.KEY)).thenReturn(testKey);
    Mockito.when(message.getHeader(KafkaSpanDecorator.OFFSET)).thenReturn(testOffset);
    Mockito.when(message.getHeader(KafkaSpanDecorator.PARTITION)).thenReturn(testPartition);
    Mockito.when(message.getHeader(KafkaSpanDecorator.PARTITION_KEY)).thenReturn(testPartitionKey);
    SpanDecorator decorator = new KafkaSpanDecorator();
    MockTracer tracer = new MockTracer();
    MockSpan span = tracer.buildSpan("TestSpan").start();
    decorator.pre(span, exchange, endpoint);
    assertEquals(testKey, span.tags().get(KafkaSpanDecorator.KAFKA_KEY_TAG));
    assertEquals(testOffset, span.tags().get(KafkaSpanDecorator.KAFKA_OFFSET_TAG));
    assertEquals(testPartition, span.tags().get(KafkaSpanDecorator.KAFKA_PARTITION_TAG));
    assertEquals(testPartitionKey, span.tags().get(KafkaSpanDecorator.KAFKA_PARTITION_KEY_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)

Example 3 with MockSpan

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

the class MongoDBSpanDecoratorTest method testPre.

@Test
public void testPre() {
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn(MONGODB_STATEMENT);
    SpanDecorator decorator = new MongoDBSpanDecorator();
    MockTracer tracer = new MockTracer();
    MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
    decorator.pre(span, null, endpoint);
    assertEquals("mongodb", span.tags().get(Tags.DB_TYPE.getKey()));
    assertEquals("flights", span.tags().get(Tags.DB_INSTANCE.getKey()));
    assertTrue(span.tags().containsKey(Tags.DB_STATEMENT.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 4 with MockSpan

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

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

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