use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HostnameResolutionTest method testResolveFromBuffer.
@Test
public void testResolveFromBuffer() {
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsValue(Buffer.buffer("192.168.0.15 server.net"))));
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.impl.VertxInternal in project vert.x by eclipse.
the class HostnameResolutionTest method testSearchDomain.
@Test
public void testSearchDomain() throws Exception {
String addr_host1_foo_com = "127.0.0.1";
String addr_host1 = "127.0.0.2";
String addr_host3 = "127.0.0.3";
String addr_host4_sub_foo_com = "127.0.0.4";
String addr_host5_sub_foo_com = "127.0.0.5";
String addr_host5_sub = "127.0.0.6";
String addr_host6_sub_sub_foo_com = "127.0.0.7";
String addr_host7_sub_sub_foo_com = "127.0.0.8";
String addr_host7_sub_sub = "127.0.0.9";
Map<String, String> records = new HashMap<>();
records.put("host1.foo.com", addr_host1_foo_com);
records.put("host1", addr_host1);
records.put("host3", addr_host3);
records.put("host4.sub.foo.com", addr_host4_sub_foo_com);
records.put("host5.sub.foo.com", addr_host5_sub_foo_com);
records.put("host5.sub", addr_host5_sub);
records.put("host6.sub.sub.foo.com", addr_host6_sub_sub_foo_com);
records.put("host7.sub.sub.foo.com", addr_host7_sub_sub_foo_com);
records.put("host7.sub.sub", addr_host7_sub_sub);
dnsServer.testResolveA(records::get);
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).setNdots(2).addSearchDomain("foo.com")));
// host1 resolves host1.foo.com with foo.com search domain
CountDownLatch latch1 = new CountDownLatch(1);
vertx.resolveAddress("host1", onSuccess(resolved -> {
assertEquals(addr_host1_foo_com, resolved.getHostAddress());
latch1.countDown();
}));
awaitLatch(latch1);
// "host1." absolute query
CountDownLatch latch2 = new CountDownLatch(1);
vertx.resolveAddress("host1.", onSuccess(resolved -> {
assertEquals(addr_host1, resolved.getHostAddress());
latch2.countDown();
}));
awaitLatch(latch2);
// "host2" not resolved
CountDownLatch latch3 = new CountDownLatch(1);
vertx.resolveAddress("host2", onFailure(cause -> {
assertTrue(cause instanceof UnknownHostException);
latch3.countDown();
}));
awaitLatch(latch3);
// "host3" resolves to addr_host3 as fallback
CountDownLatch latch4 = new CountDownLatch(1);
vertx.resolveAddress("host3", onSuccess(cause -> {
assertEquals(addr_host3, cause.getHostAddress());
latch4.countDown();
}));
awaitLatch(latch4);
// "host3." does not contain a dot but is absolute
CountDownLatch latch5 = new CountDownLatch(1);
vertx.resolveAddress("host3.", onSuccess(resolved -> {
assertEquals(addr_host3, resolved.getHostAddress());
latch5.countDown();
}));
awaitLatch(latch5);
// "host4.sub" contains a dot but not resolved then resolved to "host4.sub.foo.com" with "foo.com" search domain
CountDownLatch latch6 = new CountDownLatch(1);
vertx.resolveAddress("host4.sub", onSuccess(resolved -> {
assertEquals(addr_host4_sub_foo_com, resolved.getHostAddress());
latch6.countDown();
}));
awaitLatch(latch6);
// "host5.sub" contains one dots and is resolved via search domain to "host5.sub.foo.com" and not to "host5.sub"
CountDownLatch latch7 = new CountDownLatch(1);
vertx.resolveAddress("host5.sub", onSuccess(resolved -> {
assertEquals(addr_host5_sub_foo_com, resolved.getHostAddress());
latch7.countDown();
}));
awaitLatch(latch7);
// "host6.sub.sub" contains two dots and is resolved to "host6.sub.sub.foo.com" as fallback
CountDownLatch latch8 = new CountDownLatch(1);
vertx.resolveAddress("host6.sub.sub", onSuccess(resolved -> {
assertEquals(addr_host6_sub_sub_foo_com, resolved.getHostAddress());
latch8.countDown();
}));
awaitLatch(latch8);
// "host6.sub.sub" contains two dots and is resolved to "host6.sub.sub" and not to "host6.sub.sub.foo.com"
CountDownLatch latch9 = new CountDownLatch(1);
vertx.resolveAddress("host7.sub.sub", onSuccess(resolved -> {
assertEquals(addr_host7_sub_sub, resolved.getHostAddress());
latch9.countDown();
}));
awaitLatch(latch9);
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HostnameResolutionTest method testMultipleSearchDomain.
@Test
public void testMultipleSearchDomain() throws Exception {
Map<String, String> records = new HashMap<>();
records.put("host1.foo.com", "127.0.0.1");
records.put("host2.bar.com", "127.0.0.2");
records.put("host3.bar.com", "127.0.0.3");
records.put("host3.foo.com", "127.0.0.4");
dnsServer.testResolveA(records);
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsValue(Buffer.buffer()).setNdots(1).addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com").addSearchDomain("bar.com")));
// "host1" resolves via the "foo.com" search path
CountDownLatch latch1 = new CountDownLatch(1);
vertx.resolveAddress("host1", onSuccess(resolved -> {
assertEquals("127.0.0.1", resolved.getHostAddress());
latch1.countDown();
}));
awaitLatch(latch1);
// "host2" resolves via the "bar.com" search path
CountDownLatch latch2 = new CountDownLatch(1);
vertx.resolveAddress("host2", onSuccess(resolved -> {
assertEquals("127.0.0.2", resolved.getHostAddress());
latch2.countDown();
}));
awaitLatch(latch2);
// "host3" resolves via the "foo.com" search path as it is the first one
CountDownLatch latch3 = new CountDownLatch(1);
vertx.resolveAddress("host3", onSuccess(resolved -> {
assertEquals("127.0.0.4", resolved.getHostAddress());
latch3.countDown();
}));
awaitLatch(latch3);
// "host4" does not resolve
vertx.resolveAddress("host4", onFailure(cause -> {
assertTrue(cause instanceof UnknownHostException);
testComplete();
}));
await();
}
use of io.vertx.core.impl.VertxInternal 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.impl.VertxInternal in project vert.x by eclipse.
the class PemTrustOptions method getHelper.
KeyStoreHelper getHelper(Vertx vertx) throws Exception {
if (helper == null) {
Stream<Buffer> certValues = certPaths.stream().map(path -> ((VertxInternal) vertx).resolveFile(path).getAbsolutePath()).map(vertx.fileSystem()::readFileBlocking);
certValues = Stream.concat(certValues, this.certValues.stream());
helper = new KeyStoreHelper(KeyStoreHelper.loadCA(certValues), null, null);
}
return helper;
}
Aggregations