[java-idp-integration-tests] branch main updated: Replace deprecated Spring method to find available ports.
Tom Zeller
tzeller at dragonacea.biz
Tue Aug 23 13:09:50 UTC 2022
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch main
in repository java-idp-integration-tests.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=639552aec7ee9c36ac27a3ac66343013124c5c53
The following commit(s) were added to refs/heads/main by this push:
new 639552a Replace deprecated Spring method to find available ports.
639552a is described below
commit 639552aec7ee9c36ac27a3ac66343013124c5c53
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Tue Aug 23 08:09:41 2022 -0500
Replace deprecated Spring method to find available ports.
Select ~random port to shutdown Servlet container.
---
.../integration/tests/AbstractServerProcess.java | 21 +++++++++++++++++
.../idp/integration/tests/BaseIntegrationTest.java | 12 ++++++++--
.../idp/integration/tests/JettyServerProcess.java | 27 ++--------------------
.../idp/integration/tests/TomcatServerProcess.java | 23 ++++--------------
4 files changed, 38 insertions(+), 45 deletions(-)
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java b/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java
index bc3ff40..a5bde2f 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/AbstractServerProcess.java
@@ -91,6 +91,9 @@ public class AbstractServerProcess extends AbstractInitializableComponent implem
/** Whether the server process is running. */
@Nonnull private boolean isRunning = false;
+ /** Port to use to shutdown Servlet Container. Defaults to 8005. */
+ @Nonnull private int shutdownPort = 8005;
+
/**
* Build the commands used to create the server process. Appends additional commands.
*
@@ -208,6 +211,15 @@ public class AbstractServerProcess extends AbstractInitializableComponent implem
return pathToContainerHome;
}
+ /**
+ * Get port to use to shutdown Servlet container.
+ *
+ * @return port to use to shutdown Servlet container
+ */
+ public int getShutdownPort() {
+ return shutdownPort;
+ }
+
/**
* Set additional commands to start the server process.
*
@@ -262,6 +274,15 @@ public class AbstractServerProcess extends AbstractInitializableComponent implem
return this;
}
+ /**
+ * Set port to use to shutdown Servlet container.
+ *
+ * @param port to use to shutdown Servlet container
+ */
+ public void setShutdownPort(@Nonnull int port) {
+ shutdownPort = port;
+ }
+
/** {@inheritDoc} */
@Override
public void start() {
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
index 2f28be7..510f0e0 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -280,6 +280,9 @@ public abstract class BaseIntegrationTest
/** Port that the test LDAP server listens on. Defaults to 10389. */
@Nonnull protected Integer ldapPort = 10389;
+ /** Port to shutdown Servlet Container. Defaults to 8005. */
+ @Nonnull protected Integer shutdownPort = 8005;
+
/** Non-secure address that clients should connect to. Defaults to "localhost". */
@Nonnull protected String address = "localhost";
@@ -793,8 +796,8 @@ public abstract class BaseIntegrationTest
if (Boolean.getBoolean("8080")) {
return;
}
-
- final SortedSet<Integer> ports = findAvailablePorts(4);
+
+ final SortedSet<Integer> ports = findAvailablePorts(5);
final Iterator<Integer> iterator = ports.iterator();
port = iterator.next();
@@ -809,6 +812,9 @@ public abstract class BaseIntegrationTest
ldapPort = iterator.next();
log.debug("Selecting port '{}' for LDAP", ldapPort);
serverCommands.add("-D" + TEST_LDAP_PORT_PROPERTY + "=" + Integer.toString(ldapPort));
+
+ shutdownPort = iterator.next();
+ log.debug("Selecting port '{}' to shutdown Servlet container", securePort);
}
/**
@@ -1148,6 +1154,7 @@ public abstract class BaseIntegrationTest
server.setServletContainerHomePath(pathToJettyHome);
server.setAdditionalCommands(serverCommands);
server.setStatusPageURL(getBaseURL() + StatusTest.statusPath);
+ server.setShutdownPort(shutdownPort);
server.initialize();
server.start();
}
@@ -1163,6 +1170,7 @@ public abstract class BaseIntegrationTest
server.setServletContainerHomePath(pathToTomcatHome);
server.setAdditionalCommands(serverCommands);
server.setStatusPageURL(getBaseURL() + StatusTest.statusPath);
+ server.setShutdownPort(shutdownPort);
server.initialize();
server.start();
}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/JettyServerProcess.java b/src/test/java/net/shibboleth/idp/integration/tests/JettyServerProcess.java
index 5273a05..644b320 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/JettyServerProcess.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/JettyServerProcess.java
@@ -31,7 +31,6 @@ import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.SocketUtils;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -43,9 +42,6 @@ public class JettyServerProcess extends AbstractServerProcess {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(JettyServerProcess.class);
- /** Port to use to shutdown Jetty. Defaults to 8005. */
- @Nonnull private int shutdownPort = 8005;
-
/** Passphrase to use to shutdown Jetty. Defaults to SHUTDOWN. */
@Nonnull private String shutdownKey = "SHUTDOWN";
@@ -65,8 +61,7 @@ public class JettyServerProcess extends AbstractServerProcess {
getCommands().add("-jar");
getCommands().add(getServletContainerHomePath().toAbsolutePath().toString() + "/start.jar");
getCommands().add("STOP.KEY=" + shutdownKey);
- nextAvailableShutdownPort();
- getCommands().add("STOP.PORT=" + Integer.toString(shutdownPort));
+ getCommands().add("STOP.PORT=" + Integer.toString(getShutdownPort()));
}
/**
@@ -81,24 +76,6 @@ public class JettyServerProcess extends AbstractServerProcess {
shutdownKey = key;
}
- /**
- * Configure the next available port in the range 20000-30000 to shutdown Jetty.
- *
- * @return the next available port to use to shutdown Tomcat, by default '8005' if the '8080' system property is
- * <code>true</code>
- * @throws ComponentInitializationException if catalina.properties cannot be modified
- */
- @Nonnull
- public int nextAvailableShutdownPort() throws ComponentInitializationException {
- if (Boolean.getBoolean("8080")) {
- log.debug("System property '8080' is true, using default shutdown port {}", shutdownPort);
- return shutdownPort;
- }
- shutdownPort = SocketUtils.findAvailableTcpPort(20000, 30000);
- log.debug("Selecting Jetty shutdown port {}", shutdownPort);
- return shutdownPort;
- }
-
/**
* Attempt to shutdown Jetty.
*
@@ -145,7 +122,7 @@ public class JettyServerProcess extends AbstractServerProcess {
/** {@inheritDoc} */
@Override
public void stop() {
- shutdown("127.0.0.1", shutdownPort, shutdownKey);
+ shutdown("127.0.0.1", getShutdownPort(), shutdownKey);
super.stop();
}
}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/TomcatServerProcess.java b/src/test/java/net/shibboleth/idp/integration/tests/TomcatServerProcess.java
index 93e0834..257fc71 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/TomcatServerProcess.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/TomcatServerProcess.java
@@ -27,7 +27,6 @@ import javax.annotation.Nonnull;
import org.apache.commons.net.telnet.TelnetClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.SocketUtils;
import org.testng.Assert;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -39,9 +38,6 @@ public class TomcatServerProcess extends AbstractServerProcess {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(TomcatServerProcess.class);
- /** Port to use to shutdown Tomcat. Defaults to 8005. */
- @Nonnull private int shutdownPort = 8005;
-
/** {@inheritDoc} */
@Override
protected void doInitialize() throws ComponentInitializationException {
@@ -81,25 +77,18 @@ public class TomcatServerProcess extends AbstractServerProcess {
getCommands().add(pathToStartup.toAbsolutePath().toString());
// Configure Tomcat's shutdown port
- nextAvailableShutdownPort();
+ setUpShutdownPort();
}
/**
- * Configure the next available port in the range 20000-30000 to shutdown Tomcat.
+ * Configure port to shutdown Tomcat.
*
- * @return the next available port to use to shutdown Tomcat, by default '8005' if the '8080' system property is
- * <code>true</code>
* @throws ComponentInitializationException if catalina.properties cannot be modified
*/
@Nonnull
- public int nextAvailableShutdownPort() throws ComponentInitializationException {
-
- if (Boolean.getBoolean("8080")) {
- log.debug("System property '8080' is true, using default shutdown port {}", shutdownPort);
- return shutdownPort;
- }
+ public void setUpShutdownPort() throws ComponentInitializationException {
- shutdownPort = SocketUtils.findAvailableTcpPort(20000, 30000);
+ final int shutdownPort = getShutdownPort();
log.debug("Selecting Tomcat shutdown port {}", shutdownPort);
final Path pathToCatalinaProp = getServletContainerBasePath().resolve(Paths.get("conf", "catalina.properties"));
@@ -110,8 +99,6 @@ public class TomcatServerProcess extends AbstractServerProcess {
log.error("Unable to replace file '{}'", pathToCatalinaProp, e);
throw new ComponentInitializationException(e);
}
-
- return shutdownPort;
}
/**
@@ -150,7 +137,7 @@ public class TomcatServerProcess extends AbstractServerProcess {
/** {@inheritDoc} */
@Override
public void stop() {
- shutdown("127.0.0.1", shutdownPort, "SHUTDOWN");
+ shutdown("127.0.0.1", getShutdownPort(), "SHUTDOWN");
super.stop();
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list