Search in sources :

Example 1 with Span

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);
    });
}
Also used : Context(io.vertx.core.Context) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) Span(io.vertx.test.faketracer.Span)

Example 2 with Span

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);
    });
}
Also used : Context(io.vertx.core.Context) CountDownLatch(java.util.concurrent.CountDownLatch) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) Span(io.vertx.test.faketracer.Span)

Example 3 with Span

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"));
    }
}
Also used : List(java.util.List) Map(java.util.Map) Test(org.junit.Test) Span(io.vertx.test.faketracer.Span) FakeTracer(io.vertx.test.faketracer.FakeTracer) Context(io.vertx.core.Context) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) io.vertx.core.http(io.vertx.core.http) Context(io.vertx.core.Context) Span(io.vertx.test.faketracer.Span) Test(org.junit.Test)

Example 4 with Span

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());
}
Also used : Context(io.vertx.core.Context) List(java.util.List) Map(java.util.Map) Test(org.junit.Test) Span(io.vertx.test.faketracer.Span) FakeTracer(io.vertx.test.faketracer.FakeTracer) Context(io.vertx.core.Context) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) io.vertx.core.http(io.vertx.core.http) Span(io.vertx.test.faketracer.Span) Test(org.junit.Test)

Example 5 with Span

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);
    });
}
Also used : Context(io.vertx.core.Context) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) Span(io.vertx.test.faketracer.Span)

Aggregations

Context (io.vertx.core.Context)12 Span (io.vertx.test.faketracer.Span)12 DeliveryOptions (io.vertx.core.eventbus.DeliveryOptions)6 io.vertx.core.http (io.vertx.core.http)6 FakeTracer (io.vertx.test.faketracer.FakeTracer)6 List (java.util.List)6 Map (java.util.Map)6 Function (java.util.function.Function)6 Collectors (java.util.stream.Collectors)6 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2