@Test public void testIllegalArguments() throws Exception { dnsServer.testResolveAAAA("::1"); DnsClient dns = prepareDns(); assertNullPointerException(() -> dns.lookup(null, ar -> {})); assertNullPointerException(() -> dns.lookup4(null, ar -> {})); assertNullPointerException(() -> dns.lookup6(null, ar -> {})); assertNullPointerException(() -> dns.resolveA(null, ar -> {})); assertNullPointerException(() -> dns.resolveAAAA(null, ar -> {})); assertNullPointerException(() -> dns.resolveCNAME(null, ar -> {})); assertNullPointerException(() -> dns.resolveMX(null, ar -> {})); assertNullPointerException(() -> dns.resolveTXT(null, ar -> {})); assertNullPointerException(() -> dns.resolvePTR(null, ar -> {})); assertNullPointerException(() -> dns.resolveNS(null, ar -> {})); assertNullPointerException(() -> dns.resolveSRV(null, ar -> {})); }
@Test public void testResolveSRV() throws Exception { final int priority = 10; final int weight = 1; final int port = 80; final String target = "vertx.io"; dnsServer.testResolveSRV(priority, weight, port, target); DnsClient dns = prepareDns(); dns.resolveSRV("vertx.io", ar -> { List<SrvRecord> result = ar.result(); assertNotNull(result); assertFalse(result.isEmpty()); assertEquals(1, result.size()); SrvRecord record = result.get(0); assertEquals(priority, record.priority()); assertEquals(weight, record.weight()); assertEquals(port, record.port()); assertEquals(target, record.target()); testComplete(); }); await(); }
@Test public void testLookupNonExisting() throws Exception { dnsServer.testLookupNonExisting(); DnsClient dns = prepareDns(); dns.lookup("gfegjegjf.sg1", ar -> { DnsException cause = (DnsException)ar.cause(); assertEquals(DnsResponseCode.NXDOMAIN, cause.code()); testComplete(); }); await(); }
@Test public void testResolveA() throws Exception { final String ip = "10.0.0.1"; dnsServer.testResolveA(ip); DnsClient dns = prepareDns(); dns.resolveA("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(ip, result.get(0)); ((DnsClientImpl) dns).inProgressQueries(num -> { assertEquals(0, (int)num); testComplete(); }); })); await(); }
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 testLookup6() throws Exception { dnsServer.testLookup6(); DnsClient dns = prepareDns(); dns.lookup6("vertx.io", onSuccess(result -> { assertEquals("0:0:0:0:0:0:0:1", result); testComplete(); })); await(); }
@Test public void testResolveAAAA() throws Exception { dnsServer.testResolveAAAA("::1"); DnsClient dns = prepareDns(); dns.resolveAAAA("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals("0:0:0:0:0:0:0:1", result.get(0)); testComplete(); })); await(); }
@Test public void testResolvePTR() throws Exception { final String ptr = "ptr.vertx.io"; dnsServer.testResolvePTR(ptr); DnsClient dns = prepareDns(); dns.resolvePTR("10.0.0.1.in-addr.arpa", onSuccess(result -> { assertEquals(ptr, result); testComplete(); })); await(); }
@Test public void testResolveNS() throws Exception { final String ns = "ns.vertx.io"; dnsServer.testResolveNS(ns); DnsClient dns = prepareDns(); dns.resolveNS("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(ns, result.get(0)); testComplete(); })); await(); }
@Test public void testResolveCNAME() throws Exception { final String cname = "cname.vertx.io"; dnsServer.testResolveCNAME(cname); DnsClient dns = prepareDns(); dns.resolveCNAME("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); String record = result.get(0); assertFalse(record.isEmpty()); assertEquals(cname, record); testComplete(); })); await(); }
@Test public void testResolveMX() throws Exception { final String mxRecord = "mail.vertx.io"; final int prio = 10; dnsServer.testResolveMX(prio, mxRecord); DnsClient dns = prepareDns(); dns.resolveMX("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); MxRecord record = result.get(0); assertEquals(prio, record.priority()); assertEquals(record.name(), mxRecord); testComplete(); })); await(); }
private void attemptRecover(final Callback<List<EndpointDefinition>> callback, final String serviceURL, final Throwable error) { final DnsClient dnsClient2 = dnsClientProvider.getIfErrors(); dnsClient2.resolveSRV(serviceURL, event -> { if (event.succeeded()) { if (debug) logger.debug("loadServiceEndpointsByDNSService FAIL OVER SUCCESS serviceURL={} ", serviceURL); callback.resolve(convertEndpoints(event.result())); } else { logger.info("loadServiceEndpointsByDNSService FAIL OVER FAILURE " + serviceURL, event.cause()); //Send the first failure callback.onError(error); } }); }
@Test public void testLookup() throws Exception { String ip = "10.0.0.1"; dnsServer.testLookup(ip); DnsClient dns = prepareDns(); dns.lookup("vertx.io", onSuccess(result -> { assertEquals(ip, result); testComplete(); })); await(); }
@Test public void testResolveAIpV6() throws Exception { final String ip = "10.0.0.1"; dnsServer.testResolveA(ip).ipAddress("::1"); // force the fake dns server to Ipv6 DnsClient dns = prepareDns(); dns.resolveA("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(ip, result.get(0)); ((DnsClientImpl) dns).inProgressQueries(num -> { assertEquals(0, (int)num); testComplete(); }); })); await(); }
@Test public void testLookup4CNAME() throws Exception { final String cname = "cname.vertx.io"; final String ip = "10.0.0.1"; dnsServer.testLookup4CNAME(cname, ip); DnsClient dns = prepareDns(); dns.lookup4("vertx.io", onSuccess(result -> { assertEquals(ip, result); testComplete(); })); await(); }
/** * Try to lookup the AAAA (ipv6) record for the given name. The first found will be used. * @param name the name to resolve * @param handler the to notify with the . The handler will get notified with the resolved {@link java.net.Inet6Address} if a record was found. If non was found it will get notifed with <code>null</code>. If an error accours it will get failed. * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.dns.DnsClient lookup6(String name, Handler<AsyncResult<String>> handler) { delegate.lookup6(name, handler); return this; }
/** * Try to resolve all AAAA (ipv6) records for the given name. * @param name the name to resolve * @param handler the {@link io.vertx.core.Handler} to notify with the {@link io.vertx.core.AsyncResult}. The handler will get notified with a {@link java.util.List} that contains all the resolved {@link java.net.Inet6Address}es. If none was found an empty {@link java.util.List} will be used. If an error accours it will get failed. * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.dns.DnsClient resolveAAAA(String name, Handler<AsyncResult<List<String>>> handler) { delegate.resolveAAAA(name, handler); return this; }
/** * Try to resolve the PTR record for the given name. * @param name the name to resolve the PTR for * @param handler the to notify with the . The handler will get notified with the resolved {@link java.lang.String} if a record was found. If none was found it will get notified with <code>null</code>. If an error accours it will get failed. * @return a reference to this, so the API can be used fluently. */ public io.vertx.rxjava.core.dns.DnsClient resolvePTR(String name, Handler<AsyncResult<String>> handler) { delegate.resolvePTR(name, handler); return this; }
/** * Try to resolve the NS records for the given name. * @param name the name for which the NS records should be resolved * @param handler the to notify with the . The handler will get notified with a List that contains all resolved {@link java.lang.String}s. If none was found it will get notified with an empty {@link java.util.List}. If an error accours it will get failed. * @return a reference to this, so the API can be used fluently. */ public io.vertx.rxjava.core.dns.DnsClient resolveNS(String name, Handler<AsyncResult<List<String>>> handler) { delegate.resolveNS(name, handler); return this; }
/** * Try to resolve the CNAME record for the given name. * @param name the name to resolve the CNAME for * @param handler the to notify with the . The handler will get notified with the resolved {@link java.lang.String} if a record was found. If none was found it will get notified with <code>null</code>. If an error accours it will get failed. * @return a reference to this, so the API can be used fluently. */ public io.vertx.rxjava.core.dns.DnsClient resolveCNAME(String name, Handler<AsyncResult<List<String>>> handler) { delegate.resolveCNAME(name, handler); return this; }