adoroszlai commented on a change in pull request #2550:
URL: https://github.com/apache/ozone/pull/2550#discussion_r691046302



##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -700,6 +701,9 @@ public void bootstrapOzoneManager(String omNodeId) throws 
Exception {
     while (true) {
       try {
         basePort = 10000 + RANDOM.nextInt(1000) * 4;
+        if (!isPortAvailable(basePort)) {

Review comment:
       There are already some tests that use random port using this 
`ServerSocket(0)` technique.  We could just call this method to get OM port:
   
   
https://github.com/apache/ozone/blob/d96399142f1f84f54d6dd783dbff6b8415f1c1e6/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/SCMTestUtils.java#L115-L122

##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -700,6 +701,9 @@ public void bootstrapOzoneManager(String omNodeId) throws 
Exception {
     while (true) {
       try {
         basePort = 10000 + RANDOM.nextInt(1000) * 4;
+        if (!isPortAvailable(basePort)) {

Review comment:
       I'd go for calling it once for each distinct port.  Any port can be 
occupied independently.

##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
##########
@@ -966,4 +970,31 @@ public StorageContainerManager 
getStorageContainerManager() {
     return getStorageContainerManagers().get(0);
   }
 
+  private int getFreePort() {
+    ServerSocket ss = null;
+    try {
+      ss = new ServerSocket(0);
+      return ss.getLocalPort();
+    } catch (IOException e) {
+      e.printStackTrace();
+    } finally {
+      if (ss != null) {
+        try {
+          ss.close();
+        } catch (IOException e) {
+          LOG.error("Got exception while closing ServerSocket: " +
+              e.getMessage());
+        }
+      }
+    }
+    return -1;
+  }
+
+  private Set<Integer> getFreePortSet(int size) {
+    Set<Integer> portSet = new HashSet<>();
+    while (portSet.size() < size) {
+      portSet.add(getFreePort());

Review comment:
       This reminds me: we could use `NetUtils.createLocalServerAddress(int)` 
from Ratis to get multiple free ports.
   
   
https://github.com/apache/ratis/blob/5e444084307dce717816dd16c7942d785fd3e9d1/ratis-common/src/main/java/org/apache/ratis/util/NetUtils.java#L119-L143




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