diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 655bbdbe015..31a7cad3f5e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -1237,9 +1237,41 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { } /** - * Shutdown HBase mini cluster. Does not shutdown zk or dfs if running. + * Shutdown HBase mini cluster.Does not shutdown zk or dfs if running. + * @throws java.io.IOException in case command is unsuccessful */ public void shutdownMiniHBaseCluster() throws IOException { + cleanup(); + if (this.hbaseCluster != null) { + this.hbaseCluster.shutdown(); + // Wait till hbase is down before going on to shutdown zk. + this.hbaseCluster.waitUntilShutDown(); + this.hbaseCluster = null; + } + if (zooKeeperWatcher != null) { + zooKeeperWatcher.close(); + zooKeeperWatcher = null; + } + } + + /** + * Abruptly Shutdown HBase mini cluster. Does not shutdown zk or dfs if running. + * @throws java.io.IOException throws in case command is unsuccessful + */ + public void killMiniHBaseCluster() throws IOException { + cleanup(); + if (this.hbaseCluster != null) { + getMiniHBaseCluster().killAll(); + this.hbaseCluster = null; + } + if (zooKeeperWatcher != null) { + zooKeeperWatcher.close(); + zooKeeperWatcher = null; + } + } + + // close hbase admin, close current connection and reset MIN MAX configs for RS. + private void cleanup() throws IOException { if (hbaseAdmin != null) { hbaseAdmin.close(); hbaseAdmin = null; @@ -1251,16 +1283,6 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility { // unset the configuration for MIN and MAX RS to start conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, -1); conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MAXTOSTART, -1); - if (this.hbaseCluster != null) { - this.hbaseCluster.shutdown(); - // Wait till hbase is down before going on to shutdown zk. - this.hbaseCluster.waitUntilShutDown(); - this.hbaseCluster = null; - } - if (zooKeeperWatcher != null) { - zooKeeperWatcher.close(); - zooKeeperWatcher = null; - } } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java index 97de8a9e773..0ec97ef2a26 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java @@ -26,11 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.File; -import java.io.IOException; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import java.util.Random; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; @@ -62,6 +58,9 @@ import org.slf4j.LoggerFactory; */ @Category({MiscTests.class, LargeTests.class}) public class TestHBaseTestingUtility { + private static final int NUMTABLES = 1; + private static final int NUMROWS = 100; + private static final int NUMREGIONS = 10; @ClassRule public static final HBaseClassTestRule CLASS_RULE = @@ -471,4 +470,32 @@ public class TestHBaseTestingUtility { htu.shutdownMiniCluster(); } } + + // This test demonstrates how long killHBTU takes vs. shutdownHBTU takes + // for realistic results, adjust NUMROWS, NUMTABLES to much larger number. + @Test + public void testKillMiniHBaseCluster() throws Exception { + + HBaseTestingUtility htu = new HBaseTestingUtility(); + htu.startMiniZKCluster(); + + try { + htu.startMiniHBaseCluster(); + + TableName tableName; + byte[] FAM_NAME; + + for(int i = 0; i < NUMTABLES; i++) { + tableName = TableName.valueOf(name.getMethodName() + i); + FAM_NAME = Bytes.toBytes("fam" + i); + + try (Table table = htu.createMultiRegionTable(tableName, FAM_NAME, NUMREGIONS)) { + htu.loadRandomRows(table, FAM_NAME, 100, NUMROWS); + } + } + } finally { + htu.killMiniHBaseCluster(); + htu.shutdownMiniZKCluster(); + } + } }