summaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java
diff options
context:
space:
mode:
Diffstat (limited to 'metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java')
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java
index fdf2fae3081..f7802fd04fb 100644
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java
+++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java
@@ -23,23 +23,26 @@ public class MockHttpServer {
/**
* Mock http server that will return response as body
*
- * @param port the port to listen to
* @param response the response to return along with 200 OK
* @param path the file path that the server will accept requests for. E.g /state/v1/metrics
*/
- public MockHttpServer(int port, String response, String path) throws IOException {
+ public MockHttpServer(String response, String path) throws IOException {
this.response = response;
- this.server = HttpServer.create(new InetSocketAddress(port), 10);
+ this.server = HttpServer.create(new InetSocketAddress(0), 10);
this.server.createContext(path, new MyHandler());
this.server.setExecutor(null); // creates a default executor
this.server.start();
- System.out.println("Started web server on port " + port);
+ System.out.println("Started web server on port " + port());
}
public synchronized void setResponse(String r) {
this.response = r;
}
+ public int port() {
+ return server.getAddress().getPort();
+ }
+
public void close() {
this.server.stop(0);
}