Search in sources :

Example 1 with NodeSelector

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));
}
Also used : WrappedClusterManager(io.vertx.core.spi.cluster.WrappedClusterManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) NodeSelector(io.vertx.core.spi.cluster.NodeSelector) WrappedNodeSelector(io.vertx.core.spi.cluster.WrappedNodeSelector) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 2 with NodeSelector

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();
}
Also used : NodeSelector(io.vertx.core.spi.cluster.NodeSelector) DefaultNodeSelector(io.vertx.core.spi.cluster.impl.DefaultNodeSelector) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) VertxBuilder(io.vertx.core.impl.VertxBuilder) Test(org.junit.Test) VertxTestBase(io.vertx.test.core.VertxTestBase) Collections(java.util.Collections) Promise(io.vertx.core.Promise) DefaultNodeSelector(io.vertx.core.spi.cluster.impl.DefaultNodeSelector) NodeSelector(io.vertx.core.spi.cluster.NodeSelector) DefaultNodeSelector(io.vertx.core.spi.cluster.impl.DefaultNodeSelector) VertxBuilder(io.vertx.core.impl.VertxBuilder) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 3 with NodeSelector

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();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) NodeSelector(io.vertx.core.spi.cluster.NodeSelector) WrappedClusterManager(io.vertx.core.spi.cluster.WrappedClusterManager) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Stream(java.util.stream.Stream) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RegistrationUpdateEvent(io.vertx.core.spi.cluster.RegistrationUpdateEvent) Cert(io.vertx.test.tls.Cert) WrappedNodeSelector(io.vertx.core.spi.cluster.WrappedNodeSelector) WrappedNodeSelector(io.vertx.core.spi.cluster.WrappedNodeSelector) WrappedClusterManager(io.vertx.core.spi.cluster.WrappedClusterManager) NodeSelector(io.vertx.core.spi.cluster.NodeSelector) WrappedNodeSelector(io.vertx.core.spi.cluster.WrappedNodeSelector) CountDownLatch(java.util.concurrent.CountDownLatch) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) RegistrationUpdateEvent(io.vertx.core.spi.cluster.RegistrationUpdateEvent) Test(org.junit.Test)

Example 4 with NodeSelector

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();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) NodeSelector(io.vertx.core.spi.cluster.NodeSelector) WrappedClusterManager(io.vertx.core.spi.cluster.WrappedClusterManager) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Stream(java.util.stream.Stream) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RegistrationUpdateEvent(io.vertx.core.spi.cluster.RegistrationUpdateEvent) Cert(io.vertx.test.tls.Cert) WrappedNodeSelector(io.vertx.core.spi.cluster.WrappedNodeSelector) WrappedClusterManager(io.vertx.core.spi.cluster.WrappedClusterManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) NodeSelector(io.vertx.core.spi.cluster.NodeSelector) WrappedNodeSelector(io.vertx.core.spi.cluster.WrappedNodeSelector) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Aggregations

Vertx (io.vertx.core.Vertx)4 VertxOptions (io.vertx.core.VertxOptions)4 NodeSelector (io.vertx.core.spi.cluster.NodeSelector)4 Test (org.junit.Test)4 Promise (io.vertx.core.Promise)3 WrappedClusterManager (io.vertx.core.spi.cluster.WrappedClusterManager)3 WrappedNodeSelector (io.vertx.core.spi.cluster.WrappedNodeSelector)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 VertxInternal (io.vertx.core.impl.VertxInternal)2 RegistrationUpdateEvent (io.vertx.core.spi.cluster.RegistrationUpdateEvent)2 TestUtils (io.vertx.test.core.TestUtils)2 Cert (io.vertx.test.tls.Cert)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Consumer (java.util.function.Consumer)2