From 699dbacb912886d40924fa5e8d77594eac08f179 Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Thu, 18 Jun 2015 11:56:57 +0530 Subject: [PATCH] HBASE-13659 Improve test run time for TestMetaWithReplicas class --- .../hadoop/hbase/client/TestMetaWithReplicas.java | 50 +++++++++++----------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java index 354dc66..de108a9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java @@ -18,12 +18,10 @@ */ package org.apache.hadoop.hbase.client; -import javax.annotation.Nullable; - -import java.io.IOException; import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.assertErrors; import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.doFsck; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Arrays; import java.util.Collection; @@ -43,20 +41,19 @@ import org.apache.hadoop.hbase.RegionLocations; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotFoundException; -import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.ConnectionManager.HConnectionImplementation; import org.apache.hadoop.hbase.regionserver.StorefileRefresherChore; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.HBaseFsck; -import org.apache.hadoop.hbase.util.HBaseFsckRepair; import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE; +import org.apache.hadoop.hbase.util.HBaseFsckRepair; import org.apache.hadoop.hbase.util.hbck.HbckTestingUtil; import org.apache.hadoop.hbase.zookeeper.LoadBalancerTracker; 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.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -66,10 +63,10 @@ import org.junit.experimental.categories.Category; @Category(MediumTests.class) public class TestMetaWithReplicas { static final Log LOG = LogFactory.getLog(TestMetaWithReplicas.class); - private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - @Before - public void setup() throws Exception { + @BeforeClass + public static void setup() throws Exception { TEST_UTIL.getConfiguration().setInt("zookeeper.session.timeout", 30000); TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3); TEST_UTIL.getConfiguration().setInt( @@ -97,8 +94,8 @@ public class TestMetaWithReplicas { LOG.debug("All meta replicas assigned"); } - @After - public void tearDown() throws Exception { + @AfterClass + public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -381,17 +378,22 @@ public class TestMetaWithReplicas { locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true); HRegionLocation hrl = rl.getRegionLocation(1); ServerName oldServer = hrl.getServerName(); - TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer); - int i = 0; - do { - LOG.debug("Waiting for the replica " + hrl.getRegionInfo() + " to come up"); - Thread.sleep(30000); //wait for the detection/recovery - rl = ConnectionManager.getConnectionInternal(TEST_UTIL.getConfiguration()). - locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true); - hrl = rl.getRegionLocation(1); - i++; - } while ((hrl == null || hrl.getServerName().equals(oldServer)) && i < 3); - assertTrue(i != 3); + try { + TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer); + int i = 0; + do { + LOG.debug("Waiting for the replica " + hrl.getRegionInfo() + " to come up"); + Thread.sleep(30000); // wait for the detection/recovery + rl = + ConnectionManager.getConnectionInternal(TEST_UTIL.getConfiguration()).locateRegion( + TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true); + hrl = rl.getRegionLocation(1); + i++; + } while ((hrl == null || hrl.getServerName().equals(oldServer)) && i < 3); + assertTrue(i != 3); + } finally { + TEST_UTIL.getHBaseClusterInterface().startRegionServer(oldServer.getHostname(), 0); + } } @Test -- 1.9.2.msysgit.0