@Test
public void testNegativeTtl() throws Exception {

    final DnsNameResolver resolver = newResolver().negativeTtl(10).build();
    try {
        resolveNonExistentDomain(resolver);
        final int size = 10000;
        final List<UnknownHostException> exceptions = new ArrayList<UnknownHostException>();
        // If negative cache works, this thread should be done really quickly.
        final Thread negativeLookupThread = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < size; i++) {
                    exceptions.add(resolveNonExistentDomain(resolver));
                    if (isInterrupted()) {
                        break;
                    }
                }
            }
        };
        negativeLookupThread.start();
        negativeLookupThread.join(DEFAULT_TEST_TIMEOUT_MS);
        if (negativeLookupThread.isAlive()) {
            negativeLookupThread.interrupt();
            fail("Cached negative lookups did not finish quickly.");
        }
        assertThat(exceptions, hasSize(size));
    } finally {
        resolver.close();
    }
}