use of io.vertx.core.spi.cluster.ClusterManager in project api-framework by vinscom.
the class SingletonServiceImplTest method testStart.
@Test
public void testStart(TestContext context) throws InterruptedException, ExecutionException {
Async async = context.async(2);
Vertx vertx = Glue.instance().resolve("/io/vertx/core/Vertx");
ClusterManager cm = Glue.instance().resolve("/io/vertx/spi/cluster/ClusterManager");
vertx.sharedData().<String, String>rxGetClusterWideMap("__in.erail.services").flatMapCompletable(// Service is running on some other node
(m) -> m.rxPut("DummySingletonService", "NodeDownID")).subscribe(() -> {
DummySingletonService service = Glue.instance().resolve("/in/erail/service/DummySingletonService");
Observable.timer(100, TimeUnit.MILLISECONDS).subscribe((t) -> {
vertx.sharedData().<String, String>rxGetClusterWideMap("__in.erail.services").flatMap((m) -> {
return m.rxGet("DummySingletonService");
}).doOnSuccess((nodeId) -> {
// Validate after starting this service. Control is still with other node
context.assertNotEquals(cm.getNodeID(), nodeId);
async.countDown();
}).subscribe((nodeId) -> {
// Trigger remote node leave
service.nodeLeft("NodeDownID");
Observable.timer(100, TimeUnit.MILLISECONDS).subscribe((p) -> {
vertx.sharedData().<String, String>rxGetClusterWideMap("__in.erail.services").flatMap(m2 -> {
return m2.rxGet("DummySingletonService");
}).subscribe((updatedNodeId) -> {
context.assertEquals(cm.getNodeID(), updatedNodeId);
context.assertEquals(service.getRecorder().size(), 1);
async.countDown();
});
});
});
});
});
}
use of io.vertx.core.spi.cluster.ClusterManager in project vertx-zero by silentbalanceyh.
the class Motor method start.
public static <T> void start(final Class<?> clazz, final Consumer<T> consumer, final Consumer<Consumer<T>> fnSingle, final BiConsumer<ClusterManager, Consumer<T>> fnCluster, final Annal logger) {
if (null == consumer) {
throw new VertxCallbackException(clazz);
}
// 1. Check if clustered mode
final ClusterOptions cluster = ZeroGrid.getClusterOption();
if (cluster.isEnabled()) {
// 2.1. Clustered
final ClusterManager manager = cluster.getManager();
logger.info(Info.APP_CLUSTERD, manager.getClass().getName(), manager.getNodeID(), manager.isActive());
fnCluster.accept(manager, consumer);
} else {
// 2.2. Standalone
fnSingle.accept(consumer);
}
}
use of io.vertx.core.spi.cluster.ClusterManager in project vert.x by eclipse.
the class VertxOptionsTest method testOptions.
@Test
public void testOptions() {
VertxOptions options = new VertxOptions();
assertEquals(2 * Runtime.getRuntime().availableProcessors(), options.getEventLoopPoolSize());
int rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setEventLoopPoolSize(rand));
assertEquals(rand, options.getEventLoopPoolSize());
try {
options.setEventLoopPoolSize(0);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertEquals(20, options.getWorkerPoolSize());
rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setWorkerPoolSize(rand));
assertEquals(rand, options.getWorkerPoolSize());
try {
options.setWorkerPoolSize(0);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertEquals(20, options.getInternalBlockingPoolSize());
rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setInternalBlockingPoolSize(rand));
assertEquals(rand, options.getInternalBlockingPoolSize());
try {
options.setInternalBlockingPoolSize(0);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertEquals(0, options.getEventBusOptions().getPort());
options.getEventBusOptions().setPort(1234);
assertEquals(1234, options.getEventBusOptions().getPort());
try {
options.getEventBusOptions().setPort(-1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
try {
options.getEventBusOptions().setPort(65536);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertEquals(-1, options.getEventBusOptions().getClusterPublicPort());
options.getEventBusOptions().setClusterPublicPort(1234);
assertEquals(1234, options.getEventBusOptions().getClusterPublicPort());
try {
options.getEventBusOptions().setClusterPublicPort(-1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
try {
options.getEventBusOptions().setClusterPublicPort(65536);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertNull(options.getEventBusOptions().getHost());
String randString = TestUtils.randomUnicodeString(100);
options.getEventBusOptions().setHost(randString);
assertEquals(randString, options.getEventBusOptions().getHost());
assertEquals(null, options.getEventBusOptions().getClusterPublicHost());
randString = TestUtils.randomUnicodeString(100);
options.getEventBusOptions().setClusterPublicHost(randString);
assertEquals(randString, options.getEventBusOptions().getClusterPublicHost());
assertEquals(20000, options.getEventBusOptions().getClusterPingInterval());
long randomLong = TestUtils.randomPositiveLong();
options.getEventBusOptions().setClusterPingInterval(randomLong);
assertEquals(randomLong, options.getEventBusOptions().getClusterPingInterval());
try {
options.getEventBusOptions().setClusterPingInterval(-1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
assertEquals(randomLong, options.getEventBusOptions().getClusterPingInterval());
}
assertEquals(20000, options.getEventBusOptions().getClusterPingReplyInterval());
randomLong = TestUtils.randomPositiveLong();
options.getEventBusOptions().setClusterPingReplyInterval(randomLong);
assertEquals(randomLong, options.getEventBusOptions().getClusterPingReplyInterval());
try {
options.getEventBusOptions().setClusterPingReplyInterval(-1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
assertEquals(randomLong, options.getEventBusOptions().getClusterPingReplyInterval());
}
assertEquals(1000, options.getBlockedThreadCheckInterval());
rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setBlockedThreadCheckInterval(rand));
assertEquals(rand, options.getBlockedThreadCheckInterval());
try {
options.setBlockedThreadCheckInterval(0);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
// 2 seconds in nano seconds
assertEquals(2000l * 1000000, options.getMaxEventLoopExecuteTime());
rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setMaxEventLoopExecuteTime(rand));
assertEquals(rand, options.getMaxEventLoopExecuteTime());
try {
options.setMaxEventLoopExecuteTime(0);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
// 1 minute in nano seconds
assertEquals(1l * 60 * 1000 * 1000000, options.getMaxWorkerExecuteTime());
rand = TestUtils.randomPositiveInt();
assertEquals(options, options.setMaxWorkerExecuteTime(rand));
assertEquals(rand, options.getMaxWorkerExecuteTime());
try {
options.setMaxWorkerExecuteTime(0);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
ClusterManager mgr = new FakeClusterManager();
assertNull(options.getClusterManager());
assertEquals(options, options.setClusterManager(mgr));
assertSame(mgr, options.getClusterManager());
assertFalse(options.isHAEnabled());
assertEquals(options, options.setHAEnabled(true));
assertTrue(options.isHAEnabled());
rand = TestUtils.randomPositiveInt();
assertEquals(1, options.getQuorumSize());
assertEquals(options, options.setQuorumSize(rand));
assertEquals(rand, options.getQuorumSize());
try {
options.setQuorumSize(0);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
try {
options.setQuorumSize(-1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup());
randString = TestUtils.randomUnicodeString(100);
assertEquals(options, options.setHAGroup(randString));
assertEquals(randString, options.getHAGroup());
try {
options.setHAGroup(null);
fail("Should throw exception");
} catch (NullPointerException e) {
// OK
}
assertNotNull(options.getMetricsOptions());
try {
options.setWarningExceptionTime(-1);
fail("Should throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertEquals(options, options.setWarningExceptionTime(1000000000l));
assertEquals(1000000000l, options.getWarningExceptionTime());
assertEquals(options, options.setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS));
assertEquals(TimeUnit.SECONDS, options.getMaxEventLoopExecuteTimeUnit());
assertEquals(options, options.setMaxWorkerExecuteTimeUnit(TimeUnit.MILLISECONDS));
assertEquals(TimeUnit.MILLISECONDS, options.getMaxWorkerExecuteTimeUnit());
assertEquals(options, options.setWarningExceptionTimeUnit(TimeUnit.MINUTES));
assertEquals(TimeUnit.MINUTES, options.getWarningExceptionTimeUnit());
assertEquals(options, options.setBlockedThreadCheckIntervalUnit(TimeUnit.MILLISECONDS));
assertEquals(TimeUnit.MILLISECONDS, options.getBlockedThreadCheckIntervalUnit());
}
use of io.vertx.core.spi.cluster.ClusterManager in project vertx-examples by vert-x3.
the class MainClassNode1 method main.
public static void main(String[] args) {
JsonObject zkConfig = configureClusterManager();
ClusterManager zookeeperClusterManager = new ZookeeperClusterManager(zkConfig);
VertxOptions options = configureVertx(zookeeperClusterManager);
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(2);
vertx.deployVerticle("verticle.SenderVerticle", deploymentOptions);
System.out.println("Sender verticle deployed");
}
});
}
use of io.vertx.core.spi.cluster.ClusterManager in project vertx-examples by vert-x3.
the class MainClassNode2 method main.
public static void main(String[] args) {
JsonObject zkConfig = configureClusterManager();
ClusterManager zookeeperClusterManager = new ZookeeperClusterManager(zkConfig);
VertxOptions options = configureVertx(zookeeperClusterManager);
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
DeploymentOptions deploymentOptions = new DeploymentOptions().setInstances(2);
vertx.deployVerticle("verticle.ConsumerVerticle", deploymentOptions);
System.out.println("consumer verticle deployed");
}
});
}
Aggregations