lhotari commented on code in PR #25694:
URL: https://github.com/apache/pulsar/pull/25694#discussion_r3193817604


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImplTest.java:
##########
@@ -947,7 +947,13 @@ public void testOwnBrokerZnodeByMultipleBroker() throws 
Exception {
         ServiceConfiguration config = new ServiceConfiguration();
         config.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
         config.setClusterName("use");
-        
config.setWebServicePort(Optional.of(PortManager.nextLockedFreePort()));
+        // Pre-allocate a port: the test creates a znode at the broker's 
would-be address before
+        // starting the broker, so it needs to know the address up front.
+        int webPort;
+        try (ServerSocket socket = new ServerSocket(0)) {
+            webPort = socket.getLocalPort();
+        }

Review Comment:
   Keeping the existing PortManager would be useful for this type of use cases. 
After closing the socket, the previous port could get reused immediately since 
the socket is no longer open.



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImplWithAdvertisedListenersTest.java:
##########
@@ -61,6 +65,14 @@ protected ServiceConfiguration 
updateConfig(ServiceConfiguration conf) {
         return conf;
     }
 
+    private static int allocateFreePort() {
+        try (ServerSocket socket = new ServerSocket(0)) {
+            return socket.getLocalPort();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }

Review Comment:
   Keeping the existing PortManager would be useful for this type of use cases. 
After closing the socket, the previous port could get reused immediately since 
the socket is no longer open.



##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ServiceUrlQuarantineTest.java:
##########
@@ -97,10 +100,12 @@ protected void setup() throws Exception {
                         .build();
     }
 
-    private int nextLockedFreePort() {
-        int newLockedFreePort = PortManager.nextLockedFreePort();
-        this.lockedFreePortSet.add(newLockedFreePort);
-        return newLockedFreePort;
+    private static int allocateFreePort() {
+        try (ServerSocket socket = new ServerSocket(0)) {
+            return socket.getLocalPort();
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
     }

Review Comment:
   Keeping the existing PortManager would be useful for this type of use cases. 
After closing the socket, the previous port could get reused immediately since 
the socket is no longer open.



-- 
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]

Reply via email to