ayushtkn commented on a change in pull request #4028:
URL: https://github.com/apache/hadoop/pull/4028#discussion_r818311796



##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java
##########
@@ -1053,6 +1053,25 @@ public static int getFreeSocketPort() {
     return port;
   }
 
+  /**
+   * Return free ports. There is no guarantee they will remain free, so
+   * ports should be used immediately. The number of free ports returned by
+   * this method should match argument {@code numOfPorts}.
+   *
+   * @param numOfPorts Number of free ports to acquire.
+   * @return Free ports for binding a local socket.
+   */
+  public static Set<Integer> getFreeSocketPorts(int numOfPorts) {
+    final Set<Integer> freePorts = new HashSet<>(numOfPorts);
+    for (int i = 0; i < numOfPorts * 5; i++) {
+      freePorts.add(getFreeSocketPort());

Review comment:
       ``getFreeSocketPort()`` as per code can return 0 as well, we should 
avoid that? We can't classify 0 as a unique free port.
   if it returns 0, then your test would also fail. you would be expecting the 
port to be 0, but it would be different 




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to