HBASE-19138 Rare failure in TestLruBlockCache

Wait for the block count to drop to zero after awaiting shutdown of the executor pool
This commit is contained in:
Andrew Purtell 2017-10-31 11:35:48 -07:00
parent d099263e13
commit 0ac5b33747
1 changed files with 16 additions and 0 deletions

View File

@ -31,6 +31,10 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
import org.apache.hadoop.hbase.io.HeapSize;
import org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread;
import org.apache.hadoop.hbase.util.ClassSize;
@ -55,6 +59,7 @@ public class TestLruBlockCache {
final long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);
final Configuration conf = HBaseConfiguration.create();
final LruBlockCache cache = new LruBlockCache(maxSize, blockSize);
EvictionThread evictionThread = cache.getEvictionThread();
assertTrue(evictionThread != null);
@ -83,6 +88,17 @@ public class TestLruBlockCache {
service.shutdown();
// The test may fail here if the evict thread frees the blocks too fast
service.awaitTermination(10, TimeUnit.MINUTES);
Waiter.waitFor(conf, 10000, 100, new ExplainingPredicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return cache.getBlockCount() == 0;
}
@Override
public String explainFailure() throws Exception {
return "Cache block count failed to return to 0";
}
});
assertEquals(0, cache.getBlockCount());
assertEquals(cache.getOverhead(), cache.getCurrentSize());
}