hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [1/4] hbase git commit: HBASE-20027 Add test TestClusterPortAssignment
Date Wed, 21 Feb 2018 21:12:45 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 c0bca137f -> c5e692c1d
  refs/heads/branch-1.4 491adbc5f -> a01323b2c
  refs/heads/branch-2 5c988c996 -> 67b7ce38f
  refs/heads/master bf5f03446 -> 173a5bf1f


HBASE-20027 Add test TestClusterPortAssignment

LocalHBaseCluster forces random port assignment for sake of concurrent unit test
execution friendliness, but we still need a positive test for RPC and info port
assignment.


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c5e692c1
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c5e692c1
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c5e692c1

Branch: refs/heads/branch-1
Commit: c5e692c1dc0c8830eb16ffe2561870e957cbbe8e
Parents: c0bca13
Author: Andrew Purtell <apurtell@apache.org>
Authored: Tue Feb 20 17:43:58 2018 -0800
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Wed Feb 21 13:12:26 2018 -0800

----------------------------------------------------------------------
 .../apache/hadoop/hbase/LocalHBaseCluster.java  | 18 +++--
 .../apache/hadoop/hbase/MiniHBaseCluster.java   |  8 ++-
 .../hadoop/hbase/TestClusterPortAssignment.java | 75 ++++++++++++++++++++
 3 files changed, 91 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/c5e692c1/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
index 9f8b3c1..042037e 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
@@ -69,6 +69,8 @@ public class LocalHBaseCluster {
   public static final String LOCAL = "local";
   /** 'local:' */
   public static final String LOCAL_COLON = LOCAL + ":";
+  public static final String ASSIGN_RANDOM_PORTS = "hbase.localcluster.assign.random.ports";
+
   private final Configuration conf;
   private final Class<? extends HMaster> masterClass;
   private final Class<? extends HRegionServer> regionServerClass;
@@ -142,13 +144,15 @@ public class LocalHBaseCluster {
 
     // Always have masters and regionservers come up on port '0' so we don't
     // clash over default ports.
-    conf.set(HConstants.MASTER_PORT, "0");
-    conf.set(HConstants.REGIONSERVER_PORT, "0");
-    if (conf.getInt(HConstants.REGIONSERVER_INFO_PORT, 0) != -1) {
-      conf.set(HConstants.REGIONSERVER_INFO_PORT, "0");
-    }
-    if (conf.getInt(HConstants.MASTER_INFO_PORT, 0) != -1) {
-      conf.set(HConstants.MASTER_INFO_PORT, "0");
+    if (conf.getBoolean(ASSIGN_RANDOM_PORTS, true)) {
+      conf.set(HConstants.MASTER_PORT, "0");
+      conf.set(HConstants.REGIONSERVER_PORT, "0");
+      if (conf.getInt(HConstants.REGIONSERVER_INFO_PORT, 0) != -1) {
+        conf.set(HConstants.REGIONSERVER_INFO_PORT, "0");
+      }
+      if (conf.getInt(HConstants.MASTER_INFO_PORT, 0) != -1) {
+        conf.set(HConstants.MASTER_INFO_PORT, "0");
+      }
     }
 
     this.masterClass = (Class<? extends HMaster>)

http://git-wip-us.apache.org/repos/asf/hbase/blob/c5e692c1/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
index af89d3c..299e7b9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
@@ -85,9 +85,11 @@ public class MiniHBaseCluster extends HBaseCluster {
          Class<? extends MiniHBaseCluster.MiniHBaseClusterRegionServer> regionserverClass)
       throws IOException, InterruptedException {
     super(conf);
-    conf.set(HConstants.MASTER_PORT, "0");
-    if (conf.getInt(HConstants.MASTER_INFO_PORT, 0) != -1) {
-      conf.set(HConstants.MASTER_INFO_PORT, "0");
+    if (conf.getBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, true)) {
+      conf.set(HConstants.MASTER_PORT, "0");
+      if (conf.getInt(HConstants.MASTER_INFO_PORT, 0) != -1) {
+        conf.set(HConstants.MASTER_INFO_PORT, "0");
+      }
     }
 
     // Hadoop 2

http://git-wip-us.apache.org/repos/asf/hbase/blob/c5e692c1/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClusterPortAssignment.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClusterPortAssignment.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClusterPortAssignment.java
new file mode 100644
index 0000000..5a46105
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClusterPortAssignment.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.BindException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(MediumTests.class)
+public class TestClusterPortAssignment {
+  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+  private static final Log LOG = LogFactory.getLog(TestClusterPortAssignment.class);
+
+  /**
+   * Check that we can start an HBase cluster specifying a custom set of
+   * RPC and infoserver ports.
+   */
+  @Test
+  public void testClusterPortAssignment() throws Exception {
+    boolean retry = false;
+    do {
+      int masterPort =  HBaseTestingUtility.randomFreePort();
+      int masterInfoPort =  HBaseTestingUtility.randomFreePort();
+      int rsPort =  HBaseTestingUtility.randomFreePort();
+      int rsInfoPort =  HBaseTestingUtility.randomFreePort();
+      TEST_UTIL.getConfiguration().setBoolean(LocalHBaseCluster.ASSIGN_RANDOM_PORTS, false);
+      TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_PORT, masterPort);
+      TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, masterInfoPort);
+      TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, rsPort);
+      TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort);
+      try {
+        MiniHBaseCluster cluster = TEST_UTIL.startMiniCluster();
+        assertTrue("Cluster failed to come up", cluster.waitForActiveAndReadyMaster(30000));
+        retry = false;
+        assertEquals("Master RPC port is incorrect", masterPort,
+          cluster.getMaster().getRpcServer().getListenerAddress().getPort());
+        assertEquals("Master info port is incorrect", masterInfoPort,
+          cluster.getMaster().getInfoServer().getPort());
+        assertEquals("RS RPC port is incorrect", rsPort,
+          cluster.getRegionServer(0).getRpcServer().getListenerAddress().getPort());
+        assertEquals("RS info port is incorrect", rsInfoPort,
+          cluster.getRegionServer(0).getInfoServer().getPort());
+      } catch (BindException e) {
+        LOG.info("Failed to bind, need to retry", e);
+        retry = true;
+      } finally {
+        TEST_UTIL.shutdownMiniCluster();
+      }
+    } while (retry);
+  }
+}


Mime
View raw message