use of io.opentracing.mock.MockSpan in project motan by weibocom.
the class OpenTracingFilterTest method checkMockTracer.
private void checkMockTracer() {
if (tracer instanceof MockTracer) {
MockTracer mt = (MockTracer) tracer;
assertEquals(1, mt.finishedSpans().size());
MockSpan span = mt.finishedSpans().get(0);
assertEquals(span.operationName(), "Motan_test_HelloService.sayHello(java.lang.String)");
assertEquals(span.parentId(), 0);
assertEquals(span.logEntries().size(), 1);
assertTrue("request success.".equals(span.logEntries().get(0).fields().get("event")));
assertTrue(span.tags().containsKey("requestId"));
}
}
use of io.opentracing.mock.MockSpan in project motan by weibocom.
the class OpenTracingFilterTest method testException.
@Test
public void testException() {
response.setException(new RuntimeException("in test"));
Response res = OTFilter.filter(refer, request);
assertEquals(response, res);
if (tracer instanceof MockTracer) {
MockSpan span = ((MockTracer) tracer).finishedSpans().get(0);
assertEquals(span.logEntries().size(), 1);
assertTrue("request fail.in test".equals(span.logEntries().get(0).fields().get("event")));
}
}
use of io.opentracing.mock.MockSpan 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()));
}
use of io.opentracing.mock.MockSpan 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));
}
use of io.opentracing.mock.MockSpan 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()));
}
Aggregations