bharathv commented on a change in pull request #954: HBASE-23305: Master based registry implementation URL: https://github.com/apache/hbase/pull/954#discussion_r362731006
########## File path: hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMasterRegistry.java ########## @@ -0,0 +1,120 @@ +/* + * 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.client; + +import static org.apache.hadoop.hbase.HConstants.META_REPLICAS_NUM; +import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HRegionLocation; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; +import org.apache.hadoop.hbase.master.HMaster; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category({ MediumTests.class, ClientTests.class }) +public class TestMasterRegistry { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestMasterRegistry.class); + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + + @BeforeClass + public static void setUp() throws Exception { + TEST_UTIL.getConfiguration().setInt(META_REPLICAS_NUM, 3); + StartMiniClusterOption.Builder builder = StartMiniClusterOption.builder(); + builder.numMasters(3).numRegionServers(3); + TEST_UTIL.startMiniCluster(builder.build()); + } + + @AfterClass + public static void tearDown() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + /** + * Generates a string of dummy master addresses in host:port format. Every other hostname won't + * have a port number. + */ + private static String generateDummyMastersList(int size) { + List<String> masters = new ArrayList<>(); + for (int i = 0; i < size; i++) { + masters.add(" localhost" + (i % 2 == 0 ? ":" + (1000 + i) : "")); + } + return String.join(",", masters); + } + + /** + * Makes sure the master registry parses the master end points in the configuration correctly. + */ + @Test public void TestMasterAddressParsing() { + Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); + int numMasters = 10; + conf.set(HConstants.MASTER_ADDRS_KEY, generateDummyMastersList(numMasters)); + try (MasterRegistry registry = new MasterRegistry(conf)) { + List<ServerName> parsedMasters = registry.getParsedMasterServers(); + assertEquals(numMasters, parsedMasters.size()); + for (int i = 0; i < numMasters; i++) { + ServerName sn = parsedMasters.get(i); + assertEquals("localhost", sn.getHostname()); + if (i % 2 == 0) { + assertEquals(1000 + i, sn.getPort()); + } else { + assertEquals(HConstants.DEFAULT_MASTER_PORT, sn.getPort()); + } + } + } + } + + @Test public void TestRegistryRPCs() throws Exception { 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: us...@infra.apache.org With regards, Apache Git Services