static void toJson(AddressResolverOptions obj, java.util.Map<String, Object> json) { json.put("cacheMaxTimeToLive", obj.getCacheMaxTimeToLive()); json.put("cacheMinTimeToLive", obj.getCacheMinTimeToLive()); json.put("cacheNegativeTimeToLive", obj.getCacheNegativeTimeToLive()); if (obj.getHostsPath() != null) { json.put("hostsPath", obj.getHostsPath()); } if (obj.getHostsValue() != null) { json.put("hostsValue", java.util.Base64.getEncoder().encodeToString(obj.getHostsValue().getBytes())); } json.put("maxQueries", obj.getMaxQueries()); json.put("ndots", obj.getNdots()); json.put("optResourceEnabled", obj.isOptResourceEnabled()); json.put("queryTimeout", obj.getQueryTimeout()); json.put("rdFlag", obj.getRdFlag()); json.put("rotateServers", obj.isRotateServers()); if (obj.getSearchDomains() != null) { JsonArray array = new JsonArray(); obj.getSearchDomains().forEach(item -> array.add(item)); json.put("searchDomains", array); } if (obj.getServers() != null) { JsonArray array = new JsonArray(); obj.getServers().forEach(item -> array.add(item)); json.put("servers", array); } } }
int maxTtl = intValue(options.getCacheMaxTimeToLive(), Integer.MAX_VALUE); int negativeTtl = intValue(options.getCacheNegativeTimeToLive(), 0); DnsCache resolveCache = new DefaultDnsCache(minTtl, maxTtl, negativeTtl);
@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()); }
static void toJson(AddressResolverOptions obj, java.util.Map<String, Object> json) { json.put("cacheMaxTimeToLive", obj.getCacheMaxTimeToLive()); json.put("cacheMinTimeToLive", obj.getCacheMinTimeToLive()); json.put("cacheNegativeTimeToLive", obj.getCacheNegativeTimeToLive()); if (obj.getHostsPath() != null) { json.put("hostsPath", obj.getHostsPath()); } if (obj.getHostsValue() != null) { json.put("hostsValue", java.util.Base64.getEncoder().encodeToString(obj.getHostsValue().getBytes())); } json.put("maxQueries", obj.getMaxQueries()); json.put("ndots", obj.getNdots()); json.put("optResourceEnabled", obj.isOptResourceEnabled()); json.put("queryTimeout", obj.getQueryTimeout()); json.put("rdFlag", obj.getRdFlag()); json.put("rotateServers", obj.isRotateServers()); if (obj.getSearchDomains() != null) { JsonArray array = new JsonArray(); obj.getSearchDomains().forEach(item -> array.add(item)); json.put("searchDomains", array); } if (obj.getServers() != null) { JsonArray array = new JsonArray(); obj.getServers().forEach(item -> array.add(item)); json.put("servers", array); } } }
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(servers, options.getServers()); assertEquals(minTTL, options.getCacheMinTimeToLive()); assertEquals(maxTTL, options.getCacheMaxTimeToLive()); assertEquals(negativeTTL, options.getCacheNegativeTimeToLive()); assertEquals(queryTimeout, options.getQueryTimeout()); assertEquals(servers, copy.getServers()); assertEquals(minTTL, copy.getCacheMinTimeToLive()); assertEquals(maxTTL, copy.getCacheMaxTimeToLive()); assertEquals(negativeTTL, copy.getCacheNegativeTimeToLive()); assertEquals(queryTimeout, copy.getQueryTimeout()); assertEquals(servers, jsonCopy.getServers()); assertEquals(minTTL, jsonCopy.getCacheMinTimeToLive()); assertEquals(maxTTL, jsonCopy.getCacheMaxTimeToLive()); assertEquals(negativeTTL, jsonCopy.getCacheNegativeTimeToLive()); assertEquals(queryTimeout, jsonCopy.getQueryTimeout());
int maxTtl = intValue(options.getCacheMaxTimeToLive(), Integer.MAX_VALUE); int negativeTtl = intValue(options.getCacheNegativeTimeToLive(), 0); DnsCache resolveCache = new DefaultDnsCache(minTtl, maxTtl, negativeTtl);
@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()); }
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(servers, options.getServers()); assertEquals(minTTL, options.getCacheMinTimeToLive()); assertEquals(maxTTL, options.getCacheMaxTimeToLive()); assertEquals(negativeTTL, options.getCacheNegativeTimeToLive()); assertEquals(queryTimeout, options.getQueryTimeout()); assertEquals(servers, copy.getServers()); assertEquals(minTTL, copy.getCacheMinTimeToLive()); assertEquals(maxTTL, copy.getCacheMaxTimeToLive()); assertEquals(negativeTTL, copy.getCacheNegativeTimeToLive()); assertEquals(queryTimeout, copy.getQueryTimeout()); assertEquals(servers, jsonCopy.getServers()); assertEquals(minTTL, jsonCopy.getCacheMinTimeToLive()); assertEquals(maxTTL, jsonCopy.getCacheMaxTimeToLive()); assertEquals(negativeTTL, jsonCopy.getCacheNegativeTimeToLive()); assertEquals(queryTimeout, jsonCopy.getQueryTimeout());