HBASE-14897 TestTableLockManager.testReapAllTableLocks is flakey

(cherry picked from commit 47082579a8)
Signed-off-by: Sean Busbey <busbey@apache.org>
This commit is contained in:
chenheng 2015-12-01 10:31:00 +08:00 committed by Sean Busbey
parent 99306bba77
commit 7990546efe
1 changed files with 28 additions and 4 deletions

View File

@ -42,7 +42,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.InterProcessLock;
import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.NotServingRegionException;
import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.ScheduledChore;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
@ -55,6 +55,7 @@ import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.exceptions.LockTimeoutException; import org.apache.hadoop.hbase.exceptions.LockTimeoutException;
import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.LoadTestTool; import org.apache.hadoop.hbase.util.LoadTestTool;
import org.apache.hadoop.hbase.util.StoppableImplementation; import org.apache.hadoop.hbase.util.StoppableImplementation;
@ -234,6 +235,23 @@ public class TestTableLockManager {
} }
public class TableLockCounter implements InterProcessLock.MetadataHandler {
private int lockCount = 0;
@Override
public void handleMetadata(byte[] metadata) {
lockCount++;
}
public void reset() {
lockCount = 0;
}
public int getLockCount() {
return lockCount;
}
}
@Test(timeout = 600000) @Test(timeout = 600000)
public void testReapAllTableLocks() throws Exception { public void testReapAllTableLocks() throws Exception {
@ -269,9 +287,15 @@ public class TestTableLockManager {
writeLocksObtained.await(); writeLocksObtained.await();
writeLocksAttempted.await(); writeLocksAttempted.await();
TableLockCounter counter = new TableLockCounter();
do {
counter.reset();
lockManager.visitAllLocks(counter);
Thread.sleep(10);
} while (counter.getLockCount() != 10);
//now reap all table locks //now reap all table locks
lockManager.reapWriteLocks(); lockManager.reapWriteLocks();
TEST_UTIL.getConfiguration().setInt(TableLockManager.TABLE_WRITE_LOCK_TIMEOUT_MS, 0); TEST_UTIL.getConfiguration().setInt(TableLockManager.TABLE_WRITE_LOCK_TIMEOUT_MS, 0);
TableLockManager zeroTimeoutLockManager = TableLockManager.createTableLockManager( TableLockManager zeroTimeoutLockManager = TableLockManager.createTableLockManager(
TEST_UTIL.getConfiguration(), TEST_UTIL.getZooKeeperWatcher(), serverName); TEST_UTIL.getConfiguration(), TEST_UTIL.getZooKeeperWatcher(), serverName);