RefreshingAddressResolver extends AbstractAddressResolver<InetSocketAddress> { @Override public void close() { resolverClosed = true; resolver.close(); } RefreshingAddressResolver(EventLoop eventLoop,
                              ConcurrentMap<String, CompletableFuture<CacheEntry>> cache,
                              DefaultDnsNameResolver resolver, List<DnsRecordType> dnsRecordTypes,
                              int minTtl, int maxTtl, int negativeTtl, Backoff refreshBackoff); @Override void close();  }
@Test void cacheClearWhenClosed() throws Exception { try (TestDnsServer server = new TestDnsServer(ImmutableMap.of( new DefaultDnsQuestion("foo.com.", A), new DefaultDnsResponse(0).addRecord(ANSWER, newAddressRecord("foo.com.", "1.1.1.1")))) ) { final EventLoop eventLoop = eventLoopExtension.get(); final RefreshingAddressResolverGroup group = builder(server).build(eventLoop); final AddressResolver<InetSocketAddress> resolver = group.getResolver(eventLoop); final Future<InetSocketAddress> foo = resolver.resolve( InetSocketAddress.createUnresolved("foo.com", 36462)); await().untilAsserted(() -> assertThat(foo.isSuccess()).isTrue()); assertThat(foo.getNow().getAddress().getHostAddress()).isEqualTo("1.1.1.1"); final ConcurrentMap<String, CompletableFuture<CacheEntry>> cache = group.cache(); assertThat(cache.size()).isEqualTo(1); final CacheEntry cacheEntry = cache.get("foo.com").join(); group.close(); await().until(() -> { final ScheduledFuture<?> future = cacheEntry.refreshFuture; return future != null && future.isCancelled(); }); assertThat(cache).isEmpty(); } }