Add tests to verify caches are cleared when the resolver is closed. (#8186)

Motivation:

55fec94592 fixed a bug where we did not correctly clear all caches when the resolver was closed but did not add a testcase.

Modifications:

Add testcase.

Result:

More tests.
This commit is contained in:
Norman Maurer 2018-08-10 08:46:15 +02:00 committed by GitHub
parent dbc9ec1ab2
commit 56eb1e92cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,6 +82,7 @@ import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@ -1712,4 +1713,70 @@ public class DnsNameResolverTest {
resolver.close();
}
}
@Test(timeout = 2000L)
public void testCachesClearedOnClose() throws Exception {
final CountDownLatch resolveLatch = new CountDownLatch(1);
final CountDownLatch authoritativeLatch = new CountDownLatch(1);
DnsNameResolver resolver = newResolver().resolveCache(new DnsCache() {
@Override
public void clear() {
resolveLatch.countDown();
}
@Override
public boolean clear(String hostname) {
return false;
}
@Override
public List<? extends DnsCacheEntry> get(String hostname, DnsRecord[] additionals) {
return null;
}
@Override
public DnsCacheEntry cache(
String hostname, DnsRecord[] additionals, InetAddress address, long originalTtl, EventLoop loop) {
return null;
}
@Override
public DnsCacheEntry cache(
String hostname, DnsRecord[] additionals, Throwable cause, EventLoop loop) {
return null;
}
})
.authoritativeDnsServerCache(new DnsCache() {
@Override
public void clear() {
authoritativeLatch.countDown();
}
@Override
public boolean clear(String hostname) {
return false;
}
@Override
public List<? extends DnsCacheEntry> get(String hostname, DnsRecord[] additionals) {
return null;
}
@Override
public DnsCacheEntry cache(
String hostname, DnsRecord[] additionals, InetAddress address, long originalTtl, EventLoop loop) {
return null;
}
@Override
public DnsCacheEntry cache(String hostname, DnsRecord[] additionals, Throwable cause, EventLoop loop) {
return null;
}
}).build();
resolver.close();
resolveLatch.await();
authoritativeLatch.await();
}
}