use of io.vertx.test.faketracer.Span in project vert.x by eclipse.
the class EventBusTracingTestBase method testPublish.
private void testPublish(TracingPolicy policy, boolean create, int expected, boolean singleTrace) throws Exception {
vertx2.eventBus().consumer("the-address", msg -> {
});
vertx2.eventBus().consumer("the-address", msg -> {
});
Context ctx = vertx1.getOrCreateContext();
ctx.runOnContext(v -> {
if (create) {
tracer.activate(tracer.newTrace());
}
vertx1.eventBus().publish("the-address", "ping", new DeliveryOptions().setTracingPolicy(policy));
});
assertWaitUntil(() -> tracer.getFinishedSpans().size() == expected);
List<Span> finishedSpans = tracer.getFinishedSpans();
if (singleTrace) {
assertSingleTrace(finishedSpans);
}
finishedSpans.forEach(span -> {
assertEquals("publish", span.operation);
});
}
use of io.vertx.test.faketracer.Span in project vert.x by eclipse.
the class EventBusTracingTestBase method testRequestReply.
private void testRequestReply(TracingPolicy policy, boolean create, boolean fail, int expected) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
vertx2.eventBus().consumer("the-address", msg -> {
if (fail) {
msg.fail(10, "it failed");
} else {
msg.reply("pong");
}
});
Context ctx = vertx1.getOrCreateContext();
ctx.runOnContext(v -> {
if (create) {
tracer.activate(tracer.newTrace());
}
vertx1.eventBus().request("the-address", "ping", new DeliveryOptions().setTracingPolicy(policy), ar -> {
assertEquals(fail, ar.failed());
// make sure span is finished
vertx1.runOnContext(v2 -> latch.countDown());
});
});
awaitLatch(latch);
List<Span> finishedSpans = tracer.getFinishedSpans();
assertEquals(expected, finishedSpans.size());
assertSingleTrace(finishedSpans);
finishedSpans.forEach(span -> {
assertEquals("send", span.operation);
});
}
use of io.vertx.test.faketracer.Span in project vert.x by eclipse.
the class HttpTracingTestBase method testMultipleHttpServerRequest.
@Test
public void testMultipleHttpServerRequest() throws Exception {
server.requestHandler(serverReq -> {
assertNotNull(tracer.activeSpan());
switch(serverReq.path()) {
case "/1":
{
vertx.setTimer(10, id -> {
client.request(HttpMethod.GET, 8080, "localhost", "/2", onSuccess(clientReq -> {
clientReq.send(onSuccess(resp -> {
serverReq.response().end();
}));
}));
});
break;
}
case "/2":
{
serverReq.response().end();
break;
}
default:
{
serverReq.response().setStatusCode(500).end();
}
}
});
startServer();
Context ctx = vertx.getOrCreateContext();
ctx.runOnContext(v -> {
Span rootSpan = tracer.newTrace();
tracer.activate(rootSpan);
client.request(HttpMethod.GET, 8080, "localhost", "/1", onSuccess(req -> {
req.send(onSuccess(resp -> {
assertEquals(rootSpan, tracer.activeSpan());
assertEquals(200, resp.statusCode());
}));
}));
});
waitUntil(() -> tracer.getFinishedSpans().size() == 4);
List<Span> finishedSpans = tracer.getFinishedSpans();
assertEquals(4, finishedSpans.size());
assertSingleTrace(finishedSpans);
Map<Integer, Span> spanMap = finishedSpans.stream().collect(Collectors.toMap(o -> o.id, Function.identity()));
List<Span> lastServerSpans = finishedSpans.stream().filter(mockSpan -> mockSpan.getTags().get("span_kind").equals("server")).filter(mockSpan -> mockSpan.getTags().get("http.url").contains("localhost:8080/2")).collect(Collectors.toList());
assertEquals(1, lastServerSpans.size());
String scheme = createBaseServerOptions().isSsl() ? "https" : "http";
for (Span server2Span : lastServerSpans) {
Span client2Span = spanMap.get(server2Span.parentId);
assertEquals("GET", client2Span.operation);
assertEquals(scheme + "://localhost:8080/2", client2Span.getTags().get("http.url"));
assertEquals("200", client2Span.getTags().get("http.status_code"));
assertEquals("client", client2Span.getTags().get("span_kind"));
Span server1Span = spanMap.get(client2Span.parentId);
assertEquals("GET", server1Span.operation);
assertEquals(scheme + "://localhost:8080/1", server1Span.getTags().get("http.url"));
assertEquals("200", client2Span.getTags().get("http.status_code"));
assertEquals("server", server1Span.getTags().get("span_kind"));
Span client1Span = spanMap.get(server1Span.parentId);
assertEquals("GET", client1Span.operation);
assertEquals(scheme + "://localhost:8080/1", client1Span.getTags().get("http.url"));
assertEquals("200", client2Span.getTags().get("http.status_code"));
assertEquals("client", client1Span.getTags().get("span_kind"));
}
}
use of io.vertx.test.faketracer.Span in project vert.x by eclipse-vertx.
the class HttpTracingTestBase method testHttpServerRequest.
@Test
public void testHttpServerRequest() throws Exception {
server.requestHandler(req -> {
assertNotNull(tracer.activeSpan());
req.response().end();
});
startServer();
Context ctx = vertx.getOrCreateContext();
ctx.runOnContext(v -> {
Span rootSpan = tracer.newTrace();
tracer.activate(rootSpan);
client.request(HttpMethod.GET, 8080, "localhost", "/1", onSuccess(req -> {
req.send(onSuccess(resp -> {
assertEquals(rootSpan, tracer.activeSpan());
assertEquals(200, resp.statusCode());
}));
}));
});
waitUntil(() -> tracer.getFinishedSpans().size() == 2);
assertSingleTrace(tracer.getFinishedSpans());
}
use of io.vertx.test.faketracer.Span in project vert.x by eclipse.
the class EventBusTracingTestBase method testSend.
private void testSend(TracingPolicy policy, boolean create, int expected) throws Exception {
AtomicInteger received = new AtomicInteger();
vertx2.eventBus().consumer("the-address", msg -> {
received.incrementAndGet();
});
Context ctx = vertx1.getOrCreateContext();
ctx.runOnContext(v -> {
if (create) {
tracer.activate(tracer.newTrace());
}
vertx1.eventBus().send("the-address", "ping", new DeliveryOptions().setTracingPolicy(policy));
});
assertWaitUntil(() -> tracer.getFinishedSpans().size() == expected);
assertWaitUntil(() -> received.get() == 1);
List<Span> finishedSpans = tracer.getFinishedSpans();
assertSingleTrace(finishedSpans);
finishedSpans.forEach(span -> {
assertEquals("send", span.operation);
});
}
Aggregations