Repository: hbase
Updated Branches:
  refs/heads/branch-2 16012f93a -> 314759652
  refs/heads/master 8237fdbd1 -> 9382f391c


HBASE-19138 Rare failure in TestLruBlockCache

Wait for the block count to drop to zero after awaiting shutdown of the 
executor pool


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/31475965
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/31475965
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/31475965

Branch: refs/heads/branch-2
Commit: 314759652f5e41ed149314ab94b8731058d67b73
Parents: 16012f9
Author: Andrew Purtell <apurt...@apache.org>
Authored: Tue Oct 31 11:35:48 2017 -0700
Committer: Andrew Purtell <apurt...@apache.org>
Committed: Tue Oct 31 13:40:55 2017 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/io/hfile/TestLruBlockCache.java    | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/31475965/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
index b4dfc0c..4eec0bf 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestLruBlockCache.java
@@ -32,6 +32,10 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.hadoop.hbase.testclassification.IOTests;
 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;
@@ -56,6 +60,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);
@@ -84,6 +89,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());
     }

Reply via email to