Search in sources :

Example 11 with VertxOptions

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

the class HATest method testSimpleFailover.

@Test
public void testSimpleFailover() throws Exception {
    startNodes(2, new VertxOptions().setHAEnabled(true));
    DeploymentOptions options = new DeploymentOptions().setHa(true);
    JsonObject config = new JsonObject().put("foo", "bar");
    options.setConfig(config);
    CountDownLatch latch = new CountDownLatch(1);
    vertices[0].deployVerticle("java:" + HAVerticle1.class.getName(), options, ar -> {
        assertTrue(ar.succeeded());
        assertEquals(1, vertices[0].deploymentIDs().size());
        assertEquals(0, vertices[1].deploymentIDs().size());
        latch.countDown();
    });
    awaitLatch(latch);
    kill(0);
    waitUntil(() -> vertices[1].deploymentIDs().size() == 1);
    checkDeploymentExists(1, "java:" + HAVerticle1.class.getName(), options);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 12 with VertxOptions

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

the class StarterTest method testConfigureFromSystemProperties.

private void testConfigureFromSystemProperties(boolean clustered) throws Exception {
    // One for each type that we support
    System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "eventLoopPoolSize", "123");
    System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "maxEventLoopExecuteTime", "123767667");
    System.setProperty(Starter.METRICS_OPTIONS_PROP_PREFIX + "enabled", "true");
    System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "haGroup", "somegroup");
    MyStarter starter = new MyStarter();
    String[] args;
    if (clustered) {
        args = new String[] { "run", "java:" + TestVerticle.class.getCanonicalName(), "-cluster" };
    } else {
        args = new String[] { "run", "java:" + TestVerticle.class.getCanonicalName() };
    }
    starter.run(args);
    waitUntil(() -> TestVerticle.instanceCount.get() == 1);
    VertxOptions opts = starter.getVertxOptions();
    assertEquals(123, opts.getEventLoopPoolSize(), 0);
    assertEquals(123767667L, opts.getMaxEventLoopExecuteTime());
    assertEquals(true, opts.getMetricsOptions().isEnabled());
    assertEquals("somegroup", opts.getHAGroup());
    cleanup(starter);
}
Also used : VertxOptions(io.vertx.core.VertxOptions)

Example 13 with VertxOptions

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

the class StarterTest method testConfigureFromSystemPropertiesInvalidPropertyType.

@Test
public void testConfigureFromSystemPropertiesInvalidPropertyType() throws Exception {
    // One for each type that we support
    System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "eventLoopPoolSize", "sausages");
    // Should be ignored
    MyStarter starter = new MyStarter();
    String[] args = { "run", "java:" + TestVerticle.class.getCanonicalName() };
    starter.run(args);
    waitUntil(() -> TestVerticle.instanceCount.get() == 1);
    VertxOptions opts = starter.getVertxOptions();
    VertxOptions def = new VertxOptions();
    if (opts.getMetricsOptions().isEnabled()) {
        def.getMetricsOptions().setEnabled(true);
    }
    assertEquals(def, opts);
    cleanup(starter);
}
Also used : VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 14 with VertxOptions

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

the class MetricsOptionsTest method testMetricsEnabledWithoutConfig.

@Test
public void testMetricsEnabledWithoutConfig() {
    vertx.close();
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true)));
    VertxMetrics metrics = ((VertxInternal) vertx).metricsSPI();
    assertNotNull(metrics);
    assertTrue(metrics instanceof DummyVertxMetrics);
}
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) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 15 with VertxOptions

use of io.vertx.core.VertxOptions in project camel by apache.

the class VertxComponent method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    if (vertx == null) {
        if (vertxFactory == null) {
            vertxFactory = new VertxFactoryImpl();
        }
        if (vertxOptions == null) {
            vertxOptions = new VertxOptions();
            if (ObjectHelper.isNotEmpty(host)) {
                vertxOptions.setClusterHost(host);
                vertxOptions.setClustered(true);
            }
            if (port > 0) {
                vertxOptions.setClusterPort(port);
                vertxOptions.setClustered(true);
            }
        }
        // we are creating vertx so we should handle its lifecycle
        createdVertx = true;
        final CountDownLatch latch = new CountDownLatch(1);
        // lets using a host / port if a host name is specified
        if (vertxOptions.isClustered()) {
            LOG.info("Creating Clustered Vertx {}:{}", vertxOptions.getClusterHost(), vertxOptions.getClusterPort());
            // use the async api as we want to wait for the eventbus to be ready before we are in started state
            vertxFactory.clusteredVertx(vertxOptions, new Handler<AsyncResult<Vertx>>() {

                @Override
                public void handle(AsyncResult<Vertx> event) {
                    if (event.cause() != null) {
                        LOG.warn("Error creating Clustered Vertx " + host + ":" + port + " due " + event.cause().getMessage(), event.cause());
                    } else if (event.succeeded()) {
                        vertx = event.result();
                        LOG.info("EventBus is ready: {}", vertx);
                    }
                    latch.countDown();
                }
            });
        } else {
            LOG.info("Creating Non-Clustered Vertx");
            vertx = vertxFactory.vertx();
            LOG.info("EventBus is ready: {}", vertx);
            latch.countDown();
        }
        if (latch.getCount() > 0) {
            LOG.info("Waiting for EventBus to be ready using {} sec as timeout", timeout);
            latch.await(timeout, TimeUnit.SECONDS);
        }
    } else {
        LOG.debug("Using Vert.x instance set on the component level.");
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) AsyncResult(io.vertx.core.AsyncResult) VertxFactoryImpl(io.vertx.core.impl.VertxFactoryImpl)

Aggregations

VertxOptions (io.vertx.core.VertxOptions)38 Test (org.junit.Test)30 VertxInternal (io.vertx.core.impl.VertxInternal)12 JsonObject (io.vertx.core.json.JsonObject)12 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 Vertx (io.vertx.core.Vertx)9 VertxException (io.vertx.core.VertxException)9 NetClient (io.vertx.core.net.NetClient)9 NetServer (io.vertx.core.net.NetServer)9 NetServerOptions (io.vertx.core.net.NetServerOptions)9 InetAddress (java.net.InetAddress)9 HashMap (java.util.HashMap)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 TimeUnit (java.util.concurrent.TimeUnit)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 Channel (io.netty.channel.Channel)8 ChannelFuture (io.netty.channel.ChannelFuture)8 ChannelInitializer (io.netty.channel.ChannelInitializer)8