use of io.opentracing.mock.MockSpan 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"));
}
use of io.opentracing.mock.MockSpan 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()));
}
use of io.opentracing.mock.MockSpan 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));
}
use of io.opentracing.mock.MockSpan in project camel by apache.
the class JdbcSpanDecoratorTest method testPre.
@Test
public void testPre() {
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.getBody()).thenReturn(SQL_STATEMENT);
SpanDecorator decorator = new JdbcSpanDecorator();
MockTracer tracer = new MockTracer();
MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
decorator.pre(span, exchange, endpoint);
assertEquals("sql", span.tags().get(Tags.DB_TYPE.getKey()));
assertEquals(SQL_STATEMENT, span.tags().get(Tags.DB_STATEMENT.getKey()));
}
use of io.opentracing.mock.MockSpan in project camel by apache.
the class SqlSpanDecoratorTest method testPre.
@Test
public void testPre() {
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(SqlSpanDecorator.CAMEL_SQL_QUERY)).thenReturn(SQL_STATEMENT);
SpanDecorator decorator = new SqlSpanDecorator();
MockTracer tracer = new MockTracer();
MockSpan span = (MockSpan) tracer.buildSpan("TestSpan").start();
decorator.pre(span, exchange, endpoint);
assertEquals("sql", span.tags().get(Tags.DB_TYPE.getKey()));
assertEquals(SQL_STATEMENT, span.tags().get(Tags.DB_STATEMENT.getKey()));
}
Aggregations