HBASE-8164 TestTableLockManager fails intermittently in trunk builds (Ted Yu)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1461797 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2013-03-27 18:56:01 +00:00
parent 4ee77aed69
commit a0185e5462
2 changed files with 39 additions and 3 deletions

View File

@ -1920,6 +1920,41 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
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<HRegion> regions = getHBaseCluster().getRegions(tableName);
int regCount = regions.size();
Set<Integer> attempted = new HashSet<Integer>();
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;
}

View File

@ -25,8 +25,10 @@ import static org.junit.Assert.assertEquals;
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 @@ public class TestTableLockManager {
@Override
public void chore() {
try {
Random random = new Random();
List<HRegionInfo> 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);