use of io.vertx.core.spi.cluster.NodeSelector in project vert.x by eclipse.
the class ClusteredEventBusTest method testSelectorDoesNotWantUpdates.
@Test
public void testSelectorDoesNotWantUpdates() throws Exception {
AtomicReference<NodeSelector> nodeSelectorRef = new AtomicReference<>();
VertxOptions options = getOptions().setClusterManager(new WrappedClusterManager(getClusterManager()) {
@Override
public void init(Vertx vertx, NodeSelector nodeSelector) {
nodeSelectorRef.set(nodeSelector);
super.init(vertx, nodeSelector);
}
});
startNodes(options);
assertNotNull(nodeSelectorRef.get());
assertFalse(nodeSelectorRef.get().wantsUpdatesFor(ADDRESS1));
}
use of io.vertx.core.spi.cluster.NodeSelector in project vert.x by eclipse.
the class WriteHandlerLookupFailureTest method test.
@Test
public void test() {
Throwable cause = new Throwable();
VertxOptions options = new VertxOptions();
options.getEventBusOptions().setHost("localhost").setPort(0);
NodeSelector nodeSelector = new DefaultNodeSelector() {
@Override
public void selectForSend(Message<?> message, Promise<String> promise) {
promise.fail(cause);
}
@Override
public void selectForPublish(Message<?> message, Promise<Iterable<String>> promise) {
promise.fail("Not implemented");
}
};
new VertxBuilder(options).init().clusterNodeSelector(nodeSelector).clusteredVertx(onSuccess(node -> {
vertx = node;
MessageProducer<String> sender = vertx.eventBus().sender("foo");
sender.write("the_string", onFailure(err -> {
assertSame(cause, err);
testComplete();
}));
}));
await();
}
use of io.vertx.core.spi.cluster.NodeSelector in project vert.x by eclipse.
the class ClusteredEventBusTest method testSendWriteHandler.
@Test
public void testSendWriteHandler() throws Exception {
CountDownLatch updateLatch = new CountDownLatch(3);
Supplier<VertxOptions> options = () -> getOptions().setClusterManager(new WrappedClusterManager(getClusterManager()) {
@Override
public void init(Vertx vertx, NodeSelector nodeSelector) {
super.init(vertx, new WrappedNodeSelector(nodeSelector) {
@Override
public void registrationsUpdated(RegistrationUpdateEvent event) {
super.registrationsUpdated(event);
if (event.address().equals(ADDRESS1) && event.registrations().size() == 1) {
updateLatch.countDown();
}
}
@Override
public boolean wantsUpdatesFor(String address) {
return true;
}
});
}
});
startNodes(options.get(), options.get());
waitFor(2);
vertices[1].eventBus().consumer(ADDRESS1, msg -> complete()).completionHandler(onSuccess(v1 -> updateLatch.countDown()));
awaitLatch(updateLatch);
MessageProducer<String> producer = vertices[0].eventBus().sender(ADDRESS1);
producer.write("body", onSuccess(v2 -> complete()));
await();
}
use of io.vertx.core.spi.cluster.NodeSelector in project vert.x by eclipse.
the class ClusteredEventBusTest method testSelectorWantsUpdates.
@Test
public void testSelectorWantsUpdates() throws Exception {
AtomicReference<NodeSelector> nodeSelectorRef = new AtomicReference<>();
VertxOptions options = getOptions().setClusterManager(new WrappedClusterManager(getClusterManager()) {
@Override
public void init(Vertx vertx, NodeSelector nodeSelector) {
nodeSelectorRef.set(nodeSelector);
super.init(vertx, nodeSelector);
}
});
startNodes(options);
assertNotNull(nodeSelectorRef.get());
vertices[0].eventBus().consumer(ADDRESS1, msg -> {
assertTrue(nodeSelectorRef.get().wantsUpdatesFor(ADDRESS1));
testComplete();
}).completionHandler(onSuccess(v -> vertices[0].eventBus().send(ADDRESS1, "foo")));
await();
}
Aggregations