Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CDA9B200CD9 for ; Thu, 20 Jul 2017 07:42:40 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CC24116A953; Thu, 20 Jul 2017 05:42:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E87FB16A94E for ; Thu, 20 Jul 2017 07:42:39 +0200 (CEST) Received: (qmail 68371 invoked by uid 500); 20 Jul 2017 05:42:39 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 68303 invoked by uid 99); 20 Jul 2017 05:42:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jul 2017 05:42:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1D4C9E96A8; Thu, 20 Jul 2017 05:42:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: busbey@apache.org To: commits@hbase.apache.org Date: Thu, 20 Jul 2017 05:42:39 -0000 Message-Id: <5018d2d5c51149f9a3d9e930e782d6fc@git.apache.org> In-Reply-To: <571ad936ce604807af51502be66ae630@git.apache.org> References: <571ad936ce604807af51502be66ae630@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [02/26] hbase git commit: HBASE-17922 Clean TestRegionServerHostname for hadoop3. archived-at: Thu, 20 Jul 2017 05:42:41 -0000 HBASE-17922 Clean TestRegionServerHostname for hadoop3. Change-Id: I6f1514b1bc301be553912539e6a4192c2ccc782b Signed-off-by: Apekshit Sharma Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/9e0f450c Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/9e0f450c Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/9e0f450c Branch: refs/heads/HBASE-18147 Commit: 9e0f450c0ca732a9634e2147c2e0d7b885eca9cc Parents: 500592d Author: Mike Drob Authored: Thu Jun 29 15:30:11 2017 -0500 Committer: Apekshit Sharma Committed: Thu Jul 13 11:44:18 2017 -0700 ---------------------------------------------------------------------- .../regionserver/TestRegionServerHostname.java | 64 +++++++++----------- 1 file changed, 29 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/9e0f450c/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java index 679595a..317a3a2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java @@ -17,9 +17,10 @@ */ 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 java.io.IOException; import java.net.InetAddress; import java.net.NetworkInterface; 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.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -45,36 +48,40 @@ import org.junit.experimental.categories.Category; public class TestRegionServerHostname { 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) public void testInvalidRegionServerHostnameAbortsServer() throws Exception { - final int NUM_MASTERS = 1; - final int NUM_RS = 1; String invalidHostname = "hostAddr.invalid"; - Configuration conf = HBaseConfiguration.create(); - HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf); TEST_UTIL.getConfiguration().set(HRegionServer.RS_HOSTNAME_KEY, invalidHostname); + HRegionServer hrs = null; try { - TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS); - } catch (IOException ioe) { - Throwable t1 = ioe.getCause(); - Throwable t2 = t1.getCause(); - assertTrue(t1.getMessage() + " - " + t2.getMessage(), - t2.getMessage().contains("Failed resolve of " + invalidHostname) || - t2.getMessage().contains("Problem binding to " + invalidHostname)); - return; - } finally { - TEST_UTIL.shutdownMiniCluster(); + hrs = new HRegionServer(TEST_UTIL.getConfiguration(), null); + } catch (IllegalArgumentException iae) { + assertTrue(iae.getMessage(), + iae.getMessage().contains("Failed resolve of " + invalidHostname) || + iae.getMessage().contains("Problem binding to " + invalidHostname)); } - assertTrue("Failed to validate against invalid hostname", false); + assertNull("Failed to validate against invalid hostname", hrs); } @Test(timeout=120000) public void testRegionServerHostname() throws Exception { - final int NUM_MASTERS = 1; - final int NUM_RS = 1; Enumeration netInterfaceList = NetworkInterface.getNetworkInterfaces(); - Configuration conf = HBaseConfiguration.create(); - HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf); while (netInterfaceList.hasMoreElements()) { NetworkInterface ni = netInterfaceList.nextElement(); Enumeration addrList = ni.getInetAddresses(); @@ -109,11 +116,7 @@ public class TestRegionServerHostname { @Test(timeout=30000) public void testConflictRegionServerHostnameConfigurationsAbortServer() throws Exception { - final int NUM_MASTERS = 1; - final int NUM_RS = 1; Enumeration netInterfaceList = NetworkInterface.getNetworkInterfaces(); - Configuration conf = HBaseConfiguration.create(); - HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf); while (netInterfaceList.hasMoreElements()) { NetworkInterface ni = netInterfaceList.nextElement(); Enumeration addrList = ni.getInetAddresses(); @@ -150,20 +153,11 @@ public class TestRegionServerHostname { @Test(timeout=30000) 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.startMiniCluster(NUM_MASTERS, NUM_RS); - try { - ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher(); + try (ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher()) { List servers = ZKUtil.listChildrenNoWatch(zkw, zkw.znodePaths.rsZNode); - // there would be NUM_RS+1 children - one for the master - assertTrue(servers.size() == NUM_RS+1); - zkw.close(); - } finally { - TEST_UTIL.shutdownMiniCluster(); + assertEquals("should be NUM_RS+1 children - one for master", NUM_RS + 1, servers.size()); } } }