use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testAsync.
@Test
public void testAsync() throws Exception {
{
getRestTemplate().getForEntity("/async", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("async", span.operationName());
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterConcurrentHandlingStarted", "preHandle", "afterCompletion"));
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testAsyncDeferred.
@Test
public void testAsyncDeferred() throws Exception {
{
getRestTemplate().getForEntity("/asyncDeferred", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("test", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/asyncDeferred"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(202, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterConcurrentHandlingStarted", "preHandle", "afterCompletion"));
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testNoURLMapping.
@Test
public void testNoURLMapping() {
{
getRestTemplate().getForEntity("/nouUrlMapping", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("GET", span.operationName());
Assert.assertEquals(404, span.tags().get(Tags.HTTP_STATUS.getKey()));
assertLogEvents(span.logEntries(), Collections.<String>emptyList());
span = mockSpans.get(1);
Assert.assertEquals(0, span.tags().size());
Assert.assertEquals(mockSpans.get(0).context().spanId(), span.parentId());
Assert.assertEquals(0, span.tags().size());
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
Assert.assertEquals("BasicErrorController", span.logEntries().get(0).fields().get("handler.class_simple_name"));
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class AbstractBaseITests method testLocalSpan.
@Test
public void testLocalSpan() {
{
getRestTemplate().getForEntity("/localSpan", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan childSpan = mockSpans.get(0);
MockSpan parentSpan = mockSpans.get(1);
Assert.assertEquals("localSpan", parentSpan.operationName());
Assert.assertEquals(childSpan.context().traceId(), parentSpan.context().traceId());
Assert.assertEquals(childSpan.parentId(), parentSpan.context().spanId());
}
use of io.opentracing.mock.MockSpan in project java-spring-web by opentracing-contrib.
the class TracingAsyncRestTemplateTest method testMultipleRequests.
@Test
public void testMultipleRequests() throws InterruptedException, ExecutionException {
final String url = "http://localhost:8080/foo/";
int numberOfCalls = 1000;
mockServer.expect(ExpectedCount.manyTimes(), MockRestRequestMatchers.requestTo(new Contains("/foo"))).andRespond(MockRestResponseCreators.withSuccess());
ExecutorService executorService = Executors.newFixedThreadPool(100);
List<Future<?>> futures = new ArrayList<>(numberOfCalls);
for (int i = 0; i < numberOfCalls; i++) {
final String requestUrl = url + i;
final Scope parentSpan = mockTracer.buildSpan("foo").startActive(false);
parentSpan.span().setTag("request-url", requestUrl);
final Span cont = parentSpan.span();
futures.add(executorService.submit(new Runnable() {
@Override
public void run() {
try (Scope span = mockTracer.scopeManager().activate(cont, true)) {
client.getForEntity(requestUrl, String.class);
}
}
}));
parentSpan.close();
}
// wait to finish all calls
for (Future<?> future : futures) {
future.get();
}
executorService.awaitTermination(1, TimeUnit.SECONDS);
executorService.shutdown();
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(numberOfCalls * 2, mockSpans.size());
final List<MockSpan> parentSpans = new ArrayList<>();
final Map<Long, MockSpan> childSpans = new HashMap<>();
for (MockSpan mockSpan : mockSpans) {
if (mockSpan.tags().containsKey("request-url")) {
parentSpans.add(mockSpan);
} else {
childSpans.put(mockSpan.parentId(), mockSpan);
}
}
Assert.assertEquals(numberOfCalls, parentSpans.size());
Assert.assertEquals(numberOfCalls, childSpans.size());
for (MockSpan parentSpan : parentSpans) {
MockSpan childSpan = childSpans.get(parentSpan.context().spanId());
Assert.assertEquals(parentSpan.tags().get("request-url"), childSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(parentSpan.context().traceId(), childSpan.context().traceId());
Assert.assertEquals(parentSpan.context().spanId(), childSpan.parentId());
Assert.assertEquals(0, childSpan.generatedErrors().size());
Assert.assertEquals(0, parentSpan.generatedErrors().size());
}
}
Aggregations