HBASE-17922 Clean TestRegionServerHostname for hadoop3.
Change-Id: I6f1514b1bc301be553912539e6a4192c2ccc782b Signed-off-by: Apekshit Sharma <appy@apache.org>
This commit is contained in:
parent
e22f7bc893
commit
246d42297b
|
@ -17,9 +17,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.regionserver;
|
package org.apache.hadoop.hbase.regionserver;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -35,6 +36,8 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
|
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
|
||||||
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
||||||
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
|
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@ -45,36 +48,40 @@ import org.junit.experimental.categories.Category;
|
||||||
public class TestRegionServerHostname {
|
public class TestRegionServerHostname {
|
||||||
private static final Log LOG = LogFactory.getLog(TestRegionServerHostname.class);
|
private static final Log LOG = LogFactory.getLog(TestRegionServerHostname.class);
|
||||||
|
|
||||||
|
private HBaseTestingUtility TEST_UTIL;
|
||||||
|
|
||||||
|
private static final int NUM_MASTERS = 1;
|
||||||
|
private static final int NUM_RS = 1;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
Configuration conf = HBaseConfiguration.create();
|
||||||
|
TEST_UTIL = new HBaseTestingUtility(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown() throws Exception {
|
||||||
|
TEST_UTIL.shutdownMiniCluster();
|
||||||
|
}
|
||||||
|
|
||||||
@Test (timeout=30000)
|
@Test (timeout=30000)
|
||||||
public void testInvalidRegionServerHostnameAbortsServer() throws Exception {
|
public void testInvalidRegionServerHostnameAbortsServer() throws Exception {
|
||||||
final int NUM_MASTERS = 1;
|
|
||||||
final int NUM_RS = 1;
|
|
||||||
String invalidHostname = "hostAddr.invalid";
|
String invalidHostname = "hostAddr.invalid";
|
||||||
Configuration conf = HBaseConfiguration.create();
|
|
||||||
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
|
|
||||||
TEST_UTIL.getConfiguration().set(HRegionServer.RS_HOSTNAME_KEY, invalidHostname);
|
TEST_UTIL.getConfiguration().set(HRegionServer.RS_HOSTNAME_KEY, invalidHostname);
|
||||||
|
HRegionServer hrs = null;
|
||||||
try {
|
try {
|
||||||
TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
|
hrs = new HRegionServer(TEST_UTIL.getConfiguration(), null);
|
||||||
} catch (IOException ioe) {
|
} catch (IllegalArgumentException iae) {
|
||||||
Throwable t1 = ioe.getCause();
|
assertTrue(iae.getMessage(),
|
||||||
Throwable t2 = t1.getCause();
|
iae.getMessage().contains("Failed resolve of " + invalidHostname) ||
|
||||||
assertTrue(t1.getMessage() + " - " + t2.getMessage(),
|
iae.getMessage().contains("Problem binding to " + invalidHostname));
|
||||||
t2.getMessage().contains("Failed resolve of " + invalidHostname) ||
|
|
||||||
t2.getMessage().contains("Problem binding to " + invalidHostname));
|
|
||||||
return;
|
|
||||||
} finally {
|
|
||||||
TEST_UTIL.shutdownMiniCluster();
|
|
||||||
}
|
}
|
||||||
assertTrue("Failed to validate against invalid hostname", false);
|
assertNull("Failed to validate against invalid hostname", hrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout=120000)
|
@Test(timeout=120000)
|
||||||
public void testRegionServerHostname() throws Exception {
|
public void testRegionServerHostname() throws Exception {
|
||||||
final int NUM_MASTERS = 1;
|
|
||||||
final int NUM_RS = 1;
|
|
||||||
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
|
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
|
||||||
Configuration conf = HBaseConfiguration.create();
|
|
||||||
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
|
|
||||||
while (netInterfaceList.hasMoreElements()) {
|
while (netInterfaceList.hasMoreElements()) {
|
||||||
NetworkInterface ni = netInterfaceList.nextElement();
|
NetworkInterface ni = netInterfaceList.nextElement();
|
||||||
Enumeration<InetAddress> addrList = ni.getInetAddresses();
|
Enumeration<InetAddress> addrList = ni.getInetAddresses();
|
||||||
|
@ -109,11 +116,7 @@ public class TestRegionServerHostname {
|
||||||
|
|
||||||
@Test(timeout=30000)
|
@Test(timeout=30000)
|
||||||
public void testConflictRegionServerHostnameConfigurationsAbortServer() throws Exception {
|
public void testConflictRegionServerHostnameConfigurationsAbortServer() throws Exception {
|
||||||
final int NUM_MASTERS = 1;
|
|
||||||
final int NUM_RS = 1;
|
|
||||||
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
|
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
|
||||||
Configuration conf = HBaseConfiguration.create();
|
|
||||||
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
|
|
||||||
while (netInterfaceList.hasMoreElements()) {
|
while (netInterfaceList.hasMoreElements()) {
|
||||||
NetworkInterface ni = netInterfaceList.nextElement();
|
NetworkInterface ni = netInterfaceList.nextElement();
|
||||||
Enumeration<InetAddress> addrList = ni.getInetAddresses();
|
Enumeration<InetAddress> addrList = ni.getInetAddresses();
|
||||||
|
@ -150,20 +153,11 @@ public class TestRegionServerHostname {
|
||||||
|
|
||||||
@Test(timeout=30000)
|
@Test(timeout=30000)
|
||||||
public void testRegionServerHostnameReportedToMaster() throws Exception {
|
public void testRegionServerHostnameReportedToMaster() throws Exception {
|
||||||
final int NUM_MASTERS = 1;
|
|
||||||
final int NUM_RS = 1;
|
|
||||||
Configuration conf = HBaseConfiguration.create();
|
|
||||||
HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
|
|
||||||
TEST_UTIL.getConfiguration().setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true);
|
TEST_UTIL.getConfiguration().setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY, true);
|
||||||
TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
|
TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
|
||||||
try {
|
try (ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher()) {
|
||||||
ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
|
|
||||||
List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.znodePaths.rsZNode);
|
List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.znodePaths.rsZNode);
|
||||||
// there would be NUM_RS+1 children - one for the master
|
assertEquals("should be NUM_RS+1 children - one for master", NUM_RS + 1, servers.size());
|
||||||
assertTrue(servers.size() == NUM_RS+1);
|
|
||||||
zkw.close();
|
|
||||||
} finally {
|
|
||||||
TEST_UTIL.shutdownMiniCluster();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue