Index: hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (revision 1460768) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (working copy) @@ -1920,6 +1920,41 @@ closeRegion(hrl.getRegionInfo().getRegionName()); } + /* + * Retrieves a splittable region randomly from tableName + * + * @param tableName name of table + * @param maxAttempts maximum number of attempts, unlimited for value of -1 + * @return the HRegion chosen, null if none was found within limit of maxAttempts + */ + public HRegion getSplittableRegion(byte[] tableName, int maxAttempts) { + List regions = getHBaseCluster().getRegions(tableName); + int regCount = regions.size(); + Set attempted = new HashSet(); + int idx; + int attempts = 0; + do { + regions = getHBaseCluster().getRegions(tableName); + if (regCount != regions.size()) { + // if there was region movement, clear attempted Set + attempted.clear(); + } + regCount = regions.size(); + idx = random.nextInt(regions.size()); + // if we have just tried this region, there is no need to try again + if (attempted.contains(idx)) continue; + try { + regions.get(idx).checkSplit(); + return regions.get(idx); + } catch (Exception ex) { + LOG.warn("Caught exception", ex); + attempted.add(idx); + } + attempts++; + } while (maxAttempts == -1 || attempts < maxAttempts); + return null; + } + public MiniZooKeeperCluster getZkCluster() { return zkCluster; } Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java (revision 1460768) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableLockManager.java (working copy) @@ -25,8 +25,10 @@ import static org.junit.Assert.fail; import java.io.IOException; +import java.util.HashSet; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -353,9 +355,8 @@ @Override public void chore() { try { - Random random = new Random(); - List regions = admin.getTableRegions(tableName); - byte[] regionName = regions.get(random.nextInt(regions.size())).getRegionName(); + HRegion region = TEST_UTIL.getSplittableRegion(tableName, -1); + byte[] regionName = region.getRegionName(); admin.flush(regionName); admin.compact(regionName); admin.split(regionName);