Search in sources :

Example 1 with RegistrationUpdateEvent

use of io.vertx.core.spi.cluster.RegistrationUpdateEvent 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)

Aggregations

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