This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new fbadfa58d37 (chores) tests: check port availability before running CXF
tests
fbadfa58d37 is described below
commit fbadfa58d3746ce0e900de54ffb732fe316f69a3
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Sep 14 14:11:30 2022 +0200
(chores) tests: check port availability before running CXF tests
Should prevent false negatives on hosts where the required port is not
available
---
.../org/apache/camel/test/AvailablePortFinder.java | 18 ++++++++++++++++--
.../itest/security/GreeterClientCxfMessageTest.java | 3 +++
.../apache/camel/itest/security/GreeterClientTest.java | 15 +++++++++++++++
3 files changed, 34 insertions(+), 2 deletions(-)
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/AvailablePortFinder.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/AvailablePortFinder.java
index fe11bc15d37..d1d5a106c79 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/AvailablePortFinder.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/AvailablePortFinder.java
@@ -181,10 +181,24 @@ public final class AvailablePortFinder {
* @return the port number itself if the port is
free or, in case of port 0, the first
* available port number.
*/
- private static int probePort(int port) {
+ public static int probePort(int port) {
+ return probePort(null, port);
+ }
+
+ /**
+ * Probe a port to see if it is free
+ *
+ * @param port an integer port number to be tested. If
port is 0, then the next available port is
+ * returned.
+ * @throws IllegalStateException if the port is not free or, in case of
port 0, if there are no ports available at
+ * all.
+ * @return the port number itself if the port is
free or, in case of port 0, the first
+ * available port number.
+ */
+ public static int probePort(InetAddress address, int port) {
try (ServerSocket ss = new ServerSocket()) {
ss.setReuseAddress(true);
- ss.bind(new InetSocketAddress((InetAddress) null, port), 1);
+ ss.bind(new InetSocketAddress(address, port), 1);
int probedPort = ss.getLocalPort();
LOG.info("Available port is -> {}", probedPort);
return probedPort;
diff --git
a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java
b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java
index 43d16dabd5b..d48fdd3c3f5 100644
---
a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java
+++
b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java
@@ -17,10 +17,13 @@
package org.apache.camel.itest.security;
import org.apache.camel.test.spring.junit5.CamelSpringTest;
+import org.junit.jupiter.api.condition.EnabledIf;
import org.springframework.test.context.ContextConfiguration;
@CamelSpringTest
@ContextConfiguration(locations = { "CxfMessageCamelContext.xml" })
+@EnabledIf(value =
"org.apache.camel.itest.security.GreeterClientTest#isPortAvailable",
+ disabledReason = "This test uses a fixed port that may not be
available on certain hosts")
public class GreeterClientCxfMessageTest extends GreeterClientTest {
}
diff --git
a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
index 0ca6315a602..9da5c380f4e 100644
---
a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
+++
b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.itest.security;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
@@ -24,6 +26,7 @@ import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPFaultException;
import org.apache.camel.CamelContext;
+import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
@@ -32,6 +35,7 @@ import org.apache.hello_world_soap_http.Greeter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@@ -41,6 +45,8 @@ import static org.junit.jupiter.api.Assertions.fail;
@CamelSpringTest
@ContextConfiguration(locations = { "camel-context.xml" })
+@EnabledIf(value =
"org.apache.camel.itest.security.GreeterClientTest#isPortAvailable",
+ disabledReason = "This test uses a fixed port that may not be
available on certain hosts")
public class GreeterClientTest {
private static final java.net.URL WSDL_LOC;
static {
@@ -120,4 +126,13 @@ public class GreeterClientTest {
}
}
+ public static boolean isPortAvailable() {
+ try {
+ AvailablePortFinder.probePort(InetAddress.getByName("localhost"),
9000);
+ } catch (IllegalStateException | UnknownHostException e) {
+ return false;
+ }
+
+ return true;
+ }
}