// Start the servers
HttpServer[] servers = new HttpServer[numServers];
CountDownLatch startServerLatch = new CountDownLatch(numServers);
Set<HttpServer> connectedServers = new ConcurrentHashSet<>();
for (int i = 0; i < numServers; i++) {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setHost(DEFAULT_HTTP_HOST).setPort(DEFAULT_HTTP_PORT));
server.requestHandler(req -> {
connectedServers.add(server);
req.response().end();
});
server.listen(ar -> {
assertTrue(ar.succeeded());
startServerLatch.countDown();
});
servers[i] = server;
}
awaitLatch(startServerLatch);
CountDownLatch reqLatch = new CountDownLatch(requests);
for (int count = 0; count < requests; count++) {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
assertEquals(200, resp.statusCode());
reqLatch.countDown();
}).end();
}
awaitLatch(reqLatch);
assertEquals(expectedConnectedServers, connectedServers.size());
CountDownLatch serverCloseLatch = new CountDownLatch(numServers);
for (HttpServer server: servers) {
server.close(ar -> {
assertTrue(ar.succeeded());
serverCloseLatch.countDown();
});
}