001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.master;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021
022import java.net.InetAddress;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.HBaseConfiguration;
025import org.apache.hadoop.hbase.HBaseTestingUtil;
026import org.apache.hadoop.hbase.HConstants;
027import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
028import org.apache.hadoop.hbase.StartTestingClusterOption;
029import org.apache.hadoop.hbase.testclassification.MasterTests;
030import org.apache.hadoop.hbase.testclassification.MediumTests;
031import org.junit.jupiter.api.AfterEach;
032import org.junit.jupiter.api.BeforeEach;
033import org.junit.jupiter.api.Tag;
034import org.junit.jupiter.api.Test;
035import org.slf4j.Logger;
036import org.slf4j.LoggerFactory;
037
038@Tag(MasterTests.TAG)
039@Tag(MediumTests.TAG)
040public class TestMasterUseIp {
041
042  private static final Logger LOG = LoggerFactory.getLogger(TestMasterUseIp.class);
043
044  private HBaseTestingUtil TEST_UTIL;
045  private SingleProcessHBaseCluster CLUSTER;
046
047  private static final int NUM_MASTERS = 1;
048  private static final int NUM_RS = 1;
049
050  @BeforeEach
051  public void setup() throws Exception {
052    Configuration conf = HBaseConfiguration.create();
053    conf.setBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY, true);
054    TEST_UTIL = new HBaseTestingUtil(conf);
055    StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(NUM_MASTERS)
056      .numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
057    CLUSTER = TEST_UTIL.startMiniCluster(option);
058  }
059
060  @AfterEach
061  public void teardown() throws Exception {
062    TEST_UTIL.shutdownMiniCluster();
063  }
064
065  @Test
066  public void testMasterUseIp() throws Exception {
067    String hostname = CLUSTER.getMaster(0).getServerName().getHostname();
068    String ip = InetAddress.getByName(hostname).getHostAddress();
069    LOG.info("hostname= " + hostname + " ,ip=" + ip);
070    assertEquals(ip, hostname);
071  }
072}