From 1d873a9de9ad98d9f3120fa2ff59c3372650775b Mon Sep 17 00:00:00 2001 From: Jason Gustafson Date: Fri, 12 Jul 2019 15:29:10 -0700 Subject: [PATCH] MINOR: Use dynamic port in `RestServerTest` (#7079) We have seen some failures recently in `RestServerTest`. It's the usual problem with reliance on static ports. ``` Caused by: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8083 at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:346) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:308) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.server.Server.doStart(Server.java:396) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.apache.kafka.connect.runtime.rest.RestServer.initializeServer(RestServer.java:178) ... 56 more Caused by: java.net.BindException: Address already in use ``` This patch makes the chosen port dynamic. Reviewers: Ismael Juma --- .../apache/kafka/connect/runtime/rest/RestServerTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java index 3609fb3ac32..a640b83f383 100644 --- a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java +++ b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java @@ -78,6 +78,7 @@ public class RestServerTest { workerProps.put(WorkerConfig.INTERNAL_KEY_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put(WorkerConfig.INTERNAL_VALUE_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); workerProps.put(DistributedConfig.OFFSET_STORAGE_TOPIC_CONFIG, "connect-offsets"); + workerProps.put(WorkerConfig.LISTENERS_CONFIG, "HTTP://localhost:0"); return workerProps; } @@ -105,6 +106,7 @@ public class RestServerTest { // Build listener from hostname and port configMap = new HashMap<>(baseWorkerProps()); + configMap.remove(WorkerConfig.LISTENERS_CONFIG); configMap.put(WorkerConfig.REST_HOST_NAME_CONFIG, "my-hostname"); configMap.put(WorkerConfig.REST_PORT_CONFIG, "8080"); config = new DistributedConfig(configMap); @@ -115,7 +117,7 @@ public class RestServerTest { @SuppressWarnings("deprecation") @Test public void testAdvertisedUri() { - // Advertised URI from listeenrs without protocol + // Advertised URI from listeners without protocol Map configMap = new HashMap<>(baseWorkerProps()); configMap.put(WorkerConfig.LISTENERS_CONFIG, "http://localhost:8080,https://localhost:8443"); DistributedConfig config = new DistributedConfig(configMap); @@ -153,6 +155,7 @@ public class RestServerTest { // listener from hostname and port configMap = new HashMap<>(baseWorkerProps()); + configMap.remove(WorkerConfig.LISTENERS_CONFIG); configMap.put(WorkerConfig.REST_HOST_NAME_CONFIG, "my-hostname"); configMap.put(WorkerConfig.REST_PORT_CONFIG, "8080"); config = new DistributedConfig(configMap);