gnodet-bot commented on code in PR #28184:
URL: https://github.com/apache/camel/pull/28184#discussion_r4335217578
##########
components/camel-cxf/camel-cxf-common/src/test/java/org/apache/camel/component/cxf/common/CXFTestSupport.java:
##########
@@ -19,72 +19,70 @@
import org.apache.camel.test.AvailablePortFinder;
/**
- * For test cases that use unique contexts, they can share the ports which
will make things a bit faster as ports aren't
- * opened and closed all the time.
+ * Provides pre-allocated port numbers as system properties for test cases and
Spring XML contexts.
*/
public final class CXFTestSupport {
- static final int PORT1 = AvailablePortFinder.getNextRandomAvailable();
- static final int PORT2 = AvailablePortFinder.getNextRandomAvailable();
- static final int PORT3 = AvailablePortFinder.getNextRandomAvailable();
- static final int PORT4 = AvailablePortFinder.getNextRandomAvailable();
- static final int PORT5 = AvailablePortFinder.getNextRandomAvailable();
- static final int PORT6 = AvailablePortFinder.getNextRandomAvailable();
- static final int PORT7 = AvailablePortFinder.getNextRandomAvailable();
- static final int SSL_PORT = AvailablePortFinder.getNextRandomAvailable();
+ static final AvailablePortFinder.Port PORT1 = AvailablePortFinder.find();
+ static final AvailablePortFinder.Port PORT2 = AvailablePortFinder.find();
+ static final AvailablePortFinder.Port PORT3 = AvailablePortFinder.find();
+ static final AvailablePortFinder.Port PORT4 = AvailablePortFinder.find();
+ static final AvailablePortFinder.Port PORT5 = AvailablePortFinder.find();
+ static final AvailablePortFinder.Port PORT6 = AvailablePortFinder.find();
+ static final AvailablePortFinder.Port PORT7 = AvailablePortFinder.find();
+ static final AvailablePortFinder.Port SSL_PORT =
AvailablePortFinder.find();
static {
//set them as system properties so Spring can use the property
placeholder
//things to set them into the URL's in the spring contexts
- System.setProperty("CXFTestSupport.port1", Integer.toString(PORT1));
- System.setProperty("CXFTestSupport.port2", Integer.toString(PORT2));
- System.setProperty("CXFTestSupport.port3", Integer.toString(PORT3));
- System.setProperty("CXFTestSupport.port4", Integer.toString(PORT4));
- System.setProperty("CXFTestSupport.port5", Integer.toString(PORT5));
- System.setProperty("CXFTestSupport.port6", Integer.toString(PORT6));
- System.setProperty("CXFTestSupport.port7", Integer.toString(PORT7));
- System.setProperty("CXFTestSupport.sslPort",
Integer.toString(SSL_PORT));
-
System.setProperty("org.apache.cxf.transports.http_undertow.DontClosePort",
"true");
+ System.setProperty("CXFTestSupport.port1", PORT1.toString());
+ System.setProperty("CXFTestSupport.port2", PORT2.toString());
+ System.setProperty("CXFTestSupport.port3", PORT3.toString());
+ System.setProperty("CXFTestSupport.port4", PORT4.toString());
+ System.setProperty("CXFTestSupport.port5", PORT5.toString());
+ System.setProperty("CXFTestSupport.port6", PORT6.toString());
+ System.setProperty("CXFTestSupport.port7", PORT7.toString());
+ System.setProperty("CXFTestSupport.sslPort", SSL_PORT.toString());
}
private CXFTestSupport() {
}
public static int getPort(String name) {
- int port = AvailablePortFinder.getNextRandomAvailable();
+ int port = AvailablePortFinder.find().getPort();
Review Comment:
💡 **Nit:** Unlike the static fields (`PORT1`–`PORT7`, `SSL_PORT`) which
retain their `Port` reference to keep the port reserved, `getPort(String name)`
intentionally discards the `Port` object — the port is only reserved for the
duration of the call. A brief comment would make this intent explicit:
```suggestion
// Port reference is intentionally discarded — the port is not
reserved after this call.
int port = AvailablePortFinder.find().getPort();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]