protected void awaitClose(NetServer server) throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); server.close((asyncResult) -> { latch.countDown(); }); awaitLatch(latch); }
protected void startServer(SocketAddress remoteAddress, Context context, NetServer server) throws Exception { CountDownLatch latch = new CountDownLatch(1); context.runOnContext(v -> { server.listen(remoteAddress, onSuccess(s -> latch.countDown())); }); awaitLatch(latch); }
awaitLatch(latch); for (int i = 0; i < numThreads; i++) { threads[i].join();
listenLatch.countDown(); })); awaitLatch(listenLatch); awaitLatch(clientLatch); awaitLatch(serverLatch);
@Test public void testSharedServersRoundRobinButFirstStartAndStopServer() throws Exception { // Start and stop a server on the same port/host before hand to make sure it doesn't interact server.close(); CountDownLatch latch = new CountDownLatch(1); server = vertx.createNetServer(); server.connectHandler(sock -> { fail("Should not connect"); }).listen(testAddress, ar -> { if (ar.succeeded()) { latch.countDown(); } else { fail("Failed to bind server"); } }); awaitLatch(latch); CountDownLatch closeLatch = new CountDownLatch(1); server.close(ar -> { assertTrue(ar.succeeded()); closeLatch.countDown(); }); assertTrue(closeLatch.await(10, TimeUnit.SECONDS)); testSharedServersRoundRobin(); }
awaitLatch(latchClient); awaitLatch(latchConns);
@Test public void testClosingVertxCloseSharedServers() throws Exception { int numServers = 2; Vertx vertx = Vertx.vertx(getOptions()); List<NetServerImpl> servers = new ArrayList<>(); for (int i = 0;i < numServers;i++) { NetServer server = vertx.createNetServer().connectHandler(so -> { fail(); }); startServer(server); servers.add((NetServerImpl) server); } CountDownLatch latch = new CountDownLatch(1); vertx.close(onSuccess(v -> { latch.countDown(); })); awaitLatch(latch); servers.forEach(server -> { assertTrue(server.isClosed()); }); }
server.connectHandler(so -> { try { awaitLatch(latch2); } catch (InterruptedException e) { fail(e.getMessage()); latch1.countDown(); }); awaitLatch(latch1); workers.get(0).runOnContext(v -> { NetClient client = vertx.createNetClient();
@Test public void testSharedServersRoundRobinWithOtherServerRunningOnDifferentPort() throws Exception { CountDownLatch latch = new CountDownLatch(1); // Have a server running on a different port to make sure it doesn't interact server.close(); server = vertx.createNetServer(new NetServerOptions().setPort(4321)); server.connectHandler(sock -> { fail("Should not connect"); }).listen(ar2 -> { if (ar2.succeeded()) { latch.countDown(); } else { fail("Failed to bind server"); } }); awaitLatch(latch); testSharedServersRoundRobin(); }
awaitLatch(latch1); NetClient client = vertx.createNetClient(); client.connect(testAddress, ar -> {
}); try { awaitLatch(latch); } catch (InterruptedException e) { fail(e);
latch.countDown(); })); awaitLatch(latch); client.connect(1234, "localhost", onSuccess(so -> { NetSocketInternal soInt = (NetSocketInternal) so;
protected void awaitClose(NetServer server) throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); server.close((asyncResult) -> { latch.countDown(); }); awaitLatch(latch); }
protected void startServer(SocketAddress remoteAddress, Context context, NetServer server) throws Exception { CountDownLatch latch = new CountDownLatch(1); context.runOnContext(v -> { server.listen(remoteAddress, onSuccess(s -> latch.countDown())); }); awaitLatch(latch); }
awaitLatch(latch); for (int i = 0; i < numThreads; i++) { threads[i].join();
@Test public void testClosingVertxCloseSharedServers() throws Exception { int numServers = 2; Vertx vertx = Vertx.vertx(getOptions()); List<NetServerImpl> servers = new ArrayList<>(); for (int i = 0;i < numServers;i++) { NetServer server = vertx.createNetServer().connectHandler(so -> { fail(); }); startServer(server); servers.add((NetServerImpl) server); } CountDownLatch latch = new CountDownLatch(1); vertx.close(onSuccess(v -> { latch.countDown(); })); awaitLatch(latch); servers.forEach(server -> { assertTrue(server.isClosed()); }); }
@Test public void testSharedServersRoundRobinButFirstStartAndStopServer() throws Exception { // Start and stop a server on the same port/host before hand to make sure it doesn't interact server.close(); CountDownLatch latch = new CountDownLatch(1); server = vertx.createNetServer(); server.connectHandler(sock -> { fail("Should not connect"); }).listen(testAddress, ar -> { if (ar.succeeded()) { latch.countDown(); } else { fail("Failed to bind server"); } }); awaitLatch(latch); CountDownLatch closeLatch = new CountDownLatch(1); server.close(ar -> { assertTrue(ar.succeeded()); closeLatch.countDown(); }); assertTrue(closeLatch.await(10, TimeUnit.SECONDS)); testSharedServersRoundRobin(); }
@Test public void testSharedServersRoundRobinWithOtherServerRunningOnDifferentPort() throws Exception { CountDownLatch latch = new CountDownLatch(1); // Have a server running on a different port to make sure it doesn't interact server.close(); server = vertx.createNetServer(new NetServerOptions().setPort(4321)); server.connectHandler(sock -> { fail("Should not connect"); }).listen(ar2 -> { if (ar2.succeeded()) { latch.countDown(); } else { fail("Failed to bind server"); } }); awaitLatch(latch); testSharedServersRoundRobin(); }
awaitLatch(latch1); NetClient client = vertx.createNetClient(); client.connect(testAddress, ar -> {