Search in sources :

Example 11 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)

Example 12 with FakeHttpClientMetrics

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

the class HttpMetricsTestBase method testResetImmediately.

@Test
public void testResetImmediately() {
    FakeHttpClientMetrics metrics = FakeMetricsBase.getMetrics(client);
    server.requestHandler(req -> {
    }).listen(testAddress, onSuccess(v -> {
        client.request(HttpMethod.GET, 8080, "localhost", "/somepath", onSuccess(request -> {
            assertNull(metrics.getMetric(request));
            request.reset(0);
            vertx.setTimer(10, id -> {
                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) 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