Search in sources :

Example 21 with AddressResolverOptions

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

the class HostnameResolutionTest method testDefaultJsonOptions.

@Test
public void testDefaultJsonOptions() {
    AddressResolverOptions options = new AddressResolverOptions(new JsonObject());
    assertEquals(AddressResolverOptions.DEFAULT_OPT_RESOURCE_ENABLED, options.isOptResourceEnabled());
    assertEquals(AddressResolverOptions.DEFAULT_SERVERS, options.getServers());
    assertEquals(AddressResolverOptions.DEFAULT_CACHE_MIN_TIME_TO_LIVE, options.getCacheMinTimeToLive());
    assertEquals(AddressResolverOptions.DEFAULT_CACHE_MAX_TIME_TO_LIVE, options.getCacheMaxTimeToLive());
    assertEquals(AddressResolverOptions.DEFAULT_CACHE_NEGATIVE_TIME_TO_LIVE, options.getCacheNegativeTimeToLive());
    assertEquals(AddressResolverOptions.DEFAULT_QUERY_TIMEOUT, options.getQueryTimeout());
    assertEquals(AddressResolverOptions.DEFAULT_MAX_QUERIES, options.getMaxQueries());
    assertEquals(AddressResolverOptions.DEFAULT_RD_FLAG, options.getRdFlag());
    assertEquals(AddressResolverOptions.DEFAULT_SEACH_DOMAINS, options.getSearchDomains());
    assertEquals(AddressResolverOptions.DEFAULT_NDOTS, options.getNdots());
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 22 with AddressResolverOptions

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

the class HostnameResolutionTest method testResolveFromFile.

@Test
public void testResolveFromFile() {
    File f = new File(new File(new File(new File("src"), "test"), "resources"), "hosts_config.txt");
    VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsPath(f.getAbsolutePath())));
    vertx.resolveAddress("server.net", onSuccess(addr -> {
        assertEquals("192.168.0.15", addr.getHostAddress());
        assertEquals("server.net", addr.getHostName());
        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) File(java.io.File) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 23 with AddressResolverOptions

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

the class HostnameResolutionTest method testSearchDomain.

@Test
public void testSearchDomain() throws Exception {
    Map<String, String> records = new HashMap<>();
    records.put("host1.foo.com", "127.0.0.1");
    records.put("host1", "127.0.0.2");
    records.put("host3", "127.0.0.3");
    records.put("host4.sub.foo.com", "127.0.0.4");
    records.put("host5.sub.foo.com", "127.0.0.5");
    records.put("host5.sub", "127.0.0.6");
    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")));
    // host1 resolves host1.foo.com with foo.com search domain
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx.resolveAddress("host1", onSuccess(resolved -> {
        assertEquals("127.0.0.1", resolved.getHostAddress());
        latch1.countDown();
    }));
    awaitLatch(latch1);
    // "host1." absolute query
    CountDownLatch latch2 = new CountDownLatch(1);
    vertx.resolveAddress("host1.", onSuccess(resolved -> {
        assertEquals("127.0.0.2", resolved.getHostAddress());
        latch2.countDown();
    }));
    awaitLatch(latch2);
    // "host2" not resolved
    CountDownLatch latch3 = new CountDownLatch(1);
    vertx.resolveAddress("host2", onFailure(cause -> {
        assertTrue(cause instanceof UnknownHostException);
        latch3.countDown();
    }));
    awaitLatch(latch3);
    // "host3" does not contain a dot or is not absolute
    CountDownLatch latch4 = new CountDownLatch(1);
    vertx.resolveAddress("host3", onFailure(cause -> {
        assertTrue(cause instanceof UnknownHostException);
        latch4.countDown();
    }));
    awaitLatch(latch4);
    // "host3." does not contain a dot but is absolute
    CountDownLatch latch5 = new CountDownLatch(1);
    vertx.resolveAddress("host3.", onSuccess(resolved -> {
        assertEquals("127.0.0.3", resolved.getHostAddress());
        latch5.countDown();
    }));
    awaitLatch(latch5);
    // "host4.sub" contains a dot but not resolved then resolved to "host4.sub.foo.com" with "foo.com" search domain
    CountDownLatch latch6 = new CountDownLatch(1);
    vertx.resolveAddress("host4.sub", onSuccess(resolved -> {
        assertEquals("127.0.0.4", resolved.getHostAddress());
        latch6.countDown();
    }));
    awaitLatch(latch6);
    // "host5.sub" contains a dot and is resolved
    CountDownLatch latch7 = new CountDownLatch(1);
    vertx.resolveAddress("host5.sub", onSuccess(resolved -> {
        assertEquals("127.0.0.6", resolved.getHostAddress());
        latch7.countDown();
    }));
    awaitLatch(latch7);
}
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 24 with AddressResolverOptions

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

the class HostnameResolutionTest method testInvalidHostsConfig.

@Test
public void testInvalidHostsConfig() {
    try {
        AddressResolverOptions options = new AddressResolverOptions().setHostsPath("whatever.txt");
        vertx(new VertxOptions().setAddressResolverOptions(options));
        fail();
    } catch (VertxException ignore) {
    }
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) VertxException(io.vertx.core.VertxException) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 25 with AddressResolverOptions

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

the class HostnameResolutionTest method testSearchDomainWithNdots2.

@Test
public void testSearchDomainWithNdots2() throws Exception {
    Map<String, String> records = new HashMap<>();
    records.put("host1.sub.foo.com", "127.0.0.1");
    records.put("host2.sub.foo.com", "127.0.0.2");
    records.put("host2.sub", "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(2)));
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx.resolveAddress("host1.sub", onSuccess(resolved -> {
        assertEquals("127.0.0.1", resolved.getHostAddress());
        latch1.countDown();
    }));
    awaitLatch(latch1);
    // "host2.sub" is resolved with the foo.com search domain as ndots = 2
    CountDownLatch latch2 = new CountDownLatch(1);
    vertx.resolveAddress("host2.sub", onSuccess(resolved -> {
        assertEquals("127.0.0.2", 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

AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)30 Test (org.junit.Test)25 VertxOptions (io.vertx.core.VertxOptions)13 AddressResolver (io.vertx.core.impl.AddressResolver)11 InetAddress (java.net.InetAddress)11 CompletableFuture (java.util.concurrent.CompletableFuture)11 FakeDNSServer (io.vertx.test.fakedns.FakeDNSServer)10 InetSocketAddress (java.net.InetSocketAddress)10 ArrayList (java.util.ArrayList)10 VertxException (io.vertx.core.VertxException)9 Buffer (io.vertx.core.buffer.Buffer)9 VertxInternal (io.vertx.core.impl.VertxInternal)9 JsonObject (io.vertx.core.json.JsonObject)9 NetClient (io.vertx.core.net.NetClient)9 NetServer (io.vertx.core.net.NetServer)9 NetServerOptions (io.vertx.core.net.NetServerOptions)9 HashMap (java.util.HashMap)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 Channel (io.netty.channel.Channel)8