Search in sources :

Example 41 with MetricsOptions

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

the class MetricsOptionsTest method testSetMetricsInstanceTakesPrecedenceOverServiceLoader.

@Test
public void testSetMetricsInstanceTakesPrecedenceOverServiceLoader() {
    DummyVertxMetrics metrics = DummyVertxMetrics.INSTANCE;
    vertx.close();
    VertxOptions options = new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(new SimpleVertxMetricsFactory<>(metrics)));
    vertx = createVertxLoadingMetricsFromMetaInf(options, "io.vertx.test.fakemetrics.FakeMetricsFactory");
    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)

Example 42 with MetricsOptions

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

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 43 with MetricsOptions

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

the class MetricsTest method testThreadPoolMetricsWithNamedExecuteBlocking.

@Test
public void testThreadPoolMetricsWithNamedExecuteBlocking() throws InterruptedException {
    // Close the instance automatically created
    vertx.close();
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(new FakeMetricsFactory())));
    WorkerExecutor workerExec = vertx.createSharedWorkerExecutor("my-pool", 10);
    Map<String, PoolMetrics> all = FakePoolMetrics.getPoolMetrics();
    FakePoolMetrics metrics = (FakePoolMetrics) all.get("my-pool");
    assertThat(metrics.getPoolSize(), is(10));
    assertThat(metrics.numberOfIdleThreads(), is(10));
    Handler<Promise<Void>> job = getSomeDumbTask();
    AtomicBoolean hadWaitingQueue = new AtomicBoolean();
    AtomicBoolean hadIdle = new AtomicBoolean();
    AtomicBoolean hadRunning = new AtomicBoolean();
    for (int i = 0; i < 100; i++) {
        workerExec.executeBlocking(job, false, ar -> {
            if (metrics.numberOfWaitingTasks() > 0) {
                hadWaitingQueue.set(true);
            }
            if (metrics.numberOfIdleThreads() > 0) {
                hadIdle.set(true);
            }
            if (metrics.numberOfRunningTasks() > 0) {
                hadRunning.set(true);
            }
        });
    }
    waitUntil(() -> metrics.numberOfSubmittedTask() == 100 && metrics.numberOfCompletedTasks() == 100);
    assertTrue(hadIdle.get());
    assertTrue(hadWaitingQueue.get());
    assertTrue(hadRunning.get());
    assertEquals(metrics.numberOfIdleThreads(), 10);
    assertEquals(metrics.numberOfRunningTasks(), 0);
    assertEquals(metrics.numberOfWaitingTasks(), 0);
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 44 with MetricsOptions

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

the class VertxOptionsTest method testCopyOptions.

@Test
public void testCopyOptions() {
    VertxOptions options = new VertxOptions();
    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();
    Random rand = new Random();
    boolean haEnabled = rand.nextBoolean();
    boolean fileResolverCachingEnabled = rand.nextBoolean();
    boolean metricsEnabled = rand.nextBoolean();
    int quorumSize = 51214;
    String haGroup = TestUtils.randomAlphaString(100);
    long warningExceptionTime = TestUtils.randomPositiveLong();
    TimeUnit maxEventLoopExecuteTimeUnit = TimeUnit.SECONDS;
    TimeUnit maxWorkerExecuteTimeUnit = TimeUnit.MILLISECONDS;
    TimeUnit warningExceptionTimeUnit = TimeUnit.MINUTES;
    TimeUnit blockedThreadCheckIntervalUnit = TimeUnit.MINUTES;
    options.getEventBusOptions().setPort(clusterPort);
    options.getEventBusOptions().setClusterPublicPort(clusterPublicPort);
    options.setEventLoopPoolSize(eventLoopPoolSize);
    options.setInternalBlockingPoolSize(internalBlockingPoolSize);
    options.setWorkerPoolSize(workerPoolSize);
    options.setBlockedThreadCheckInterval(blockedThreadCheckInterval);
    options.getEventBusOptions().setHost(clusterHost);
    options.getEventBusOptions().setClusterPublicHost(clusterPublicHost);
    options.getEventBusOptions().setClusterPingInterval(clusterPingInterval);
    options.getEventBusOptions().setClusterPingReplyInterval(clusterPingReplyInterval);
    options.setMaxEventLoopExecuteTime(maxEventLoopExecuteTime);
    options.setMaxWorkerExecuteTime(maxWorkerExecuteTime);
    options.setHAEnabled(haEnabled);
    options.setQuorumSize(quorumSize);
    options.setHAGroup(haGroup);
    options.setMetricsOptions(new MetricsOptions().setEnabled(metricsEnabled));
    options.setTracingOptions(new TracingOptions().setFactory(new FakeTracerFactory()));
    options.setWarningExceptionTime(warningExceptionTime);
    options.setMaxEventLoopExecuteTimeUnit(maxEventLoopExecuteTimeUnit);
    options.setMaxWorkerExecuteTimeUnit(maxWorkerExecuteTimeUnit);
    options.setWarningExceptionTimeUnit(warningExceptionTimeUnit);
    options.setBlockedThreadCheckIntervalUnit(blockedThreadCheckIntervalUnit);
    options = new VertxOptions(options);
    assertEquals(clusterPort, options.getEventBusOptions().getPort());
    assertEquals(clusterPublicPort, options.getEventBusOptions().getClusterPublicPort());
    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(clusterPublicHost, options.getEventBusOptions().getClusterPublicHost());
    assertEquals(maxEventLoopExecuteTime, options.getMaxEventLoopExecuteTime());
    assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
    assertEquals(haEnabled, options.isHAEnabled());
    assertEquals(quorumSize, options.getQuorumSize());
    assertEquals(haGroup, options.getHAGroup());
    MetricsOptions metricsOptions = options.getMetricsOptions();
    assertNotNull(metricsOptions);
    assertEquals(metricsEnabled, metricsOptions.isEnabled());
    TracingOptions tracingOptions = options.getTracingOptions();
    assertNotNull(tracingOptions);
    assertTrue(tracingOptions.getFactory() instanceof FakeTracerFactory);
    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) TracingOptions(io.vertx.core.tracing.TracingOptions) Random(java.util.Random) FakeTracerFactory(io.vertx.test.faketracer.FakeTracerFactory) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 45 with MetricsOptions

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

the class MetricsOptionsTest method testMetricsFromServiceLoader.

@Test
public void testMetricsFromServiceLoader() {
    vertx.close();
    VertxOptions options = new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true));
    vertx = createVertxLoadingMetricsFromMetaInf(options, "io.vertx.test.fakemetrics.FakeMetricsFactory");
    VertxMetrics metrics = ((VertxInternal) vertx).metricsSPI();
    assertNotNull(metrics);
    assertTrue(metrics instanceof FakeVertxMetrics);
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) FakeVertxMetrics(io.vertx.test.fakemetrics.FakeVertxMetrics) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) VertxInternal(io.vertx.core.impl.VertxInternal) FakeVertxMetrics(io.vertx.test.fakemetrics.FakeVertxMetrics) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Aggregations

MetricsOptions (io.vertx.core.metrics.MetricsOptions)90 Test (org.junit.Test)74 DummyVertxMetrics (io.vertx.core.metrics.impl.DummyVertxMetrics)49 VertxMetricsFactory (io.vertx.core.spi.VertxMetricsFactory)41 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)39 CountDownLatch (java.util.concurrent.CountDownLatch)37 AtomicReference (java.util.concurrent.atomic.AtomicReference)37 io.vertx.core (io.vertx.core)36 Buffer (io.vertx.core.buffer.Buffer)36 DatagramSocket (io.vertx.core.datagram.DatagramSocket)36 DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)36 EventBus (io.vertx.core.eventbus.EventBus)36 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)36 io.vertx.core.http (io.vertx.core.http)36 io.vertx.core.net (io.vertx.core.net)36 BiConsumer (java.util.function.BiConsumer)36 Function (java.util.function.Function)36 VertxOptions (io.vertx.core.VertxOptions)28 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 EventBusOptions (io.vertx.core.eventbus.EventBusOptions)24