Search in sources :

Example 6 with FakeHttpClientMetrics

use of io.vertx.test.fakemetrics.FakeHttpClientMetrics in project vert.x by eclipse.

the class HttpMetricsTestBase method testClientConnectionClosed.

@Test
public void testClientConnectionClosed() throws Exception {
    server.requestHandler(req -> {
        req.response().setChunked(true).write(Buffer.buffer("some-data"));
    });
    startServer();
    client = vertx.createHttpClient(createBaseClientOptions().setIdleTimeout(2));
    FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
    client.request(requestOptions).onComplete(onSuccess(req -> {
        req.send(onSuccess(resp -> {
            HttpClientMetric metric = metrics.getMetric(resp.request());
            assertNotNull(metric);
            assertFalse(metric.failed.get());
            resp.exceptionHandler(err -> {
                assertNull(metrics.getMetric(resp.request()));
                assertTrue(metric.failed.get());
                testComplete();
            });
        }));
    }));
    await();
}
Also used : Arrays(java.util.Arrays) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) FakeMetricsBase(io.vertx.test.fakemetrics.FakeMetricsBase) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTCPMetrics(io.vertx.test.fakemetrics.FakeTCPMetrics) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) NetClient(io.vertx.core.net.NetClient) SocketAddress(io.vertx.core.net.SocketAddress) Iterator(java.util.Iterator) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) Future(io.vertx.core.Future) SocketMetric(io.vertx.test.fakemetrics.SocketMetric) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AsyncTestBase(io.vertx.test.core.AsyncTestBase) Collections(java.util.Collections) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) Test(org.junit.Test)

Example 7 with FakeHttpClientMetrics

use of io.vertx.test.fakemetrics.FakeHttpClientMetrics in project vert.x by eclipse.

the class HttpMetricsTestBase method testHttpMetricsLifecycle.

@Test
public void testHttpMetricsLifecycle() throws Exception {
    int numBuffers = 10;
    int chunkSize = 1000;
    int contentLength = numBuffers * chunkSize;
    AtomicReference<HttpServerMetric> serverMetric = new AtomicReference<>();
    server.requestHandler(req -> {
        assertEquals(protocol, req.version());
        FakeHttpServerMetrics serverMetrics = FakeMetricsBase.getMetrics(server);
        assertNotNull(serverMetrics);
        HttpServerMetric metric = serverMetrics.getRequestMetric(req);
        serverMetric.set(metric);
        assertSame(((HttpServerRequestInternal) req).metric(), metric);
        assertNotNull(serverMetric.get());
        assertNotNull(serverMetric.get().socket);
        assertNull(serverMetric.get().response.get());
        assertTrue(serverMetric.get().socket.connected.get());
        assertNull(serverMetric.get().route.get());
        req.routed("/route/:param");
        assertEquals("/route/:param", serverMetric.get().route.get());
        req.bodyHandler(buff -> {
            assertEquals(contentLength, buff.length());
            assertTrue(serverMetric.get().requestEnded.get());
            assertEquals(contentLength, serverMetric.get().bytesRead.get());
            HttpServerResponse resp = req.response().setChunked(true);
            AtomicInteger numBuffer = new AtomicInteger(numBuffers);
            vertx.setPeriodic(1, timerID -> {
                Buffer chunk = TestUtils.randomBuffer(chunkSize);
                if (numBuffer.decrementAndGet() == 0) {
                    resp.end(chunk);
                    assertTrue(serverMetric.get().responseEnded.get());
                    assertEquals(contentLength, serverMetric.get().bytesWritten.get());
                    assertNull(serverMetrics.getRequestMetric(req));
                    vertx.cancelTimer(timerID);
                } else {
                    resp.write(chunk);
                    assertSame(serverMetric.get().response.get(), resp);
                }
            });
        });
    });
    startServer();
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<HttpClientMetric> clientMetric = new AtomicReference<>();
    AtomicReference<SocketMetric> clientSocketMetric = new AtomicReference<>();
    FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
    NetClient netClient = ((HttpClientImpl) client).netClient();
    FakeTCPMetrics tcpMetrics = FakeMetricsBase.getMetrics(netClient);
    assertSame(metrics, tcpMetrics);
    Context ctx = vertx.getOrCreateContext();
    ctx.runOnContext(v -> {
        assertEquals(Collections.emptySet(), metrics.endpoints());
        client.request(new RequestOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setURI(TestUtils.randomAlphaString(16))).onComplete(onSuccess(req -> {
            req.response(onSuccess(resp -> {
                clientSocketMetric.set(metrics.firstMetric(SocketAddress.inetSocketAddress(8080, "localhost")));
                assertNotNull(clientSocketMetric.get());
                assertEquals(Collections.singleton("localhost:8080"), metrics.endpoints());
                clientMetric.set(metrics.getMetric(resp.request()));
                assertNotNull(clientMetric.get());
                assertEquals(contentLength, clientMetric.get().bytesWritten.get());
                // assertNotNull(clientMetric.get().socket);
                // assertTrue(clientMetric.get().socket.connected.get());
                assertEquals((Integer) 1, metrics.connectionCount("localhost:8080"));
                assertEquals((Integer) 1, metrics.connectionCount(SocketAddress.inetSocketAddress(8080, "localhost")));
                resp.bodyHandler(buff -> {
                    assertEquals(contentLength, clientMetric.get().bytesRead.get());
                    assertNull(metrics.getMetric(resp.request()));
                    assertEquals(contentLength, buff.length());
                    latch.countDown();
                });
            })).exceptionHandler(this::fail).setChunked(true);
            assertNull(metrics.getMetric(req));
            for (int i = 0; i < numBuffers; i++) {
                req.write(TestUtils.randomBuffer(chunkSize));
            }
            req.end();
        }));
    });
    awaitLatch(latch);
    client.close();
    AsyncTestBase.assertWaitUntil(() -> metrics.endpoints().isEmpty());
    assertEquals(null, metrics.connectionCount("localhost:8080"));
    AsyncTestBase.assertWaitUntil(() -> !serverMetric.get().socket.connected.get());
    AsyncTestBase.assertWaitUntil(() -> contentLength == serverMetric.get().socket.bytesRead.get());
    AsyncTestBase.assertWaitUntil(() -> contentLength == serverMetric.get().socket.bytesWritten.get());
    AsyncTestBase.assertWaitUntil(() -> !clientSocketMetric.get().connected.get());
    assertEquals(contentLength, clientSocketMetric.get().bytesRead.get());
    assertEquals(contentLength, clientSocketMetric.get().bytesWritten.get());
    for (Iterator<Long> it : Arrays.asList(clientSocketMetric.get().bytesReadEvents.iterator(), serverMetric.get().socket.bytesWrittenEvents.iterator())) {
        while (it.hasNext()) {
            long val = it.next();
            if (it.hasNext()) {
                assertEquals(4096, val);
            } else {
                assertTrue(val < 4096);
            }
        }
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) Context(io.vertx.core.Context) Arrays(java.util.Arrays) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) FakeMetricsBase(io.vertx.test.fakemetrics.FakeMetricsBase) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTCPMetrics(io.vertx.test.fakemetrics.FakeTCPMetrics) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) NetClient(io.vertx.core.net.NetClient) SocketAddress(io.vertx.core.net.SocketAddress) Iterator(java.util.Iterator) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) Future(io.vertx.core.Future) SocketMetric(io.vertx.test.fakemetrics.SocketMetric) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AsyncTestBase(io.vertx.test.core.AsyncTestBase) Collections(java.util.Collections) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) FakeTCPMetrics(io.vertx.test.fakemetrics.FakeTCPMetrics) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) NetClient(io.vertx.core.net.NetClient) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) SocketMetric(io.vertx.test.fakemetrics.SocketMetric) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) Test(org.junit.Test)

Example 8 with FakeHttpClientMetrics

use of io.vertx.test.fakemetrics.FakeHttpClientMetrics in project vert.x by eclipse.

the class HttpMetricsTestBase method testHttpClientLifecycle.

@Test
public void testHttpClientLifecycle() throws Exception {
    // The test cannot pass for HTTP/2 upgrade for now
    HttpClientOptions opts = createBaseClientOptions();
    if (opts.getProtocolVersion() == HttpVersion.HTTP_2 && !opts.isSsl() && opts.isHttp2ClearTextUpgrade()) {
        return;
    }
    CountDownLatch requestBeginLatch = new CountDownLatch(1);
    CountDownLatch requestBodyLatch = new CountDownLatch(1);
    CountDownLatch requestEndLatch = new CountDownLatch(1);
    CompletableFuture<Void> beginResponse = new CompletableFuture<>();
    CompletableFuture<Void> endResponse = new CompletableFuture<>();
    server.requestHandler(req -> {
        assertEquals(protocol, req.version());
        requestBeginLatch.countDown();
        req.handler(buff -> {
            requestBodyLatch.countDown();
        });
        req.endHandler(v -> {
            requestEndLatch.countDown();
        });
        Context ctx = vertx.getOrCreateContext();
        beginResponse.thenAccept(v1 -> {
            ctx.runOnContext(v2 -> {
                req.response().setChunked(true).write(TestUtils.randomAlphaString(1024));
            });
        });
        endResponse.thenAccept(v1 -> {
            ctx.runOnContext(v2 -> {
                req.response().end();
            });
        });
    });
    CountDownLatch listenLatch = new CountDownLatch(1);
    server.listen(8080, "localhost", onSuccess(s -> {
        listenLatch.countDown();
    }));
    awaitLatch(listenLatch);
    FakeHttpClientMetrics clientMetrics = FakeMetricsBase.getMetrics(client);
    CountDownLatch responseBeginLatch = new CountDownLatch(1);
    CountDownLatch responseEndLatch = new CountDownLatch(1);
    Future<HttpClientRequest> request = client.request(new RequestOptions().setMethod(HttpMethod.POST).setPort(8080).setHost("localhost").setURI("/somepath")).onComplete(onSuccess(req -> {
        req.response(onSuccess(resp -> {
            responseBeginLatch.countDown();
            resp.endHandler(v -> {
                responseEndLatch.countDown();
            });
        })).setChunked(true);
        req.sendHead();
    }));
    awaitLatch(requestBeginLatch);
    HttpClientMetric reqMetric = clientMetrics.getMetric(request.result());
    waitUntil(() -> reqMetric.requestEnded.get() == 0);
    waitUntil(() -> reqMetric.responseBegin.get() == 0);
    request.result().write(TestUtils.randomAlphaString(1024));
    awaitLatch(requestBodyLatch);
    assertEquals(0, reqMetric.requestEnded.get());
    assertEquals(0, reqMetric.responseBegin.get());
    request.result().end();
    awaitLatch(requestEndLatch);
    waitUntil(() -> reqMetric.requestEnded.get() == 1);
    assertEquals(0, reqMetric.responseBegin.get());
    beginResponse.complete(null);
    awaitLatch(responseBeginLatch);
    assertEquals(1, reqMetric.requestEnded.get());
    waitUntil(() -> reqMetric.responseBegin.get() == 1);
    endResponse.complete(null);
    awaitLatch(responseEndLatch);
    waitUntil(() -> clientMetrics.getMetric(request.result()) == null);
    assertEquals(1, reqMetric.requestEnded.get());
    assertEquals(1, reqMetric.responseBegin.get());
}
Also used : Context(io.vertx.core.Context) Arrays(java.util.Arrays) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) FakeMetricsBase(io.vertx.test.fakemetrics.FakeMetricsBase) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTCPMetrics(io.vertx.test.fakemetrics.FakeTCPMetrics) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) NetClient(io.vertx.core.net.NetClient) SocketAddress(io.vertx.core.net.SocketAddress) Iterator(java.util.Iterator) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) Future(io.vertx.core.Future) SocketMetric(io.vertx.test.fakemetrics.SocketMetric) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AsyncTestBase(io.vertx.test.core.AsyncTestBase) Collections(java.util.Collections) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) CompletableFuture(java.util.concurrent.CompletableFuture) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) Test(org.junit.Test)

Example 9 with FakeHttpClientMetrics

use of io.vertx.test.fakemetrics.FakeHttpClientMetrics in project vert.x by eclipse-vertx.

the class HttpMetricsTestBase method testHttpMetricsLifecycle.

@Test
public void testHttpMetricsLifecycle() throws Exception {
    int numBuffers = 10;
    int chunkSize = 1000;
    int contentLength = numBuffers * chunkSize;
    AtomicReference<HttpServerMetric> serverMetric = new AtomicReference<>();
    server.requestHandler(req -> {
        assertEquals(protocol, req.version());
        FakeHttpServerMetrics serverMetrics = FakeMetricsBase.getMetrics(server);
        assertNotNull(serverMetrics);
        HttpServerMetric metric = serverMetrics.getRequestMetric(req);
        serverMetric.set(metric);
        assertSame(((HttpServerRequestInternal) req).metric(), metric);
        assertNotNull(serverMetric.get());
        assertNotNull(serverMetric.get().socket);
        assertNull(serverMetric.get().response.get());
        assertTrue(serverMetric.get().socket.connected.get());
        assertNull(serverMetric.get().route.get());
        req.routed("/route/:param");
        assertEquals("/route/:param", serverMetric.get().route.get());
        req.bodyHandler(buff -> {
            assertEquals(contentLength, buff.length());
            assertTrue(serverMetric.get().requestEnded.get());
            assertEquals(contentLength, serverMetric.get().bytesRead.get());
            HttpServerResponse resp = req.response().setChunked(true);
            AtomicInteger numBuffer = new AtomicInteger(numBuffers);
            vertx.setPeriodic(1, timerID -> {
                Buffer chunk = TestUtils.randomBuffer(chunkSize);
                if (numBuffer.decrementAndGet() == 0) {
                    resp.end(chunk);
                    assertTrue(serverMetric.get().responseEnded.get());
                    assertEquals(contentLength, serverMetric.get().bytesWritten.get());
                    assertNull(serverMetrics.getRequestMetric(req));
                    vertx.cancelTimer(timerID);
                } else {
                    resp.write(chunk);
                    assertSame(serverMetric.get().response.get(), resp);
                }
            });
        });
    });
    startServer();
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<HttpClientMetric> clientMetric = new AtomicReference<>();
    AtomicReference<SocketMetric> clientSocketMetric = new AtomicReference<>();
    FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
    NetClient netClient = ((HttpClientImpl) client).netClient();
    FakeTCPMetrics tcpMetrics = FakeMetricsBase.getMetrics(netClient);
    assertSame(metrics, tcpMetrics);
    Context ctx = vertx.getOrCreateContext();
    ctx.runOnContext(v -> {
        assertEquals(Collections.emptySet(), metrics.endpoints());
        client.request(new RequestOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setURI(TestUtils.randomAlphaString(16))).onComplete(onSuccess(req -> {
            req.response(onSuccess(resp -> {
                clientSocketMetric.set(metrics.firstMetric(SocketAddress.inetSocketAddress(8080, "localhost")));
                assertNotNull(clientSocketMetric.get());
                assertEquals(Collections.singleton("localhost:8080"), metrics.endpoints());
                clientMetric.set(metrics.getMetric(resp.request()));
                assertNotNull(clientMetric.get());
                assertEquals(contentLength, clientMetric.get().bytesWritten.get());
                // assertNotNull(clientMetric.get().socket);
                // assertTrue(clientMetric.get().socket.connected.get());
                assertEquals((Integer) 1, metrics.connectionCount("localhost:8080"));
                assertEquals((Integer) 1, metrics.connectionCount(SocketAddress.inetSocketAddress(8080, "localhost")));
                resp.bodyHandler(buff -> {
                    assertEquals(contentLength, clientMetric.get().bytesRead.get());
                    assertNull(metrics.getMetric(resp.request()));
                    assertEquals(contentLength, buff.length());
                    latch.countDown();
                });
            })).exceptionHandler(this::fail).setChunked(true);
            assertNull(metrics.getMetric(req));
            for (int i = 0; i < numBuffers; i++) {
                req.write(TestUtils.randomBuffer(chunkSize));
            }
            req.end();
        }));
    });
    awaitLatch(latch);
    client.close();
    AsyncTestBase.assertWaitUntil(() -> metrics.endpoints().isEmpty());
    assertEquals(null, metrics.connectionCount("localhost:8080"));
    AsyncTestBase.assertWaitUntil(() -> !serverMetric.get().socket.connected.get());
    AsyncTestBase.assertWaitUntil(() -> contentLength == serverMetric.get().socket.bytesRead.get());
    AsyncTestBase.assertWaitUntil(() -> contentLength == serverMetric.get().socket.bytesWritten.get());
    AsyncTestBase.assertWaitUntil(() -> !clientSocketMetric.get().connected.get());
    assertEquals(contentLength, clientSocketMetric.get().bytesRead.get());
    assertEquals(contentLength, clientSocketMetric.get().bytesWritten.get());
    for (Iterator<Long> it : Arrays.asList(clientSocketMetric.get().bytesReadEvents.iterator(), serverMetric.get().socket.bytesWrittenEvents.iterator())) {
        while (it.hasNext()) {
            long val = it.next();
            if (it.hasNext()) {
                assertEquals(4096, val);
            } else {
                assertTrue(val < 4096);
            }
        }
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) Context(io.vertx.core.Context) Arrays(java.util.Arrays) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) FakeMetricsBase(io.vertx.test.fakemetrics.FakeMetricsBase) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTCPMetrics(io.vertx.test.fakemetrics.FakeTCPMetrics) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) NetClient(io.vertx.core.net.NetClient) SocketAddress(io.vertx.core.net.SocketAddress) Iterator(java.util.Iterator) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) Future(io.vertx.core.Future) SocketMetric(io.vertx.test.fakemetrics.SocketMetric) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AsyncTestBase(io.vertx.test.core.AsyncTestBase) Collections(java.util.Collections) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) FakeTCPMetrics(io.vertx.test.fakemetrics.FakeTCPMetrics) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) NetClient(io.vertx.core.net.NetClient) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) SocketMetric(io.vertx.test.fakemetrics.SocketMetric) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) Test(org.junit.Test)

Example 10 with FakeHttpClientMetrics

use of io.vertx.test.fakemetrics.FakeHttpClientMetrics in project vert.x by eclipse-vertx.

the class HttpMetricsTestBase method testClientConnectionClosed.

@Test
public void testClientConnectionClosed() throws Exception {
    server.requestHandler(req -> {
        req.response().setChunked(true).write(Buffer.buffer("some-data"));
    });
    startServer();
    client = vertx.createHttpClient(createBaseClientOptions().setIdleTimeout(2));
    FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
    client.request(requestOptions).onComplete(onSuccess(req -> {
        req.send(onSuccess(resp -> {
            HttpClientMetric metric = metrics.getMetric(resp.request());
            assertNotNull(metric);
            assertFalse(metric.failed.get());
            resp.exceptionHandler(err -> {
                assertNull(metrics.getMetric(resp.request()));
                assertTrue(metric.failed.get());
                testComplete();
            });
        }));
    }));
    await();
}
Also used : Arrays(java.util.Arrays) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) FakeMetricsBase(io.vertx.test.fakemetrics.FakeMetricsBase) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTCPMetrics(io.vertx.test.fakemetrics.FakeTCPMetrics) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) NetClient(io.vertx.core.net.NetClient) SocketAddress(io.vertx.core.net.SocketAddress) Iterator(java.util.Iterator) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) Future(io.vertx.core.Future) SocketMetric(io.vertx.test.fakemetrics.SocketMetric) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) AsyncTestBase(io.vertx.test.core.AsyncTestBase) Collections(java.util.Collections) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) Test(org.junit.Test)

Aggregations

FakeHttpClientMetrics (io.vertx.test.fakemetrics.FakeHttpClientMetrics)12 HttpClientMetric (io.vertx.test.fakemetrics.HttpClientMetric)12 FakeHttpServerMetrics (io.vertx.test.fakemetrics.FakeHttpServerMetrics)11 HttpServerMetric (io.vertx.test.fakemetrics.HttpServerMetric)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Context (io.vertx.core.Context)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Test (org.junit.Test)10 VertxOptions (io.vertx.core.VertxOptions)9 Buffer (io.vertx.core.buffer.Buffer)9 MetricsOptions (io.vertx.core.metrics.MetricsOptions)9 FakeMetricsBase (io.vertx.test.fakemetrics.FakeMetricsBase)9 FakeMetricsFactory (io.vertx.test.fakemetrics.FakeMetricsFactory)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Future (io.vertx.core.Future)8 HttpClientImpl (io.vertx.core.http.impl.HttpClientImpl)8 HttpServerRequestInternal (io.vertx.core.http.impl.HttpServerRequestInternal)8 NetClient (io.vertx.core.net.NetClient)8 SocketAddress (io.vertx.core.net.SocketAddress)8