@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.testResolveA(records); 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); }
@Test public void testSearchDomainWithNdots0() throws Exception { Map<String, String> records = new HashMap<>(); records.put("host1", "127.0.0.2"); records.put("host1.foo.com", "127.0.0.3"); dnsServer.testResolveA(records); VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions( new AddressResolverOptions(). addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false). addSearchDomain("foo.com"). setNdots(0) )); // "host1" resolves directly as ndots = 0 CountDownLatch latch1 = new CountDownLatch(1); vertx.resolveAddress("host1", onSuccess(resolved -> { assertEquals("127.0.0.2", resolved.getHostAddress()); latch1.countDown(); })); awaitLatch(latch1); // "host1.foo.com" resolves to host1.foo.com CountDownLatch latch2 = new CountDownLatch(1); vertx.resolveAddress("host1.foo.com", onSuccess(resolved -> { assertEquals("127.0.0.3", resolved.getHostAddress()); latch2.countDown(); })); awaitLatch(latch2); }
try { server.listen(1234, "localhost", onSuccess(v -> listenLatch.countDown())); awaitLatch(listenLatch); AtomicReference<Thread> channelThread = new AtomicReference<>(); CountDownLatch connectLatch = new CountDownLatch(1); awaitLatch(connectLatch); channelFut.addListener(v -> { assertTrue(v.isSuccess());
latch1.countDown(); })); awaitLatch(latch1); latch2.countDown(); })); awaitLatch(latch2); latch3.countDown(); })); awaitLatch(latch3); latch4.countDown(); })); awaitLatch(latch4); latch5.countDown(); })); awaitLatch(latch5); latch6.countDown(); })); awaitLatch(latch6); latch7.countDown(); })); awaitLatch(latch7); latch8.countDown();
@Test public void testHttp() throws Exception { HttpClient client = vertx.createHttpClient(); HttpServer server = vertx.createHttpServer().requestHandler(req -> { req.response().end("foo"); }); try { CountDownLatch listenLatch = new CountDownLatch(1); server.listen(8080, "vertx.io", onSuccess(s -> { listenLatch.countDown(); })); awaitLatch(listenLatch); client.getNow(8080, "vertx.io", "/somepath", onSuccess(resp -> { Buffer buffer = Buffer.buffer(); resp.handler(buffer::appendBuffer); resp.endHandler(v -> { assertEquals(Buffer.buffer("foo"), buffer); testComplete(); }); })); await(); } finally { client.close(); server.close(); } }
latch1.countDown(); })); awaitLatch(latch1); latch2.countDown(); })); awaitLatch(latch2); latch3.countDown(); })); awaitLatch(latch3);
private void testNet(String hostname) throws Exception { NetClient client = vertx.createNetClient(); NetServer server = vertx.createNetServer().connectHandler(so -> { so.handler(buff -> { so.write(buff); so.close(); }); }); try { CountDownLatch listenLatch = new CountDownLatch(1); server.listen(1234, hostname, onSuccess(s -> { listenLatch.countDown(); })); awaitLatch(listenLatch); client.connect(1234, hostname, onSuccess(so -> { Buffer buffer = Buffer.buffer(); so.handler(buffer::appendBuffer); so.closeHandler(v -> { assertEquals(Buffer.buffer("foo"), buffer); testComplete(); }); so.write(Buffer.buffer("foo")); })); await(); } finally { client.close(); server.close(); } }
@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.testResolveA(records); 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); }
@Test public void testSearchDomainWithNdots0() throws Exception { Map<String, String> records = new HashMap<>(); records.put("host1", "127.0.0.2"); records.put("host1.foo.com", "127.0.0.3"); dnsServer.testResolveA(records); VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions( new AddressResolverOptions(). addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()). setOptResourceEnabled(false). addSearchDomain("foo.com"). setNdots(0) )); // "host1" resolves directly as ndots = 0 CountDownLatch latch1 = new CountDownLatch(1); vertx.resolveAddress("host1", onSuccess(resolved -> { assertEquals("127.0.0.2", resolved.getHostAddress()); latch1.countDown(); })); awaitLatch(latch1); // "host1.foo.com" resolves to host1.foo.com CountDownLatch latch2 = new CountDownLatch(1); vertx.resolveAddress("host1.foo.com", onSuccess(resolved -> { assertEquals("127.0.0.3", resolved.getHostAddress()); latch2.countDown(); })); awaitLatch(latch2); }
try { server.listen(1234, "localhost", onSuccess(v -> listenLatch.countDown())); awaitLatch(listenLatch); AtomicReference<Thread> channelThread = new AtomicReference<>(); CountDownLatch connectLatch = new CountDownLatch(1); awaitLatch(connectLatch); channelFut.addListener(v -> { assertTrue(v.isSuccess());
@Test public void testHttp() throws Exception { HttpClient client = vertx.createHttpClient(); HttpServer server = vertx.createHttpServer().requestHandler(req -> { req.response().end("foo"); }); try { CountDownLatch listenLatch = new CountDownLatch(1); server.listen(8080, "vertx.io", onSuccess(s -> { listenLatch.countDown(); })); awaitLatch(listenLatch); client.getNow(8080, "vertx.io", "/somepath", resp -> { Buffer buffer = Buffer.buffer(); resp.handler(buffer::appendBuffer); resp.endHandler(v -> { assertEquals(Buffer.buffer("foo"), buffer); testComplete(); }); }); await(); } finally { client.close(); server.close(); } }
latch1.countDown(); })); awaitLatch(latch1); latch2.countDown(); })); awaitLatch(latch2); latch3.countDown(); })); awaitLatch(latch3); latch4.countDown(); })); awaitLatch(latch4); latch5.countDown(); })); awaitLatch(latch5); latch6.countDown(); })); awaitLatch(latch6); latch7.countDown(); })); awaitLatch(latch7); latch8.countDown();
latch1.countDown(); })); awaitLatch(latch1); latch2.countDown(); })); awaitLatch(latch2); latch3.countDown(); })); awaitLatch(latch3);
private void testNet(String hostname) throws Exception { NetClient client = vertx.createNetClient(); NetServer server = vertx.createNetServer().connectHandler(so -> { so.handler(buff -> { so.write(buff); so.close(); }); }); try { CountDownLatch listenLatch = new CountDownLatch(1); server.listen(1234, hostname, onSuccess(s -> { listenLatch.countDown(); })); awaitLatch(listenLatch); client.connect(1234, hostname, onSuccess(so -> { Buffer buffer = Buffer.buffer(); so.handler(buffer::appendBuffer); so.closeHandler(v -> { assertEquals(Buffer.buffer("foo"), buffer); testComplete(); }); so.write(Buffer.buffer("foo")); })); await(); } finally { client.close(); server.close(); } }