/** * Returns a formatted error message for this {@link io.vertx.core.dns.DnsResponseCode}. */ @Override public String toString() { return name() + ": type " + errorCode + ", " + message; }
public AddressResolverOptions(JsonObject json) { this(); AddressResolverOptionsConverter.fromJson(json, this); }
public DnsClientOptions(JsonObject json) { DnsClientOptionsConverter.fromJson(json, this); }
@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()); }
@Test public void testInvalidHostsConfig() { try { AddressResolverOptions options = new AddressResolverOptions().setHostsPath("whatever.txt"); vertx(new VertxOptions().setAddressResolverOptions(options)); fail(); } catch (VertxException ignore) { } }
@Test public void testReverseLookupIpv4() throws Exception { String address = "10.0.0.1"; String ptr = "ptr.vertx.io"; dnsServer.testReverseLookup(ptr); DnsClient dns = prepareDns(); dns.reverseLookup(address, onSuccess(result -> { assertEquals(ptr, result); testComplete(); })); await(); }
@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 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 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(); }
@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 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 testDoNotLogActivity() throws Exception { TestLoggerFactory factory = testLogging(new DnsClientOptions().setLogActivity(false)); assertFalse(factory.hasName("io.netty.handler.logging.LoggingHandler")); }
@Test public void testLogActivity() throws Exception { TestLoggerFactory factory = testLogging(new DnsClientOptions().setLogActivity(true)); assertTrue(factory.hasName("io.netty.handler.logging.LoggingHandler")); }
private DnsClient prepareDns() throws Exception { return prepareDns(new DnsClientOptions().setQueryTimeout(15000)); }
public static void toJson(DnsClientOptions obj, java.util.Map<String, Object> json) { if (obj.getHost() != null) { json.put("host", obj.getHost()); } json.put("logActivity", obj.getLogActivity()); json.put("port", obj.getPort()); json.put("queryTimeout", obj.getQueryTimeout()); json.put("recursionDesired", obj.isRecursionDesired()); } }
@Test public void testDefaultDnsClientWithOptions() throws Exception { testDefaultDnsClient(vertx -> vertx.createDnsClient(new DnsClientOptions())); }
/** * Returns the {@link io.vertx.core.dns.DnsResponseCode} that corresponds with the given * {@code responseCode}. * * @param responseCode * the error code's id * @return corresponding {@link io.vertx.core.dns.DnsResponseCode} */ public static DnsResponseCode valueOf(int responseCode) { DnsResponseCode[] errors = DnsResponseCode.values(); for (DnsResponseCode e : errors) { if (e.errorCode == responseCode) { return e; } } return null; }
public JsonObject toJson() { JsonObject json = new JsonObject(); AddressResolverOptionsConverter.toJson(this, json); return json; } }
public JsonObject toJson() { JsonObject json = new JsonObject(); DnsClientOptionsConverter.toJson(this, json); return json; } }
@Test public void testReverseLookupIpv6() throws Exception { String ptr = "ptr.vertx.io"; dnsServer.testReverseLookup(ptr); DnsClient dns = prepareDns(); dns.reverseLookup("::1", onSuccess(result -> { assertEquals(ptr, result); testComplete(); })); await(); }