You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/11/11 23:40:07 UTC

[GitHub] [hbase] bharathv commented on a change in pull request #807: HBASE-23259: Ability to start minicluster with pre-determined master ports

bharathv commented on a change in pull request #807: HBASE-23259: Ability to start minicluster with pre-determined master ports
URL: https://github.com/apache/hbase/pull/807#discussion_r344958658
 
 

 ##########
 File path: hbase-server/src/test/java/org/apache/hadoop/hbase/TestClusterWithFixedMasterPorts.java
 ##########
 @@ -0,0 +1,77 @@
+/**
+ * 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.apache.hadoop.hbase.HBaseTestingUtility.randomFreePorts;
+
+import java.net.BindException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.JVMClusterUtil;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.apache.hbase.thirdparty.com.google.common.base.Joiner;
+
+@Category(SmallTests.class)
+public class TestClusterWithFixedMasterPorts {
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+      HBaseClassTestRule.forClass(TestClusterWithFixedMasterPorts.class);
+
+  private static final int MAX_INIT_RETRIES = 10;
+
+  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
+  @AfterClass
+  public static void cleanUp() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  /**
+   * Test runs a mini cluster with pre-determined master ports and then verifies that the
+   * configuration is reflected in the cluster conf accordingly.
+   */
+  @Test
+  public void testValidateMasterAddrConfig() throws Exception {
+    int retries = 0;
+    boolean doRetry = false;
+    StartMiniClusterOption option = StartMiniClusterOption.builder()
+        .numRegionServers(1).numMasters(3)
+        .masterPorts(randomFreePorts(3)).build();
+    do {
+      try {
+        TEST_UTIL.startMiniCluster(option);
+      } catch (BindException e) {
+        // Theoretically random ports can still cause port conflicts because they could be picked up
+        // by another process/thread before we bind to them.
+        doRetry = true;
+      }
+    } while (doRetry && retries++ < MAX_INIT_RETRIES);
+    List<String> actualMasterAddrs = new ArrayList<>();
+    for (JVMClusterUtil.MasterThread master: TEST_UTIL.getMiniHBaseCluster().getMasterThreads()) {
+      ServerName sname = master.getMaster().getServerName();
+      actualMasterAddrs.add(sname.getHostname() + ":" + sname.getPort());
+    }
+    Assert.assertEquals(Joiner.on(",").join(actualMasterAddrs),
 
 Review comment:
   Done.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services