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);
}
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);
}
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);
}
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);
}
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.");
}
}
Aggregations