Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package co.elastic.apm.agent.vertx.helper;

import co.elastic.apm.agent.testutils.TestPort;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.http.HttpServer;
Expand All @@ -44,14 +43,12 @@ public class VertxTestHttpServer {
@Nullable
private HttpServer server;

private final int port;
private final Router router;


VertxTestHttpServer() {
vertx = Vertx.vertx(new VertxOptions().setEventLoopPoolSize(5));
router = Router.router(vertx);
port = TestPort.getAvailableRandomPort();
}


Expand All @@ -65,14 +62,14 @@ public void setup(VertxTestContext testContext, boolean useSSL) throws Throwable
}

server = vertx.createHttpServer(serverOptions);
server.requestHandler(router).listen(port, testContext.succeedingThenComplete());
server.requestHandler(router).listen(0, testContext.succeedingThenComplete());
assertThat(testContext.awaitCompletion(2, TimeUnit.SECONDS)).isTrue();
if (testContext.failed()) {
logger.error("starting vertx server on port {} failed", port);
logger.error("starting vertx server on port {} failed", server.actualPort());
throw testContext.causeOfFailure();
}

logger.info("starting vertx server on port {} succeeded", port);
logger.info("starting vertx server on port {} succeeded", server.actualPort());

}

Expand All @@ -82,14 +79,14 @@ public void tearDown(VertxTestContext testContext) throws Throwable {

assertThat(testContext.awaitCompletion(2, TimeUnit.SECONDS)).isTrue();
if (testContext.failed()) {
logger.error("stopping vertx server on port {} failed", port);
logger.error("stopping vertx server on port {} failed", server.actualPort());
throw testContext.causeOfFailure();
}
logger.info("stopping vertx server on port {} succeeded", port);
logger.info("stopping vertx server on port {} succeeded", server.actualPort());
}

public int getPort() {
return port;
return server.actualPort();
}

public Router getRouter() {
Expand Down