Repository: netty/netty
File: resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverTest.java (Java)

Code before:
        } finally {
            resolver.close();
        }
    }

    @Test
    public void testResolveACachedWithDotSearchDomain() throws Exception {
        final TestDnsCache cache = new TestDnsCache(new DefaultDnsCache());
        TestDnsServer server = new TestDnsServer(Collections.singleton("test.netty.io"));
        server.start();
        DnsNameResolver resolver = newResolver(ResolvedAddressTypes.IPV4_ONLY)
                .searchDomains(Collections.singletonList("netty.io"))
                .nameServerProvider(new SingletonDnsServerAddressStreamProvider(server.localAddress()))
                .resolveCache(cache).build();
        try {
            resolver.resolve("test").syncUninterruptibly();

            assertNull(cache.cacheHits.get("test.netty.io"));

            List<? extends DnsCacheEntry> cached = cache.cache.get("test.netty.io", null);
            List<? extends DnsCacheEntry> cached2 = cache.cache.get("test.netty.io.", null);
            assertEquals(1, cached.size());
            assertEquals(cached, cached2);

            DefaultPromise<List<InetAddress>> promise =
                    new DefaultPromise<List<InetAddress>>(GlobalEventExecutor.INSTANCE);
            boolean isCached = DnsNameResolver.doResolveAllCached("test", null, promise, cache,
                    resolver.searchDomains(), resolver.ndots(), resolver.resolvedInternetProtocolFamiliesUnsafe());
            assertTrue(isCached);
            List<? extends DnsCacheEntry> entries = cache.cacheHits.get("test.netty.io");
            assertFalse(entries.isEmpty());
        } finally {
            resolver.close();
            server.stop();
        }
    }

    @Test
    public void testChannelFactoryException() {
        final IllegalStateException exception = new IllegalStateException();
        try {
            newResolver().channelFactory(new ChannelFactory<DatagramChannel>() {
                @Override
                public DatagramChannel newChannel() {
                    throw exception;
                }
            }).build();
            fail();
        } catch (Exception e) {
            assertSame(exception, e);
        }

Review comment (suggestion):
```suggestion
            Promise<List<InetAddress>> promise = GlobalEventExecutor.INSTANCE.newPromise();
```

Code after:
        }
    }

    @Test
    public void testResolveACachedWithDotSearchDomain() throws Exception {
        final TestDnsCache cache = new TestDnsCache(new DefaultDnsCache());
        TestDnsServer server = new TestDnsServer(Collections.singleton("test.netty.io"));
        server.start();
        DnsNameResolver resolver = newResolver(ResolvedAddressTypes.IPV4_ONLY)
                .searchDomains(Collections.singletonList("netty.io"))
                .nameServerProvider(new SingletonDnsServerAddressStreamProvider(server.localAddress()))
                .resolveCache(cache).build();
        try {
            resolver.resolve("test").syncUninterruptibly();

            assertNull(cache.cacheHits.get("test.netty.io"));

            List<? extends DnsCacheEntry> cached = cache.cache.get("test.netty.io", null);
            List<? extends DnsCacheEntry> cached2 = cache.cache.get("test.netty.io.", null);
            assertEquals(1, cached.size());
            assertEquals(cached, cached2);

            resolver.resolve("test").syncUninterruptibly();
            List<? extends DnsCacheEntry> entries = cache.cacheHits.get("test.netty.io");
            assertFalse(entries.isEmpty());
        } finally {
            resolver.close();
            server.stop();
        }
    }

    @Test
    public void testChannelFactoryException() {
        final IllegalStateException exception = new IllegalStateException();
        try {
            newResolver().channelFactory(new ChannelFactory<DatagramChannel>() {
                @Override
                public DatagramChannel newChannel() {
                    throw exception;
                }
            }).build();
            fail();
        } catch (Exception e) {
            assertSame(exception, e);
        }
    }

    @Test
    public void testCNameCached() throws Exception {
        final Map<String, String> cache = new ConcurrentHashMap<String, String>();
        final AtomicInteger cnameQueries = new AtomicInteger();