-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The DnsClient does not have a close method to release the underlying …
…networking resources. Add a close method to the client that closes the datagram channel, inflight queries are failed.
- Loading branch information
Showing
5 changed files
with
93 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
* Provides a way to asynchronously lookup information from DNS servers. | ||
* <p> | ||
* Please consult the documentation for more information on DNS clients. | ||
* <p> | ||
* The client is thread safe and can be used from any thread. | ||
* | ||
* @author <a href="mailto:[email protected]">Norman Maurer</a> | ||
*/ | ||
|
@@ -237,4 +239,15 @@ public interface DnsClient { | |
* Like {@link #reverseLookup(String, Handler)} but returns a {@code Future} of the asynchronous result | ||
*/ | ||
Future<@Nullable String> reverseLookup(String ipaddress); | ||
|
||
/** | ||
* Close the client. | ||
*/ | ||
void close(Handler<AsyncResult<Void>> handler); | ||
|
||
/** | ||
* Like {@link #close(Handler)} but returns a {@code Future} of the asynchronous result | ||
*/ | ||
Future<Void> close(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,33 +11,28 @@ | |
|
||
package io.vertx.core.dns; | ||
|
||
import static io.vertx.test.core.TestUtils.assertIllegalStateException; | ||
import static io.vertx.test.core.TestUtils.assertNullPointerException; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Function; | ||
|
||
import io.vertx.test.core.TestUtils; | ||
import io.vertx.test.core.VertxTestBase; | ||
import org.apache.directory.server.dns.messages.DnsMessage; | ||
import org.apache.directory.server.dns.store.RecordStore; | ||
import org.junit.Test; | ||
|
||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.DeploymentOptions; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.VertxException; | ||
import io.vertx.core.VertxOptions; | ||
import io.vertx.core.dns.DnsClient; | ||
import io.vertx.core.dns.DnsClientOptions; | ||
import io.vertx.core.dns.DnsException; | ||
import io.vertx.core.dns.DnsResponseCode; | ||
import io.vertx.core.dns.MxRecord; | ||
import io.vertx.core.dns.SrvRecord; | ||
import io.vertx.core.dns.impl.DnsClientImpl; | ||
import io.vertx.test.fakedns.FakeDNSServer; | ||
import io.vertx.test.netty.TestLoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Norman Maurer</a> | ||
* @author <a href="http://tfox.org">Tim Fox</a> | ||
|
@@ -445,6 +440,37 @@ public void testRecursionNotDesired() throws Exception { | |
await(); | ||
} | ||
|
||
@Test | ||
public void testClose() throws Exception { | ||
waitFor(2); | ||
String ip = "10.0.0.1"; | ||
RecordStore store = dnsServer.testResolveA(ip).store(); | ||
CountDownLatch latch1 = new CountDownLatch(1); | ||
CountDownLatch latch2 = new CountDownLatch(1); | ||
dnsServer.store(question -> { | ||
latch1.countDown(); | ||
try { | ||
latch2.await(10, TimeUnit.SECONDS); | ||
} catch (Exception e) { | ||
fail(e); | ||
} | ||
return store.getRecords(question); | ||
}); | ||
DnsClient dns = prepareDns(); | ||
dns | ||
.resolveA("vertx.io") | ||
.onComplete(onFailure(timeout -> { | ||
assertTrue(timeout.getMessage().contains("closed")); | ||
complete(); | ||
})); | ||
awaitLatch(latch1); | ||
dns.close().onComplete(onSuccess(v -> { | ||
complete(); | ||
latch2.countDown(); | ||
})); | ||
await(); | ||
} | ||
|
||
private DnsClient prepareDns() throws Exception { | ||
return prepareDns(new DnsClientOptions().setQueryTimeout(15000)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters