Search in sources :

Example 1 with SpanDecorator

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

the class TimerSpanDecoratorTest method testGetOperationName.

@Test
public void testGetOperationName() {
    Exchange exchange = Mockito.mock(Exchange.class);
    Mockito.when(exchange.getProperty(Exchange.TIMER_NAME)).thenReturn(TEST_NAME);
    SpanDecorator decorator = new TimerSpanDecorator() {

        @Override
        public String getComponent() {
            return null;
        }
    };
    assertEquals(TEST_NAME, decorator.getOperationName(exchange, null));
}
Also used : Exchange(org.apache.camel.Exchange) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) Test(org.junit.Test)

Example 2 with SpanDecorator

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

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

the class ElasticsearchSpanDecoratorTest method testOperationName.

@Test
public void testOperationName() {
    String opName = "INDEX";
    Endpoint endpoint = Mockito.mock(Endpoint.class);
    Mockito.when(endpoint.getEndpointUri()).thenReturn("elasticsearch://local?operation=" + opName + "&indexName=twitter&indexType=tweet");
    SpanDecorator decorator = new ElasticsearchSpanDecorator();
    assertEquals(opName, decorator.getOperationName(null, endpoint));
}
Also used : Endpoint(org.apache.camel.Endpoint) SpanDecorator(org.apache.camel.opentracing.SpanDecorator) Test(org.junit.Test)

Example 4 with SpanDecorator

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

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

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