Search in sources :

Example 1 with VertxOptions

use of io.vertx.core.VertxOptions in project vert.x by eclipse.

the class EventBusExamples method example12.

public void example12() {
    VertxOptions options = new VertxOptions();
    Vertx.clusteredVertx(options, res -> {
        if (res.succeeded()) {
            Vertx vertx = res.result();
            EventBus eventBus = vertx.eventBus();
            System.out.println("We now have a clustered event bus: " + eventBus);
        } else {
            System.out.println("Failed: " + res.cause());
        }
    });
}
Also used : EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions)

Example 2 with VertxOptions

use of io.vertx.core.VertxOptions in project vert.x by eclipse.

the class ClusteredEventBusTest method testClusteredPong.

// Make sure ping/pong works ok
@Test
public void testClusteredPong() throws Exception {
    startNodes(2, new VertxOptions().setClusterPingInterval(500).setClusterPingReplyInterval(500));
    AtomicBoolean sending = new AtomicBoolean();
    MessageConsumer<String> consumer = vertices[0].eventBus().<String>consumer("foobar").handler(msg -> {
        if (!sending.get()) {
            sending.set(true);
            vertx.setTimer(4000, id -> {
                vertices[1].eventBus().send("foobar", "whatever2");
            });
        } else {
            testComplete();
        }
    });
    consumer.completionHandler(ar -> {
        assertTrue(ar.succeeded());
        vertices[1].eventBus().send("foobar", "whatever");
    });
    await();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 3 with VertxOptions

use of io.vertx.core.VertxOptions in project vert.x by eclipse.

the class LauncherExtensibilityTest method testThatCustomLauncherCanCustomizeTheClusteredOption.

@Test
public void testThatCustomLauncherCanCustomizeTheClusteredOption() {
    Launcher myLauncher = new Launcher() {

        @Override
        protected String getMainVerticle() {
            return HttpTestVerticle.class.getName();
        }

        @Override
        public void afterStartingVertx(Vertx vertx) {
            LauncherExtensibilityTest.this.vertx = vertx;
        }

        @Override
        public void beforeStartingVertx(VertxOptions options) {
            options.setClustered(true);
        }
    };
    myLauncher.dispatch(new String[0]);
    waitUntil(() -> {
        try {
            return RunCommandTest.getHttpCode() == 200;
        } catch (IOException e) {
            return false;
        }
    });
    assertThat(this.vertx.isClustered()).isTrue();
}
Also used : Launcher(io.vertx.core.Launcher) IOException(java.io.IOException) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) RunCommandTest(io.vertx.core.impl.launcher.commands.RunCommandTest)

Example 4 with VertxOptions

use of io.vertx.core.VertxOptions in project vert.x by eclipse.

the class HostnameResolutionTest method testMultipleSearchDomain.

@Test
public void testMultipleSearchDomain() throws Exception {
    Map<String, String> records = new HashMap<>();
    records.put("host1.foo.com", "127.0.0.1");
    records.put("host2.bar.com", "127.0.0.2");
    records.put("host3.bar.com", "127.0.0.3");
    records.put("host3.foo.com", "127.0.0.4");
    dnsServer.stop();
    dnsServer = FakeDNSServer.testResolveA(records);
    dnsServer.start();
    VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com").addSearchDomain("bar.com")));
    // "host1" resolves via the "foo.com" search path
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx.resolveAddress("host1", onSuccess(resolved -> {
        assertEquals("127.0.0.1", resolved.getHostAddress());
        latch1.countDown();
    }));
    awaitLatch(latch1);
    // "host2" resolves via the "bar.com" search path
    CountDownLatch latch2 = new CountDownLatch(1);
    vertx.resolveAddress("host2", onSuccess(resolved -> {
        assertEquals("127.0.0.2", resolved.getHostAddress());
        latch2.countDown();
    }));
    awaitLatch(latch2);
    // "host3" resolves via the the "foo.com" search path as it is the first one
    CountDownLatch latch3 = new CountDownLatch(1);
    vertx.resolveAddress("host3", onSuccess(resolved -> {
        assertEquals("127.0.0.4", resolved.getHostAddress());
        latch3.countDown();
    }));
    awaitLatch(latch3);
    // "host4" does not resolve
    vertx.resolveAddress("host4", onFailure(cause -> {
        assertTrue(cause instanceof UnknownHostException);
        testComplete();
    }));
    await();
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) VertxException(io.vertx.core.VertxException) Arrays(java.util.Arrays) HttpServer(io.vertx.core.http.HttpServer) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Locale(java.util.Locale) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) NetClient(io.vertx.core.net.NetClient) VertxImpl(io.vertx.core.impl.VertxImpl) VertxInternal(io.vertx.core.impl.VertxInternal) ChannelInitializer(io.netty.channel.ChannelInitializer) AddressResolver(io.vertx.core.impl.AddressResolver) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) Collections(java.util.Collections) HttpClient(io.vertx.core.http.HttpClient) VertxInternal(io.vertx.core.impl.VertxInternal) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 5 with VertxOptions

use of io.vertx.core.VertxOptions in project vert.x by eclipse.

the class HostnameResolutionTest method testSearchDomainWithNdots0.

@Test
public void testSearchDomainWithNdots0() throws Exception {
    Map<String, String> records = new HashMap<>();
    records.put("host1", "127.0.0.2");
    records.put("host1.foo.com", "127.0.0.3");
    dnsServer.stop();
    dnsServer = FakeDNSServer.testResolveA(records);
    dnsServer.start();
    VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com").setNdots(0)));
    // "host1" resolves directly as ndots = 0
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx.resolveAddress("host1", onSuccess(resolved -> {
        assertEquals("127.0.0.2", resolved.getHostAddress());
        latch1.countDown();
    }));
    awaitLatch(latch1);
    // "host1.foo.com" resolves to host1.foo.com
    CountDownLatch latch2 = new CountDownLatch(1);
    vertx.resolveAddress("host1.foo.com", onSuccess(resolved -> {
        assertEquals("127.0.0.3", resolved.getHostAddress());
        latch2.countDown();
    }));
    awaitLatch(latch2);
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) VertxException(io.vertx.core.VertxException) Arrays(java.util.Arrays) HttpServer(io.vertx.core.http.HttpServer) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Locale(java.util.Locale) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) NetClient(io.vertx.core.net.NetClient) VertxImpl(io.vertx.core.impl.VertxImpl) VertxInternal(io.vertx.core.impl.VertxInternal) ChannelInitializer(io.netty.channel.ChannelInitializer) AddressResolver(io.vertx.core.impl.AddressResolver) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) Collections(java.util.Collections) HttpClient(io.vertx.core.http.HttpClient) VertxInternal(io.vertx.core.impl.VertxInternal) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Aggregations

VertxOptions (io.vertx.core.VertxOptions)38 Test (org.junit.Test)30 VertxInternal (io.vertx.core.impl.VertxInternal)12 JsonObject (io.vertx.core.json.JsonObject)12 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 Vertx (io.vertx.core.Vertx)9 VertxException (io.vertx.core.VertxException)9 NetClient (io.vertx.core.net.NetClient)9 NetServer (io.vertx.core.net.NetServer)9 NetServerOptions (io.vertx.core.net.NetServerOptions)9 InetAddress (java.net.InetAddress)9 HashMap (java.util.HashMap)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 TimeUnit (java.util.concurrent.TimeUnit)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 Channel (io.netty.channel.Channel)8 ChannelFuture (io.netty.channel.ChannelFuture)8 ChannelInitializer (io.netty.channel.ChannelInitializer)8