Search in sources :

Example 51 with MetricsOptions

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

the class MetricsContextTest method testFactoryInCluster.

@Test
public void testFactoryInCluster() throws Exception {
    AtomicReference<Thread> metricsThread = new AtomicReference<>();
    AtomicReference<Context> metricsContext = new AtomicReference<>();
    Thread testThread = Thread.currentThread();
    VertxMetricsFactory factory = (options) -> {
        metricsThread.set(Thread.currentThread());
        metricsContext.set(Vertx.currentContext());
        return DummyVertxMetrics.INSTANCE;
    };
    VertxOptions options = new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)).setEventBusOptions(new EventBusOptions());
    clusteredVertx(options, onSuccess(vertx -> {
        assertSame(testThread, metricsThread.get());
        assertNull(metricsContext.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) AtomicReference(java.util.concurrent.atomic.AtomicReference) EventBusOptions(io.vertx.core.eventbus.EventBusOptions) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) Test(org.junit.Test)

Example 52 with MetricsOptions

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

the class MetricsContextTest method testFactory.

@Test
public void testFactory() throws Exception {
    AtomicReference<Thread> metricsThread = new AtomicReference<>();
    AtomicReference<Context> metricsContext = new AtomicReference<>();
    VertxMetricsFactory factory = (options) -> {
        metricsThread.set(Thread.currentThread());
        metricsContext.set(Vertx.currentContext());
        return DummyVertxMetrics.INSTANCE;
    };
    vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    assertNull(metricsContext.get());
}
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) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) Test(org.junit.Test)

Example 53 with MetricsOptions

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

the class MetricsContextTest method testEventBusLifecycle.

@Test
public void testEventBusLifecycle() {
    AtomicBoolean closeCalled = new AtomicBoolean();
    VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {

        @Override
        public EventBusMetrics createEventBusMetrics() {
            return new DummyEventBusMetrics() {

                @Override
                public void close() {
                    closeCalled.set(true);
                }
            };
        }
    };
    Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    vertx.eventBus();
    executeInVanillaThread(() -> {
        vertx.close(onSuccess(v -> {
            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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MetricsOptions(io.vertx.core.metrics.MetricsOptions) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) Test(org.junit.Test)

Example 54 with MetricsOptions

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

the class MetricsContextTest method testNetClient.

private void testNetClient(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 createNetClientMetrics(NetClientOptions options) {
            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);
    NetServer server = vertx.createNetServer().connectHandler(so -> {
        so.handler(buf -> {
            so.write("bye");
        });
    });
    server.listen(1234, "localhost", onSuccess(s -> {
        latch.countDown();
    }));
    awaitLatch(latch);
    ctx.runOnContext(v1 -> {
        NetClient client = vertx.createNetClient();
        expectedThread.set(Thread.currentThread());
        expectedContext.set(Vertx.currentContext());
        client.connect(1234, "localhost", onSuccess(so -> {
            so.handler(buf -> {
                so.closeHandler(v -> {
                    assertTrue(bytesReadCalled.get());
                    assertTrue(bytesWrittenCalled.get());
                    assertTrue(socketConnectedCalled.get());
                    assertTrue(socketDisconnectedCalled.get());
                    executeInVanillaThread(() -> {
                        client.close();
                        vertx.close(v4 -> {
                            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 55 with MetricsOptions

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

the class VertxFactoryTest method testFactoryMetricsOverridesMetaInf.

@Test
public void testFactoryMetricsOverridesMetaInf() {
    runWithServiceFromMetaInf(VertxMetricsFactory.class, FakeVertxMetrics.class.getName(), () -> {
        FakeVertxMetrics metrics = new FakeVertxMetrics();
        MetricsOptions metricsOptions = new MetricsOptions().setEnabled(true);
        VertxBuilder factory = new VertxBuilder(new VertxOptions().setMetricsOptions(metricsOptions));
        factory.metrics(metrics);
        factory.init();
        Vertx vertx = factory.vertx();
        assertSame(metrics, ((VertxInternal) vertx).metricsSPI());
    });
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) FakeVertxMetrics(io.vertx.test.fakemetrics.FakeVertxMetrics) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

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