Search in sources :

Example 1 with HttpResponse

use of io.vertx.core.spi.observability.HttpResponse in project vert.x by eclipse.

the class MetricsContextTest method testHttpClientWebSocket.

private void testHttpClientWebSocket(Function<Vertx, Context> contextFactory) throws Exception {
    AtomicBoolean webSocketConnected = new AtomicBoolean();
    AtomicBoolean webSocketDisconnected = new AtomicBoolean();
    AtomicBoolean socketConnectedCalled = new AtomicBoolean();
    AtomicBoolean socketDisconnectedCalled = new AtomicBoolean();
    AtomicBoolean bytesReadCalled = new AtomicBoolean();
    AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
    AtomicBoolean closeCalled = new AtomicBoolean();
    VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {

        @Override
        public HttpClientMetrics createHttpClientMetrics(HttpClientOptions options) {
            return new DummyHttpClientMetrics() {

                @Override
                public ClientMetrics<Void, Void, HttpRequest, HttpResponse> createEndpointMetrics(SocketAddress remoteAddress, int maxPoolSize) {
                    return new ClientMetrics<Void, Void, HttpRequest, HttpResponse>() {
                    };
                }

                @Override
                public Void connected(WebSocket webSocket) {
                    webSocketConnected.set(true);
                    return null;
                }

                @Override
                public void disconnected(Void webSocketMetric) {
                    webSocketDisconnected.set(true);
                }

                @Override
                public Void connected(SocketAddress remoteAddress, String remoteName) {
                    socketConnectedCalled.set(true);
                    return null;
                }

                @Override
                public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
                    socketDisconnectedCalled.set(true);
                }

                @Override
                public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesReadCalled.set(true);
                }

                @Override
                public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesWrittenCalled.set(true);
                }

                @Override
                public void close() {
                    closeCalled.set(true);
                }
            };
        }
    };
    Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    HttpServer server = vertx.createHttpServer();
    server.webSocketHandler(ws -> {
        ws.handler(buf -> {
            ws.write(Buffer.buffer("bye"));
        });
    });
    CountDownLatch latch = new CountDownLatch(1);
    server.listen(8080, "localhost", onSuccess(s -> {
        latch.countDown();
    }));
    awaitLatch(latch);
    Context ctx = contextFactory.apply(vertx);
    ctx.runOnContext(v1 -> {
        HttpClient client = vertx.createHttpClient();
        client.webSocket(8080, "localhost", "/", onSuccess(ws -> {
            ws.handler(buf -> {
                ws.closeHandler(v2 -> {
                    executeInVanillaThread(() -> {
                        client.close();
                        vertx.close(v3 -> {
                            assertTrue(webSocketConnected.get());
                            assertTrue(webSocketDisconnected.get());
                            assertTrue(socketConnectedCalled.get());
                            assertTrue(socketDisconnectedCalled.get());
                            assertTrue(bytesReadCalled.get());
                            assertTrue(bytesWrittenCalled.get());
                            assertTrue(closeCalled.get());
                            testComplete();
                        });
                    });
                });
                ws.close();
            });
            ws.write(Buffer.buffer("hello"));
        }));
    });
    await();
}
Also used : io.vertx.core(io.vertx.core) DatagramSocket(io.vertx.core.datagram.DatagramSocket) HttpResponse(io.vertx.core.spi.observability.HttpResponse) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) HttpRequest(io.vertx.core.spi.observability.HttpRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) io.vertx.core.net(io.vertx.core.net) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) io.vertx.core.http(io.vertx.core.http) CountDownLatch(java.util.concurrent.CountDownLatch) EventBus(io.vertx.core.eventbus.EventBus) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) HttpRequest(io.vertx.core.spi.observability.HttpRequest) MetricsOptions(io.vertx.core.metrics.MetricsOptions) HttpResponse(io.vertx.core.spi.observability.HttpResponse) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 2 with HttpResponse

use of io.vertx.core.spi.observability.HttpResponse in project vert.x by eclipse.

the class MetricsContextTest method testHttpServerRequest.

private void testHttpServerRequest(Function<Vertx, Context> contextFactory) throws Exception {
    waitFor(2);
    AtomicReference<Thread> expectedThread = new AtomicReference<>();
    AtomicReference<Context> expectedContext = new AtomicReference<>();
    AtomicBoolean requestBeginCalled = new AtomicBoolean();
    AtomicBoolean responseEndCalled = new AtomicBoolean();
    AtomicBoolean socketConnectedCalled = new AtomicBoolean();
    AtomicBoolean socketDisconnectedCalled = new AtomicBoolean();
    AtomicBoolean bytesReadCalled = new AtomicBoolean();
    AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
    AtomicBoolean closeCalled = new AtomicBoolean();
    VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {

        @Override
        public HttpServerMetrics createHttpServerMetrics(HttpServerOptions options, SocketAddress localAddress) {
            return new DummyHttpServerMetrics() {

                @Override
                public Void requestBegin(Void socketMetric, HttpRequest request) {
                    requestBeginCalled.set(true);
                    return null;
                }

                @Override
                public void responseEnd(Void requestMetric, HttpResponse response, long bytesWritten) {
                    responseEndCalled.set(true);
                }

                @Override
                public Void connected(SocketAddress remoteAddress, String remoteName) {
                    socketConnectedCalled.set(true);
                    return null;
                }

                @Override
                public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
                    socketDisconnectedCalled.set(true);
                }

                @Override
                public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesReadCalled.set(true);
                }

                @Override
                public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesWrittenCalled.set(true);
                }

                @Override
                public void close() {
                    closeCalled.set(true);
                }
            };
        }
    };
    CountDownLatch latch = new CountDownLatch(1);
    Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    Context ctx = contextFactory.apply(vertx);
    ctx.runOnContext(v1 -> {
        HttpServer server = vertx.createHttpServer().requestHandler(req -> {
            HttpServerResponse response = req.response();
            response.setStatusCode(200).setChunked(true).end("bye");
            response.close();
        });
        server.listen(8080, "localhost", onSuccess(s -> {
            expectedThread.set(Thread.currentThread());
            expectedContext.set(Vertx.currentContext());
            latch.countDown();
        }));
    });
    awaitLatch(latch);
    HttpClient client = vertx.createHttpClient();
    client.connectionHandler(conn -> {
        conn.closeHandler(v -> {
            vertx.close(v4 -> {
                assertTrue(requestBeginCalled.get());
                assertTrue(responseEndCalled.get());
                assertTrue(bytesReadCalled.get());
                assertTrue(bytesWrittenCalled.get());
                assertTrue(socketConnectedCalled.get());
                assertTrue(socketDisconnectedCalled.get());
                assertTrue(closeCalled.get());
                complete();
            });
        });
    });
    client.request(HttpMethod.PUT, 8080, "localhost", "/").compose(req -> req.send(Buffer.buffer("hello")).onComplete(onSuccess(resp -> {
        complete();
    })));
    await();
}
Also used : io.vertx.core(io.vertx.core) DatagramSocket(io.vertx.core.datagram.DatagramSocket) HttpResponse(io.vertx.core.spi.observability.HttpResponse) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) HttpRequest(io.vertx.core.spi.observability.HttpRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) io.vertx.core.net(io.vertx.core.net) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) io.vertx.core.http(io.vertx.core.http) CountDownLatch(java.util.concurrent.CountDownLatch) EventBus(io.vertx.core.eventbus.EventBus) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) HttpRequest(io.vertx.core.spi.observability.HttpRequest) MetricsOptions(io.vertx.core.metrics.MetricsOptions) HttpResponse(io.vertx.core.spi.observability.HttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 3 with HttpResponse

use of io.vertx.core.spi.observability.HttpResponse in project vert.x by eclipse.

the class MetricsContextTest method testHttpServerRequestPipelining.

@Test
public void testHttpServerRequestPipelining() throws Exception {
    waitFor(2);
    AtomicInteger count = new AtomicInteger();
    VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {

        @Override
        public HttpServerMetrics createHttpServerMetrics(HttpServerOptions options, SocketAddress localAddress) {
            return new DummyHttpServerMetrics() {

                @Override
                public Void requestBegin(Void socketMetric, HttpRequest request) {
                    switch(request.uri()) {
                        case "/1":
                            assertEquals(0, count.get());
                            break;
                        case "/2":
                            assertEquals(1, count.get());
                            break;
                    }
                    return null;
                }

                @Override
                public void requestEnd(Void requestMetric, HttpRequest request, long bytesRead) {
                    switch(request.uri()) {
                        case "/1":
                            assertEquals(1, count.get());
                            break;
                        case "/2":
                            assertEquals(2, count.get());
                            break;
                    }
                }

                @Override
                public void responseEnd(Void requestMetric, HttpResponse response, long bytesWritten) {
                }

                @Override
                public Void connected(SocketAddress remoteAddress, String remoteName) {
                    return null;
                }

                @Override
                public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
                }

                @Override
                public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                }

                @Override
                public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                }

                @Override
                public void close() {
                }
            };
        }
    };
    CountDownLatch latch = new CountDownLatch(1);
    Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    HttpServer server = vertx.createHttpServer().requestHandler(req -> {
        count.incrementAndGet();
        vertx.setTimer(10, id -> {
            HttpServerResponse response = req.response();
            response.end();
        });
    });
    server.listen(8080, "localhost", onSuccess(s -> {
        latch.countDown();
    }));
    awaitLatch(latch);
    HttpClient client = vertx.createHttpClient(new HttpClientOptions().setPipelining(true).setMaxPoolSize(1));
    vertx.runOnContext(v -> {
        for (int i = 0; i < 2; i++) {
            client.request(HttpMethod.GET, 8080, "localhost", "/" + (i + 1), onSuccess(req -> {
                req.send().compose(HttpClientResponse::body).onComplete(onSuccess(body -> {
                    complete();
                }));
            }));
        }
    });
    await();
}
Also used : io.vertx.core(io.vertx.core) DatagramSocket(io.vertx.core.datagram.DatagramSocket) HttpResponse(io.vertx.core.spi.observability.HttpResponse) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) HttpRequest(io.vertx.core.spi.observability.HttpRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) io.vertx.core.net(io.vertx.core.net) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) io.vertx.core.http(io.vertx.core.http) CountDownLatch(java.util.concurrent.CountDownLatch) EventBus(io.vertx.core.eventbus.EventBus) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) HttpRequest(io.vertx.core.spi.observability.HttpRequest) MetricsOptions(io.vertx.core.metrics.MetricsOptions) HttpResponse(io.vertx.core.spi.observability.HttpResponse) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 4 with HttpResponse

use of io.vertx.core.spi.observability.HttpResponse in project vert.x by eclipse.

the class MetricsContextTest method testHttpServerWebSocket.

private void testHttpServerWebSocket(Function<Vertx, Context> contextFactory) throws Exception {
    AtomicReference<Thread> expectedThread = new AtomicReference<>();
    AtomicReference<Context> expectedContext = new AtomicReference<>();
    AtomicBoolean webSocketConnected = new AtomicBoolean();
    AtomicBoolean webSocketDisconnected = new AtomicBoolean();
    AtomicBoolean socketConnectedCalled = new AtomicBoolean();
    AtomicBoolean socketDisconnectedCalled = new AtomicBoolean();
    AtomicBoolean bytesReadCalled = new AtomicBoolean();
    AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
    AtomicBoolean closeCalled = new AtomicBoolean();
    AtomicInteger httpLifecycle = new AtomicInteger();
    VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {

        @Override
        public HttpServerMetrics createHttpServerMetrics(HttpServerOptions options, SocketAddress localAddress) {
            return new DummyHttpServerMetrics() {

                @Override
                public Void requestBegin(Void socketMetric, HttpRequest request) {
                    assertEquals(0, httpLifecycle.getAndIncrement());
                    return null;
                }

                @Override
                public void requestEnd(Void requestMetric, HttpRequest request, long bytesRead) {
                    assertEquals(1, httpLifecycle.getAndIncrement());
                }

                @Override
                public void responseBegin(Void requestMetric, HttpResponse response) {
                    assertEquals(2, httpLifecycle.getAndIncrement());
                }

                @Override
                public void responseEnd(Void requestMetric, HttpResponse response, long bytesWritten) {
                    assertEquals(3, httpLifecycle.getAndIncrement());
                }

                @Override
                public Void connected(Void socketMetric, Void requestMetric, ServerWebSocket serverWebSocket) {
                    assertEquals(2, httpLifecycle.get());
                    webSocketConnected.set(true);
                    return null;
                }

                @Override
                public void disconnected(Void serverWebSocketMetric) {
                    assertEquals(4, httpLifecycle.get());
                    webSocketDisconnected.set(true);
                }

                @Override
                public Void connected(SocketAddress remoteAddress, String remoteName) {
                    socketConnectedCalled.set(true);
                    return null;
                }

                @Override
                public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
                    socketDisconnectedCalled.set(true);
                }

                @Override
                public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesReadCalled.set(true);
                }

                @Override
                public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesWrittenCalled.set(true);
                }

                @Override
                public void close() {
                    closeCalled.set(true);
                }
            };
        }
    };
    CountDownLatch latch = new CountDownLatch(1);
    Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    Context ctx = contextFactory.apply(vertx);
    ctx.runOnContext(v1 -> {
        HttpServer server = vertx.createHttpServer().webSocketHandler(ws -> {
            ws.handler(buf -> {
                ws.write(Buffer.buffer("bye"));
            });
        });
        server.listen(8080, "localhost", onSuccess(s -> {
            expectedThread.set(Thread.currentThread());
            expectedContext.set(Vertx.currentContext());
            latch.countDown();
        }));
    });
    awaitLatch(latch);
    HttpClient client = vertx.createHttpClient();
    client.webSocket(8080, "localhost", "/", onSuccess(ws -> {
        ws.handler(buf -> {
            ws.closeHandler(v -> {
                vertx.close(v4 -> {
                    assertTrue(webSocketConnected.get());
                    assertTrue(webSocketDisconnected.get());
                    assertTrue(bytesReadCalled.get());
                    assertTrue(bytesWrittenCalled.get());
                    assertTrue(socketConnectedCalled.get());
                    assertTrue(socketDisconnectedCalled.get());
                    assertTrue(closeCalled.get());
                    testComplete();
                });
            });
            ws.close();
        });
        ws.write(Buffer.buffer("hello"));
    }));
    await();
}
Also used : io.vertx.core(io.vertx.core) DatagramSocket(io.vertx.core.datagram.DatagramSocket) HttpResponse(io.vertx.core.spi.observability.HttpResponse) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) HttpRequest(io.vertx.core.spi.observability.HttpRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) io.vertx.core.net(io.vertx.core.net) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) io.vertx.core.http(io.vertx.core.http) CountDownLatch(java.util.concurrent.CountDownLatch) EventBus(io.vertx.core.eventbus.EventBus) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) HttpRequest(io.vertx.core.spi.observability.HttpRequest) MetricsOptions(io.vertx.core.metrics.MetricsOptions) HttpResponse(io.vertx.core.spi.observability.HttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with HttpResponse

use of io.vertx.core.spi.observability.HttpResponse in project vert.x by eclipse.

the class MetricsContextTest method testHttpClientRequest.

private void testHttpClientRequest(Function<Vertx, Context> contextFactory) throws Exception {
    AtomicReference<Thread> expectedThread = new AtomicReference<>();
    AtomicReference<Context> expectedContext = new AtomicReference<>();
    AtomicReference<String> requestBeginCalled = new AtomicReference();
    AtomicBoolean responseEndCalled = new AtomicBoolean();
    AtomicBoolean socketConnectedCalled = new AtomicBoolean();
    AtomicBoolean socketDisconnectedCalled = new AtomicBoolean();
    AtomicBoolean bytesReadCalled = new AtomicBoolean();
    AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
    AtomicBoolean closeCalled = new AtomicBoolean();
    VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {

        @Override
        public HttpClientMetrics createHttpClientMetrics(HttpClientOptions options) {
            return new DummyHttpClientMetrics() {

                @Override
                public ClientMetrics<Void, Void, HttpRequest, HttpResponse> createEndpointMetrics(SocketAddress remoteAddress, int maxPoolSize) {
                    return new ClientMetrics<Void, Void, HttpRequest, HttpResponse>() {

                        @Override
                        public Void requestBegin(String uri, HttpRequest request) {
                            requestBeginCalled.set(uri);
                            return null;
                        }

                        @Override
                        public void responseEnd(Void requestMetric, long bytesRead) {
                            responseEndCalled.set(true);
                        }
                    };
                }

                @Override
                public Void connected(SocketAddress remoteAddress, String remoteName) {
                    socketConnectedCalled.set(true);
                    return null;
                }

                @Override
                public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
                    socketDisconnectedCalled.set(true);
                }

                @Override
                public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesReadCalled.set(true);
                }

                @Override
                public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
                    bytesWrittenCalled.set(true);
                }

                @Override
                public void close() {
                    closeCalled.set(true);
                }
            };
        }
    };
    Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    HttpServer server = vertx.createHttpServer();
    server.requestHandler(req -> {
        req.endHandler(buf -> {
            HttpServerResponse resp = req.response();
            resp.setChunked(true).end(Buffer.buffer("bye"));
            resp.close();
        });
    });
    CountDownLatch latch = new CountDownLatch(1);
    server.listen(8080, "localhost", onSuccess(s -> {
        latch.countDown();
    }));
    awaitLatch(latch);
    Context ctx = contextFactory.apply(vertx);
    ctx.runOnContext(v1 -> {
        expectedThread.set(Thread.currentThread());
        expectedContext.set(Vertx.currentContext());
        HttpClient client = vertx.createHttpClient();
        assertSame(expectedThread.get(), Thread.currentThread());
        client.request(HttpMethod.PUT, 8080, "localhost", "/the-uri").compose(req -> req.send(Buffer.buffer("hello")).onComplete(onSuccess(resp -> {
            executeInVanillaThread(() -> {
                client.close();
                vertx.close(v2 -> {
                    assertEquals("/the-uri", requestBeginCalled.get());
                    assertTrue(responseEndCalled.get());
                    assertTrue(socketConnectedCalled.get());
                    assertTrue(socketDisconnectedCalled.get());
                    assertTrue(bytesReadCalled.get());
                    assertTrue(bytesWrittenCalled.get());
                    assertTrue(closeCalled.get());
                    testComplete();
                });
            });
        })));
    });
    await();
}
Also used : io.vertx.core(io.vertx.core) DatagramSocket(io.vertx.core.datagram.DatagramSocket) HttpResponse(io.vertx.core.spi.observability.HttpResponse) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) HttpRequest(io.vertx.core.spi.observability.HttpRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) io.vertx.core.net(io.vertx.core.net) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) io.vertx.core.http(io.vertx.core.http) CountDownLatch(java.util.concurrent.CountDownLatch) EventBus(io.vertx.core.eventbus.EventBus) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) HttpRequest(io.vertx.core.spi.observability.HttpRequest) HttpResponse(io.vertx.core.spi.observability.HttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

io.vertx.core.http (io.vertx.core.http)6 HttpRequest (io.vertx.core.spi.observability.HttpRequest)6 HttpResponse (io.vertx.core.spi.observability.HttpResponse)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 BiConsumer (java.util.function.BiConsumer)6 Test (org.junit.Test)6 io.vertx.core (io.vertx.core)5 Buffer (io.vertx.core.buffer.Buffer)5 DatagramSocket (io.vertx.core.datagram.DatagramSocket)5 DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)5 EventBus (io.vertx.core.eventbus.EventBus)5 EventBusOptions (io.vertx.core.eventbus.EventBusOptions)5 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)5 MetricsOptions (io.vertx.core.metrics.MetricsOptions)5 DummyVertxMetrics (io.vertx.core.metrics.impl.DummyVertxMetrics)5 io.vertx.core.net (io.vertx.core.net)5 VertxMetricsFactory (io.vertx.core.spi.VertxMetricsFactory)5 VertxTestBase (io.vertx.test.core.VertxTestBase)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5