diff --git a/CHANGES.txt b/CHANGES.txt index 2babd8b99c3..2b2c2527b9c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -222,6 +222,8 @@ Release 0.21.0 - Unreleased (Lars George and J-D via Stack) HBASE-2027 HConnectionManager.HBASE_INSTANCES leaks TableServers (Dave Latham via Stack) + HBASE-2013 Add useful helpers to HBaseTestingUtility.java (Lars George + via J-D) NEW FEATURES HBASE-1901 "General" partitioner for "hbase-48" bulk (behind the api, write diff --git a/src/test/org/apache/hadoop/hbase/HBaseTestingUtility.java b/src/test/org/apache/hadoop/hbase/HBaseTestingUtility.java index ac0632ef8b0..967afc130d2 100644 --- a/src/test/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/src/test/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -35,7 +35,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HConnection; -import org.apache.hadoop.hbase.client.HConnectionManager; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; @@ -70,7 +69,8 @@ public class HBaseTestingUtility { private MiniHBaseCluster hbaseCluster = null; private MiniMRCluster mrCluster = null; private File clusterTestBuildDir = null; - + private HBaseAdmin hbaseAdmin = null; + /** System property key to get test directory value. */ public static final String TEST_DIRECTORY_KEY = "test.build.data"; @@ -511,10 +511,68 @@ public class HBaseTestingUtility { } /** - * Get the HBase cluster + * Get the HBase cluster. + * * @return hbase cluster */ - public MiniHBaseCluster getHbaseCluster() { + public MiniHBaseCluster getHBaseCluster() { return hbaseCluster; } + + /** + * Returns a HBaseAdmin instance. + * + * @return The HBaseAdmin instance. + * @throws MasterNotRunningException + */ + public HBaseAdmin getHBaseAdmin() throws MasterNotRunningException { + if (hbaseAdmin == null) { + hbaseAdmin = new HBaseAdmin(getConfiguration()); + } + return hbaseAdmin; + } + + /** + * Closes the named region. + * + * @param regionName The region to close. + * @throws IOException + */ + public void closeRegion(String regionName) throws IOException { + closeRegion(Bytes.toBytes(regionName)); + } + + /** + * Closes the named region. + * + * @param regionName The region to close. + * @throws IOException + */ + public void closeRegion(byte[] regionName) throws IOException { + HBaseAdmin admin = getHBaseAdmin(); + admin.closeRegion(regionName, (Object[]) null); + } + + /** + * Closes the region containing the given row. + * + * @param row The row to find the containing region. + * @param table The table to find the region. + * @throws IOException + */ + public void closeRegionByRow(String row, HTable table) throws IOException { + closeRegionByRow(Bytes.toBytes(row), table); + } + + /** + * Closes the region containing the given row. + * + * @param row The row to find the containing region. + * @param table The table to find the region. + * @throws IOException + */ + public void closeRegionByRow(byte[] row, HTable table) throws IOException { + HRegionLocation hrl = table.getRegionLocation(row); + closeRegion(hrl.getRegionInfo().getRegionName()); + } } \ No newline at end of file diff --git a/src/test/org/apache/hadoop/hbase/TestZooKeeper.java b/src/test/org/apache/hadoop/hbase/TestZooKeeper.java index ac79282dbe6..5a4209359dc 100644 --- a/src/test/org/apache/hadoop/hbase/TestZooKeeper.java +++ b/src/test/org/apache/hadoop/hbase/TestZooKeeper.java @@ -59,7 +59,7 @@ public class TestZooKeeper { @Before public void setUp() throws Exception { conf = TEST_UTIL.getConfiguration(); - cluster = TEST_UTIL.getHbaseCluster(); + cluster = TEST_UTIL.getHBaseCluster(); } /**