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.regionserver; 019 020import static org.junit.Assert.assertEquals; 021 022import java.net.InetAddress; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.HBaseConfiguration; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.HConstants; 028import org.apache.hadoop.hbase.SingleProcessHBaseCluster; 029import org.apache.hadoop.hbase.StartTestingClusterOption; 030import org.apache.hadoop.hbase.testclassification.MediumTests; 031import org.apache.hadoop.hbase.testclassification.RegionServerTests; 032import org.junit.After; 033import org.junit.Before; 034import org.junit.ClassRule; 035import org.junit.Test; 036import org.junit.experimental.categories.Category; 037import org.slf4j.Logger; 038import org.slf4j.LoggerFactory; 039 040@Category({ RegionServerTests.class, MediumTests.class }) 041public class TestRegionServerUseIp { 042 @ClassRule 043 public static final HBaseClassTestRule CLASS_RULE = 044 HBaseClassTestRule.forClass(TestRegionServerUseIp.class); 045 046 private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerUseIp.class); 047 048 private HBaseTestingUtil TEST_UTIL; 049 private SingleProcessHBaseCluster CLUSTER; 050 051 private static final int NUM_MASTERS = 1; 052 private static final int NUM_RS = 1; 053 054 @Before 055 public void setup() throws Exception { 056 Configuration conf = HBaseConfiguration.create(); 057 conf.setBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY, true); 058 TEST_UTIL = new HBaseTestingUtil(conf); 059 StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(NUM_MASTERS) 060 .numRegionServers(NUM_RS).numDataNodes(NUM_RS).build(); 061 CLUSTER = TEST_UTIL.startMiniCluster(option); 062 } 063 064 @After 065 public void teardown() throws Exception { 066 TEST_UTIL.shutdownMiniCluster(); 067 } 068 069 @Test 070 public void testRegionServerUseIp() throws Exception { 071 String hostname = CLUSTER.getRegionServer(0).getServerName().getHostname(); 072 String ip = InetAddress.getByName(hostname).getHostAddress(); 073 LOG.info("hostname= " + hostname + " ,ip=" + ip); 074 assertEquals(ip, hostname); 075 } 076}