Search in sources :

Example 21 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 = (vertx, options) -> {
        metricsThread.set(Thread.currentThread());
        metricsContext.set(Vertx.currentContext());
        return DummyVertxMetrics.INSTANCE;
    };
    clusteredVertx(new VertxOptions().setClustered(true).setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)), 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) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) 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) 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) Ignore(org.junit.Ignore) BiConsumer(java.util.function.BiConsumer) io.vertx.core.spi.metrics(io.vertx.core.spi.metrics) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) 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 22 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 = (vertx, options) -> {
        metricsThread.set(Thread.currentThread());
        metricsContext.set(Vertx.currentContext());
        return DummyVertxMetrics.INSTANCE;
    };
    vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
    assertSame(Thread.currentThread(), metricsThread.get());
    assertNull(metricsContext.get());
}
Also used : io.vertx.core(io.vertx.core) DatagramSocket(io.vertx.core.datagram.DatagramSocket) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) 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) 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) Ignore(org.junit.Ignore) BiConsumer(java.util.function.BiConsumer) io.vertx.core.spi.metrics(io.vertx.core.spi.metrics) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) 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 23 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 = (vertx, options) -> new DummyVertxMetrics() {

        @Override
        public EventBusMetrics createMetrics(EventBus eventBus) {
            return new DummyEventBusMetrics() {

                @Override
                public boolean isEnabled() {
                    return true;
                }

                @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) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) 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) 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) Ignore(org.junit.Ignore) BiConsumer(java.util.function.BiConsumer) io.vertx.core.spi.metrics(io.vertx.core.spi.metrics) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) 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) EventBus(io.vertx.core.eventbus.EventBus) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) Test(org.junit.Test)

Example 24 with MetricsOptions

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

the class MetricsOptionsTest method testOptions.

@Test
public void testOptions() {
    MetricsOptions options = new MetricsOptions();
    assertFalse(options.isEnabled());
    assertEquals(options, options.setEnabled(true));
    assertTrue(options.isEnabled());
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) Test(org.junit.Test)

Example 25 with MetricsOptions

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

the class MetricsOptionsTest method testSetMetricsInstance.

@Test
public void testSetMetricsInstance() {
    DummyVertxMetrics metrics = DummyVertxMetrics.INSTANCE;
    vertx.close();
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(new SimpleVertxMetricsFactory<>(metrics))));
    assertSame(metrics, ((VertxInternal) vertx).metricsSPI());
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Aggregations

MetricsOptions (io.vertx.core.metrics.MetricsOptions)27 Test (org.junit.Test)22 DummyVertxMetrics (io.vertx.core.metrics.impl.DummyVertxMetrics)16 VertxMetricsFactory (io.vertx.core.spi.VertxMetricsFactory)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 io.vertx.core (io.vertx.core)12 Buffer (io.vertx.core.buffer.Buffer)12 DatagramSocket (io.vertx.core.datagram.DatagramSocket)12 DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)12 EventBus (io.vertx.core.eventbus.EventBus)12 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)12 io.vertx.core.http (io.vertx.core.http)12 io.vertx.core.net (io.vertx.core.net)12 io.vertx.core.spi.metrics (io.vertx.core.spi.metrics)12 BiConsumer (java.util.function.BiConsumer)12 Function (java.util.function.Function)12 Ignore (org.junit.Ignore)12 VertxOptions (io.vertx.core.VertxOptions)7