Search in sources :

Example 46 with MetricsOptions

use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.

the class VertxOptionsTest method testJsonOptions.

@Test
public void testJsonOptions() {
    VertxOptions options = new VertxOptions(new JsonObject());
    assertEquals(0, options.getEventBusOptions().getPort());
    assertEquals(-1, options.getEventBusOptions().getClusterPublicPort());
    assertEquals(20000, options.getEventBusOptions().getClusterPingInterval());
    assertEquals(20000, options.getEventBusOptions().getClusterPingReplyInterval());
    assertEquals(2 * Runtime.getRuntime().availableProcessors(), options.getEventLoopPoolSize());
    assertEquals(20, options.getInternalBlockingPoolSize());
    assertEquals(20, options.getWorkerPoolSize());
    assertEquals(1000, options.getBlockedThreadCheckInterval());
    assertNull(options.getEventBusOptions().getHost());
    assertNull(options.getEventBusOptions().getClusterPublicHost());
    assertEquals(null, options.getClusterManager());
    assertEquals(2000l * 1000000, options.getMaxEventLoopExecuteTime());
    assertEquals(1l * 60 * 1000 * 1000000, options.getMaxWorkerExecuteTime());
    assertFalse(options.isHAEnabled());
    assertEquals(1, options.getQuorumSize());
    assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup());
    assertNotNull(options.getMetricsOptions());
    assertEquals(5000000000l, options.getWarningExceptionTime());
    assertEquals(TimeUnit.NANOSECONDS, options.getMaxEventLoopExecuteTimeUnit());
    assertEquals(TimeUnit.NANOSECONDS, options.getMaxWorkerExecuteTimeUnit());
    assertEquals(TimeUnit.NANOSECONDS, options.getWarningExceptionTimeUnit());
    assertEquals(TimeUnit.MILLISECONDS, options.getBlockedThreadCheckIntervalUnit());
    int clusterPort = TestUtils.randomPortInt();
    int clusterPublicPort = TestUtils.randomPortInt();
    int eventLoopPoolSize = TestUtils.randomPositiveInt();
    int internalBlockingPoolSize = TestUtils.randomPositiveInt();
    int workerPoolSize = TestUtils.randomPositiveInt();
    int blockedThreadCheckInterval = TestUtils.randomPositiveInt();
    String clusterHost = TestUtils.randomAlphaString(100);
    String clusterPublicHost = TestUtils.randomAlphaString(100);
    long clusterPingInterval = TestUtils.randomPositiveLong();
    long clusterPingReplyInterval = TestUtils.randomPositiveLong();
    int maxEventLoopExecuteTime = TestUtils.randomPositiveInt();
    int maxWorkerExecuteTime = TestUtils.randomPositiveInt();
    int proxyOperationTimeout = TestUtils.randomPositiveInt();
    long warningExceptionTime = TestUtils.randomPositiveLong();
    Random rand = new Random();
    boolean haEnabled = rand.nextBoolean();
    boolean fileResolverCachingEnabled = rand.nextBoolean();
    int quorumSize = TestUtils.randomShort() + 1;
    String haGroup = TestUtils.randomAlphaString(100);
    boolean classPathResolvingEnabled = rand.nextBoolean();
    boolean metricsEnabled = rand.nextBoolean();
    boolean jmxEnabled = rand.nextBoolean();
    String jmxDomain = TestUtils.randomAlphaString(100);
    TimeUnit maxEventLoopExecuteTimeUnit = TimeUnit.SECONDS;
    TimeUnit maxWorkerExecuteTimeUnit = TimeUnit.MILLISECONDS;
    TimeUnit warningExceptionTimeUnit = TimeUnit.MINUTES;
    TimeUnit blockedThreadCheckIntervalUnit = TimeUnit.MINUTES;
    options = new VertxOptions(new JsonObject().put("eventBusOptions", new JsonObject().put("port", clusterPort).put("clusterPublicPort", clusterPublicPort).put("host", clusterHost).put("clusterPublicHost", clusterPublicHost).put("clusterPingInterval", clusterPingInterval).put("clusterPingReplyInterval", clusterPingReplyInterval)).put("eventLoopPoolSize", eventLoopPoolSize).put("internalBlockingPoolSize", internalBlockingPoolSize).put("workerPoolSize", workerPoolSize).put("blockedThreadCheckInterval", blockedThreadCheckInterval).put("maxEventLoopExecuteTime", maxEventLoopExecuteTime).put("maxWorkerExecuteTime", maxWorkerExecuteTime).put("proxyOperationTimeout", proxyOperationTimeout).put("haEnabled", haEnabled).put("fileResolverCachingEnabled", fileResolverCachingEnabled).put("quorumSize", quorumSize).put("haGroup", haGroup).put("warningExceptionTime", warningExceptionTime).put("fileSystemOptions", new JsonObject().put("classPathResolvingEnabled", classPathResolvingEnabled).put("fileCachingEnabled", fileResolverCachingEnabled)).put("metricsOptions", new JsonObject().put("enabled", metricsEnabled).put("jmxEnabled", jmxEnabled).put("jmxDomain", jmxDomain)).put("tracingOptions", new JsonObject()).put("maxEventLoopExecuteTimeUnit", maxEventLoopExecuteTimeUnit).put("maxWorkerExecuteTimeUnit", maxWorkerExecuteTimeUnit).put("warningExceptionTimeUnit", warningExceptionTimeUnit).put("blockedThreadCheckIntervalUnit", blockedThreadCheckIntervalUnit));
    assertEquals(clusterPort, options.getEventBusOptions().getPort());
    assertEquals(clusterPublicPort, options.getEventBusOptions().getClusterPublicPort());
    assertEquals(clusterPublicHost, options.getEventBusOptions().getClusterPublicHost());
    assertEquals(clusterPingInterval, options.getEventBusOptions().getClusterPingInterval());
    assertEquals(clusterPingReplyInterval, options.getEventBusOptions().getClusterPingReplyInterval());
    assertEquals(eventLoopPoolSize, options.getEventLoopPoolSize());
    assertEquals(internalBlockingPoolSize, options.getInternalBlockingPoolSize());
    assertEquals(workerPoolSize, options.getWorkerPoolSize());
    assertEquals(blockedThreadCheckInterval, options.getBlockedThreadCheckInterval());
    assertEquals(clusterHost, options.getEventBusOptions().getHost());
    assertEquals(null, options.getClusterManager());
    assertEquals(maxEventLoopExecuteTime, options.getMaxEventLoopExecuteTime());
    assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
    assertEquals(haEnabled, options.isHAEnabled());
    assertEquals(quorumSize, options.getQuorumSize());
    assertEquals(haGroup, options.getHAGroup());
    FileSystemOptions fileSystemOptions = options.getFileSystemOptions();
    assertEquals(classPathResolvingEnabled, fileSystemOptions.isClassPathResolvingEnabled());
    assertEquals(fileResolverCachingEnabled, fileSystemOptions.isFileCachingEnabled());
    MetricsOptions metricsOptions = options.getMetricsOptions();
    assertEquals(metricsEnabled, metricsOptions.isEnabled());
    assertNotNull(options.getTracingOptions());
    assertEquals(warningExceptionTime, options.getWarningExceptionTime());
    assertEquals(maxEventLoopExecuteTimeUnit, options.getMaxEventLoopExecuteTimeUnit());
    assertEquals(maxWorkerExecuteTimeUnit, options.getMaxWorkerExecuteTimeUnit());
    assertEquals(warningExceptionTimeUnit, options.getWarningExceptionTimeUnit());
    assertEquals(blockedThreadCheckIntervalUnit, options.getBlockedThreadCheckIntervalUnit());
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) Random(java.util.Random) JsonObject(io.vertx.core.json.JsonObject) TimeUnit(java.util.concurrent.TimeUnit) FileSystemOptions(io.vertx.core.file.FileSystemOptions) Test(org.junit.Test)

Example 47 with MetricsOptions

use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.

the class MetricsContextTest method testNetServer.

private void testNetServer(Function<Vertx, Context> contextFactory) throws Exception {
    AtomicReference<Thread> expectedThread = new AtomicReference<>();
    AtomicReference<Context> expectedContext = new AtomicReference<>();
    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 TCPMetrics createNetServerMetrics(NetServerOptions options, SocketAddress localAddress) {
            return new DummyTCPMetrics() {

                @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 -> {
        NetServer server = vertx.createNetServer().connectHandler(so -> {
            so.handler(buf -> {
                so.write("bye");
            });
        });
        server.listen(1234, "localhost", onSuccess(s -> {
            expectedThread.set(Thread.currentThread());
            expectedContext.set(Vertx.currentContext());
            assertSame(expectedThread.get(), Thread.currentThread());
            latch.countDown();
        }));
    });
    awaitLatch(latch);
    NetClient client = vertx.createNetClient();
    client.connect(1234, "localhost", onSuccess(so -> {
        so.handler(buf -> {
            so.closeHandler(v -> {
                executeInVanillaThread(() -> {
                    vertx.close(v4 -> {
                        assertTrue(bytesReadCalled.get());
                        assertTrue(bytesWrittenCalled.get());
                        assertTrue(socketConnectedCalled.get());
                        assertTrue(socketDisconnectedCalled.get());
                        assertTrue(closeCalled.get());
                        testComplete();
                    });
                });
            });
            so.close();
        });
        so.write("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) MetricsOptions(io.vertx.core.metrics.MetricsOptions) 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 48 with MetricsOptions

use of io.vertx.core.metrics.MetricsOptions 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 49 with MetricsOptions

use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.

the class MetricsContextTest method testDatagram.

private void testDatagram(Function<Vertx, Context> contextFactory) throws Exception {
    AtomicReference<Thread> expectedThread = new AtomicReference<>();
    AtomicReference<Context> expectedContext = new AtomicReference<>();
    AtomicBoolean listening = new AtomicBoolean();
    AtomicBoolean bytesReadCalled = new AtomicBoolean();
    AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
    CountDownLatch closeCalled = new CountDownLatch(1);
    VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {

        @Override
        public DatagramSocketMetrics createDatagramSocketMetrics(DatagramSocketOptions options) {
            return new DummyDatagramMetrics() {

                @Override
                public void listening(String localName, SocketAddress localAddress) {
                    listening.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.countDown();
                }
            };
        }
    };
    Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    Context ctx = contextFactory.apply(vertx);
    ctx.runOnContext(v1 -> {
        expectedThread.set(Thread.currentThread());
        expectedContext.set(Vertx.currentContext());
        DatagramSocket socket = vertx.createDatagramSocket();
        socket.listen(1234, "localhost", onSuccess(v2 -> {
            socket.handler(packet -> {
                assertTrue(listening.get());
                assertTrue(bytesReadCalled.get());
                assertTrue(bytesWrittenCalled.get());
                executeInVanillaThread(socket::close);
            });
            socket.send(Buffer.buffer("msg"), 1234, "localhost", onSuccess(v3 -> {
            }));
        }));
    });
    awaitLatch(closeCalled);
}
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) AtomicReference(java.util.concurrent.atomic.AtomicReference) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DatagramSocket(io.vertx.core.datagram.DatagramSocket)

Example 50 with MetricsOptions

use of io.vertx.core.metrics.MetricsOptions 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

MetricsOptions (io.vertx.core.metrics.MetricsOptions)59 Test (org.junit.Test)49 DummyVertxMetrics (io.vertx.core.metrics.impl.DummyVertxMetrics)32 VertxMetricsFactory (io.vertx.core.spi.VertxMetricsFactory)27 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)26 CountDownLatch (java.util.concurrent.CountDownLatch)25 AtomicReference (java.util.concurrent.atomic.AtomicReference)25 io.vertx.core (io.vertx.core)24 Buffer (io.vertx.core.buffer.Buffer)24 DatagramSocket (io.vertx.core.datagram.DatagramSocket)24 DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)24 EventBus (io.vertx.core.eventbus.EventBus)24 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)24 io.vertx.core.http (io.vertx.core.http)24 io.vertx.core.net (io.vertx.core.net)24 BiConsumer (java.util.function.BiConsumer)24 Function (java.util.function.Function)24 VertxOptions (io.vertx.core.VertxOptions)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 EventBusOptions (io.vertx.core.eventbus.EventBusOptions)12