@Override protected VertxOptions getOptions() { VertxOptions options = super.getOptions(); options.getAddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()); options.getAddressResolverOptions().setOptResourceEnabled(false); return options; }
@Override protected VertxOptions getOptions() { VertxOptions options = super.getOptions(); options.getAddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()); options.getAddressResolverOptions().setOptResourceEnabled(false); return options; }
@Test public void testServerFailover() throws Exception { FakeDNSServer server = new FakeDNSServer().store(FakeDNSServer.A_store(Collections.singletonMap("vertx.io", "127.0.0.1"))).port(FakeDNSServer.PORT + 2); try { AddressResolverOptions options = new AddressResolverOptions(); options.setOptResourceEnabled(false); options.setMaxQueries(4); // 2 + 2 server.start(); InetSocketAddress dnsServerAddress = server.localAddress(); // First server is unreachable options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + (FakeDNSServer.PORT + 1)); // Second server is the failed over server options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()); AddressResolver resolver = new AddressResolver((VertxImpl) vertx, options); CompletableFuture<InetAddress> result = new CompletableFuture<>(); resolver.resolveHostname("vertx.io", ar -> { if (ar.succeeded()) { result.complete(ar.result()); } else { result.completeExceptionally(ar.cause()); } }); String resolved = result.get(10, TimeUnit.SECONDS).getHostAddress(); assertEquals("127.0.0.1", resolved); } finally { server.stop(); } } }
addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false) ));
@Test public void testNetSearchDomain() throws Exception { Map<String, String> records = new HashMap<>(); records.put("host1.foo.com", "127.0.0.1"); dnsServer.testResolveA(records); vertx.close(); vertx = vertx(new VertxOptions().setAddressResolverOptions( new AddressResolverOptions(). setHostsValue(Buffer.buffer()). setNdots(1). addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false). addSearchDomain("foo.com") )); testNet("host1"); }
options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort());
private void testDefaultDnsClient(Function<Vertx, DnsClient> clientProvider) throws Exception { final String ip = "10.0.0.1"; dnsServer.testLookup4(ip); VertxOptions vertxOptions = new VertxOptions(); InetSocketAddress fakeServerAddress = dnsServer.localAddress(); vertxOptions.getAddressResolverOptions().addServer(fakeServerAddress.getHostString() + ":" + fakeServerAddress.getPort()); Vertx vertxWithFakeDns = Vertx.vertx(vertxOptions); DnsClient dnsClient = clientProvider.apply(vertxWithFakeDns); dnsClient.lookup4("vertx.io", onSuccess(result -> { assertEquals(ip, result); testComplete(); })); await(); vertxWithFakeDns.close(); }
@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.testResolveA(records); 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); }
@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.testResolveA(records); 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); }
setHostsValue(Buffer.buffer()). setNdots(1). addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false). addSearchDomain("foo.com").
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions( new AddressResolverOptions(). addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false). setNdots(2).
@Override protected VertxOptions getOptions() { VertxOptions options = super.getOptions(); options.getAddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()); options.getAddressResolverOptions().setOptResourceEnabled(false); return options; }
@Override protected VertxOptions getOptions() { VertxOptions options = super.getOptions(); options.getAddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()); options.getAddressResolverOptions().setOptResourceEnabled(false); return options; }
@Test public void testServerFailover() throws Exception { FakeDNSServer server = new FakeDNSServer().store(FakeDNSServer.A_store(Collections.singletonMap("vertx.io", "127.0.0.1"))).port(FakeDNSServer.PORT + 2); try { AddressResolverOptions options = new AddressResolverOptions(); options.setOptResourceEnabled(false); options.setMaxQueries(4); // 2 + 2 server.start(); InetSocketAddress dnsServerAddress = server.localAddress(); // First server is unreachable options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + (FakeDNSServer.PORT + 1)); // Second server is the failed over server options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()); AddressResolver resolver = new AddressResolver((VertxImpl) vertx, options); CompletableFuture<InetAddress> result = new CompletableFuture<>(); resolver.resolveHostname("vertx.io", ar -> { if (ar.succeeded()) { result.complete(ar.result()); } else { result.completeExceptionally(ar.cause()); } }); String resolved = result.get(10, TimeUnit.SECONDS).getHostAddress(); assertEquals("127.0.0.1", resolved); } finally { server.stop(); } } }
options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort());
@Test public void testNetSearchDomain() throws Exception { Map<String, String> records = new HashMap<>(); records.put("host1.foo.com", "127.0.0.1"); dnsServer.testResolveA(records); vertx.close(); vertx = vertx(new VertxOptions().setAddressResolverOptions( new AddressResolverOptions(). setHostsValue(Buffer.buffer()). setNdots(1). addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false). addSearchDomain("foo.com") )); testNet("host1"); }
private void testDefaultDnsClient(Function<Vertx, DnsClient> clientProvider) throws Exception { final String ip = "10.0.0.1"; dnsServer.testLookup4(ip); VertxOptions vertxOptions = new VertxOptions(); InetSocketAddress fakeServerAddress = dnsServer.localAddress(); vertxOptions.getAddressResolverOptions().addServer(fakeServerAddress.getHostString() + ":" + fakeServerAddress.getPort()); Vertx vertxWithFakeDns = Vertx.vertx(vertxOptions); DnsClient dnsClient = clientProvider.apply(vertxWithFakeDns); dnsClient.lookup4("vertx.io", onSuccess(result -> { assertEquals(ip, result); testComplete(); })); await(); vertxWithFakeDns.close(); }
@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.testResolveA(records); 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); }
@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.testResolveA(records); 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); }
setHostsValue(Buffer.buffer()). setNdots(1). addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false). addSearchDomain("foo.com").