saintstack commented on a change in pull request #1659:
URL: https://github.com/apache/hbase/pull/1659#discussion_r420435064



##########
File path: 
hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
##########
@@ -264,4 +265,34 @@ boolean deleteDir(final File dir) {
       boolean failIfTimeout, Predicate<E> predicate) throws E {
     return Waiter.waitFor(this.conf, timeout, interval, failIfTimeout, 
predicate);
   }
+
+  private static final PortAllocator portAllocator = new PortAllocator();
+
+  public static int randomFreePort() {
+    try {
+      return portAllocator.randomFreePort();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  static class PortAllocator {
+
+    public PortAllocator() {
+
+    }
+
+    public int randomFreePort() throws IOException {
+      ServerSocket s = new ServerSocket(0);
+      try {
+        s.setReuseAddress(true);
+        int port = s.getLocalPort();
+        return port;
+      } finally {
+        if (null != s) {
+          s.close();
+        }
+      }
+    }
+  }
 }

Review comment:
       This is funny. I did this moving back of this facility in HBASE-24307

##########
File path: 
hbase-http/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java
##########
@@ -272,22 +272,6 @@ protected static void deleteRecursively(File d) {
     d.delete();
   }
 
-  /**
-   * Picks a free port on the host by binding a Socket to '0'.
-   */
-  protected static int getFreePort() throws IOException {
-    ServerSocket s = new ServerSocket(0);
-    try {
-      s.setReuseAddress(true);
-      int port = s.getLocalPort();
-      return port;
-    } finally {
-      if (null != s) {
-        s.close();
-      }
-    }
-  }
-

Review comment:
       I didn't get this. Good that you did.

##########
File path: 
hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
##########
@@ -264,4 +265,34 @@ boolean deleteDir(final File dir) {
       boolean failIfTimeout, Predicate<E> predicate) throws E {
     return Waiter.waitFor(this.conf, timeout, interval, failIfTimeout, 
predicate);
   }
+
+  private static final PortAllocator portAllocator = new PortAllocator();
+
+  public static int randomFreePort() {
+    try {
+      return portAllocator.randomFreePort();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  static class PortAllocator {
+
+    public PortAllocator() {
+
+    }
+
+    public int randomFreePort() throws IOException {
+      ServerSocket s = new ServerSocket(0);
+      try {
+        s.setReuseAddress(true);
+        int port = s.getLocalPort();
+        return port;
+      } finally {
+        if (null != s) {
+          s.close();
+        }
+      }
+    }
+  }
 }

Review comment:
       I don't think this is enough though. Still need to deal w/ BindException 
happening.

##########
File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/util/ProcessBasedLocalHBaseCluster.java
##########
@@ -187,11 +187,19 @@ public void startHBase() throws IOException {
   }
 
   public void startRegionServer(int port) {
-    startServer(ServerType.RS, port);
+    try {
+      startServer(ServerType.RS, port);
+    } catch (IOException e) {
+      throw new RuntimeException(e);

Review comment:
       This changes behavior? What you thinking here?




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to