use of io.vertx.core.VertxOptions in project vert.x by eclipse.
the class HostnameResolutionTest method testSearchDomainWithNdots2.
@Test
public void testSearchDomainWithNdots2() throws Exception {
Map<String, String> records = new HashMap<>();
records.put("host1.sub.foo.com", "127.0.0.1");
records.put("host2.sub.foo.com", "127.0.0.2");
records.put("host2.sub", "127.0.0.3");
dnsServer.stop();
dnsServer = FakeDNSServer.testResolveA(records);
dnsServer.start();
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com").setNdots(2)));
CountDownLatch latch1 = new CountDownLatch(1);
vertx.resolveAddress("host1.sub", onSuccess(resolved -> {
assertEquals("127.0.0.1", resolved.getHostAddress());
latch1.countDown();
}));
awaitLatch(latch1);
// "host2.sub" is resolved with the foo.com search domain as ndots = 2
CountDownLatch latch2 = new CountDownLatch(1);
vertx.resolveAddress("host2.sub", onSuccess(resolved -> {
assertEquals("127.0.0.2", resolved.getHostAddress());
latch2.countDown();
}));
awaitLatch(latch2);
}
use of io.vertx.core.VertxOptions in project vert.x by eclipse.
the class HostnameResolutionTest method testNetSearchDomain.
@Test
public void testNetSearchDomain() throws Exception {
Map<String, String> records = new HashMap<>();
records.put("host1.foo.com", "127.0.0.1");
dnsServer.stop();
dnsServer = FakeDNSServer.testResolveA(records);
dnsServer.start();
vertx.close();
vertx = vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com")));
testNet("host1");
}
use of io.vertx.core.VertxOptions in project vert.x by eclipse.
the class HostnameResolutionTest method getOptions.
@Override
protected VertxOptions getOptions() {
VertxOptions options = super.getOptions();
options.getAddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort());
options.getAddressResolverOptions().setOptResourceEnabled(false);
return options;
}
use of io.vertx.core.VertxOptions in project vert.x by eclipse.
the class HostnameResolutionTest method testCaseInsensitiveResolveFromHosts.
@Test
public void testCaseInsensitiveResolveFromHosts() {
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsPath("hosts_config.txt")));
vertx.resolveAddress("SERVER.NET", onSuccess(addr -> {
assertEquals("192.168.0.15", addr.getHostAddress());
assertEquals("server.net", addr.getHostName());
testComplete();
}));
await();
}
use of io.vertx.core.VertxOptions in project vert.x by eclipse.
the class HostnameResolutionTest method testResolveMissingLocalhost.
@Test
public void testResolveMissingLocalhost() throws Exception {
InetAddress localhost = InetAddress.getByName("localhost");
// Set a dns resolver that won't resolve localhost
dnsServer.stop();
dnsServer = FakeDNSServer.testResolveASameServer("127.0.0.1");
dnsServer.start();
dnsServerAddress = (InetSocketAddress) dnsServer.getTransports()[0].getAcceptor().getLocalAddress();
// Test using the resolver API
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false)));
CompletableFuture<Void> test1 = new CompletableFuture<>();
vertx.resolveAddress("localhost", ar -> {
if (ar.succeeded()) {
InetAddress resolved = ar.result();
if (resolved.equals(localhost)) {
test1.complete(null);
} else {
test1.completeExceptionally(new AssertionError("Unexpected localhost value " + resolved));
}
} else {
test1.completeExceptionally(ar.cause());
}
});
test1.get(10, TimeUnit.SECONDS);
CompletableFuture<Void> test2 = new CompletableFuture<>();
vertx.resolveAddress("LOCALHOST", ar -> {
if (ar.succeeded()) {
InetAddress resolved = ar.result();
if (resolved.equals(localhost)) {
test2.complete(null);
} else {
test2.completeExceptionally(new AssertionError("Unexpected localhost value " + resolved));
}
} else {
test2.completeExceptionally(ar.cause());
}
});
test2.get(10, TimeUnit.SECONDS);
// Test using bootstrap
CompletableFuture<Void> test3 = new CompletableFuture<>();
NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost(localhost.getHostAddress()));
server.connectHandler(so -> {
so.write("hello").end();
});
server.listen(ar -> {
if (ar.succeeded()) {
test3.complete(null);
} else {
test3.completeExceptionally(ar.cause());
}
});
test3.get(10, TimeUnit.SECONDS);
CompletableFuture<Void> test4 = new CompletableFuture<>();
NetClient client = vertx.createNetClient();
client.connect(1234, "localhost", ar -> {
if (ar.succeeded()) {
test4.complete(null);
} else {
test4.completeExceptionally(ar.cause());
}
});
test4.get(10, TimeUnit.SECONDS);
}
Aggregations