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 wildfly by wildfly.
the class SimpleRestClientTestCase method clientRequestSpanJoinsServer.
@Test
public void clientRequestSpanJoinsServer() {
// sanity checks
Assert.assertNotNull(tracer);
Assert.assertTrue(tracer instanceof MockTracer);
// the first span
try (Scope ignored = tracer.activateSpan(tracer.buildSpan("existing-span").start())) {
// the second span is the client request, as a child of `existing-span`
Client restClient = ClientTracingRegistrar.configure(ClientBuilder.newBuilder()).build();
// the third span is the traced endpoint, child of the client request
String targetUrl = url.toString() + "opentracing/traced";
System.out.println("We are trying to open " + targetUrl);
WebTarget target = restClient.target(targetUrl);
try (Response response = target.request().get()) {
// just a sanity check
Assert.assertEquals(200, response.getStatus());
}
tracer.activeSpan().finish();
}
// verify
MockTracer mockTracer = (MockTracer) tracer;
List<MockSpan> spans = mockTracer.finishedSpans();
Assert.assertEquals(3, spans.size());
long traceId = spans.get(0).context().traceId();
for (MockSpan span : spans) {
// they should all belong to the same trace
Assert.assertEquals(traceId, span.context().traceId());
}
}
use of io.opentracing.mock.MockSpan in project wildfly by wildfly.
the class ResourceWithCustomOperationNameNoTopicSetupOverrideForAllMessagesTestCase method customOperationName.
@Test
public void customOperationName() throws Exception {
Assert.assertTrue(tracer instanceof MockTracer);
MockTracer mockTracer = (MockTracer) tracer;
performCall("opentracing/with-custom-operation-name");
List<MockSpan> spans = mockTracer.finishedSpans();
IntStream.range(0, spans.size()).forEach(idx -> System.out.println("*** " + idx + ": " + spans.get(idx).toString()));
Assert.assertEquals(3, spans.size());
Assert.assertEquals("my-custom-method-operation-name", spans.get(0).operationName());
Assert.assertEquals("my-custom-class-operation-name", spans.get(1).operationName());
String opName = spans.get(2).operationName();
Assert.assertTrue(opName, opName.contains(WithCustomOperationNameEndpoint.class.getName()));
}
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));
}
Aggregations