@Test public void testNameServerCache() throws IOException, InterruptedException { final String overriddenIP = "12.34.12.34"; final TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() { @Override public Set<ResourceRecord> getRecords(QuestionRecord question) { switch (question.getRecordType()) { case A: Map<String, Object> attr = new HashMap<String, Object>(); attr.put(DnsAttribute.IP_ADDRESS.toLowerCase(Locale.US), overriddenIP); return Collections.<ResourceRecord>singleton( new TestDnsServer.TestResourceRecord( question.getDomainName(), question.getRecordType(), attr)); default: return null; } } }); dnsServer2.start(); try { final Set<String> overridenHostnames = new HashSet<String>(); for (String name : DOMAINS) { if (EXCLUSIONS_RESOLVE_A.contains(name)) { continue; } if (PlatformDependent.threadLocalRandom().nextBoolean()) { overridenHostnames.add(name); } } DnsNameResolver resolver = newResolver(false, new DnsServerAddressStreamProvider() { @Override public DnsServerAddressStream nameServerAddressStream(String hostname) { return overridenHostnames.contains(hostname) ? sequential(dnsServer2.localAddress()).stream() : null; } }).build(); try { final Map<String, InetAddress> resultA = testResolve0(resolver, EXCLUSIONS_RESOLVE_A, AAAA); for (Entry<String, InetAddress> resolvedEntry : resultA.entrySet()) { if (resolvedEntry.getValue().isLoopbackAddress()) { continue; } if (overridenHostnames.contains(resolvedEntry.getKey())) { assertEquals("failed to resolve " + resolvedEntry.getKey(), overriddenIP, resolvedEntry.getValue().getHostAddress()); } else { assertNotEquals("failed to resolve " + resolvedEntry.getKey(), overriddenIP, resolvedEntry.getValue().getHostAddress()); } } } finally { resolver.close(); } } finally { dnsServer2.stop(); } }
@Override public void close() { if (ch.isOpen()) { ch.close(); } }
DnsNameResolver extends InetNameResolver { @Override public void close() { if (ch.isOpen()) { ch.close(); } } }
DnsNameResolver extends InetNameResolver { @Override public void close() { if (ch.isOpen()) { ch.close(); } } DnsNameResolver(
            EventLoop eventLoop,
            ChannelFactory<? extends DatagramChannel> channelFactory,
            final DnsCache resolveCache,
            DnsCache authoritativeDnsServerCache,
            DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory,
            long queryTimeoutMillis,
            ResolvedAddressTypes resolvedAddressTypes,
            boolean recursionDesired,
            int maxQueriesPerResolve,
            boolean traceEnabled,
            int maxPayloadSize,
            boolean optResourceEnabled,
            HostsFileEntriesResolver hostsFileEntriesResolver,
            DnsServerAddressStreamProvider dnsServerAddressStreamProvider,
            String[] searchDomains,
            int ndots,
            boolean decodeIdn); }
DnsNameResolver extends InetNameResolver { @Override public void close() { if (ch.isOpen()) { ch.close(); } } DnsNameResolver(
            EventLoop eventLoop,
            ChannelFactory<? extends DatagramChannel> channelFactory,
            final DnsCache resolveCache,
            DnsCache authoritativeDnsServerCache,
            DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory,
            long queryTimeoutMillis,
            ResolvedAddressTypes resolvedAddressTypes,
            boolean recursionDesired,
            int maxQueriesPerResolve,
            boolean traceEnabled,
            int maxPayloadSize,
            boolean optResourceEnabled,
            HostsFileEntriesResolver hostsFileEntriesResolver,
            DnsServerAddressStreamProvider dnsServerAddressStreamProvider,
            String[] searchDomains,
            int ndots,
            boolean decodeIdn); DnsCache resolveCache(); DnsCache authoritativeDnsServerCache(); long queryTimeoutMillis(); ResolvedAddressTypes resolvedAddressTypes(); boolean isRecursionDesired(); int maxQueriesPerResolve(); int maxPayloadSize(); boolean isOptResourceEnabled(); HostsFileEntriesResolver hostsFileEntriesResolver(); @Override void close(); final Future<InetAddress> resolve(String inetHost, Iterable<DnsRecord> additionals); final Future<InetAddress> resolve(String inetHost, Iterable<DnsRecord> additionals,
                                             Promise<InetAddress> promise); final Future<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals); final Future<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals,
                                                Promise<List<InetAddress>> promise); final Future<List<DnsRecord>> resolveAll(DnsQuestion question); final Future<List<DnsRecord>> resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals); final Future<List<DnsRecord>> resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals,
                                                    Promise<List<DnsRecord>> promise); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(DnsQuestion question); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            DnsQuestion question, Iterable<DnsRecord> additionals); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question, Iterable<DnsRecord> additionals); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question,
            Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question,
            Iterable<DnsRecord> additionals,
            Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise); static boolean isTransportOrTimeoutError(Throwable cause); static boolean isTimeoutError(Throwable cause); }
DnsNameResolver extends InetNameResolver { @Override public void close() { if (ch.isOpen()) { ch.close(); } } DnsNameResolver(
            EventLoop eventLoop,
            ChannelFactory<? extends DatagramChannel> channelFactory,
            final DnsCache resolveCache,
            DnsCache authoritativeDnsServerCache,
            DnsQueryLifecycleObserverFactory dnsQueryLifecycleObserverFactory,
            long queryTimeoutMillis,
            ResolvedAddressTypes resolvedAddressTypes,
            boolean recursionDesired,
            int maxQueriesPerResolve,
            boolean traceEnabled,
            int maxPayloadSize,
            boolean optResourceEnabled,
            HostsFileEntriesResolver hostsFileEntriesResolver,
            DnsServerAddressStreamProvider dnsServerAddressStreamProvider,
            String[] searchDomains,
            int ndots,
            boolean decodeIdn); DnsCache resolveCache(); DnsCache authoritativeDnsServerCache(); long queryTimeoutMillis(); ResolvedAddressTypes resolvedAddressTypes(); boolean isRecursionDesired(); int maxQueriesPerResolve(); int maxPayloadSize(); boolean isOptResourceEnabled(); HostsFileEntriesResolver hostsFileEntriesResolver(); @Override void close(); final Future<InetAddress> resolve(String inetHost, Iterable<DnsRecord> additionals); final Future<InetAddress> resolve(String inetHost, Iterable<DnsRecord> additionals,
                                             Promise<InetAddress> promise); final Future<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals); final Future<List<InetAddress>> resolveAll(String inetHost, Iterable<DnsRecord> additionals,
                                                Promise<List<InetAddress>> promise); final Future<List<DnsRecord>> resolveAll(DnsQuestion question); final Future<List<DnsRecord>> resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals); final Future<List<DnsRecord>> resolveAll(DnsQuestion question, Iterable<DnsRecord> additionals,
                                                    Promise<List<DnsRecord>> promise); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(DnsQuestion question); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            DnsQuestion question, Iterable<DnsRecord> additionals); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            DnsQuestion question, Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question, Iterable<DnsRecord> additionals); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question,
            Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise); Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> query(
            InetSocketAddress nameServerAddr, DnsQuestion question,
            Iterable<DnsRecord> additionals,
            Promise<AddressedEnvelope<? extends DnsResponse, InetSocketAddress>> promise); static boolean isTransportOrTimeoutError(Throwable cause); static boolean isTimeoutError(Throwable cause);  }