From 19ad3d66547fe7ebf68ca4cec23c6ccdccf692b9 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 7 Mar 2022 08:16:21 +0800 Subject: [PATCH] HBASE-26805 Addendum forward port the test improvements in HBASE-26304 for branch-2 --- .../TestRegionHDFSBlockLocationFinder.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRegionHDFSBlockLocationFinder.java b/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRegionHDFSBlockLocationFinder.java index b98dccf062e..807b5ff35f8 100644 --- a/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRegionHDFSBlockLocationFinder.java +++ b/hbase-balancer/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRegionHDFSBlockLocationFinder.java @@ -231,9 +231,17 @@ public class TestRegionHDFSBlockLocationFinder { finder.setClusterMetrics(getMetricsWithLocality(testServer, testRegion.getRegionName(), 0.345f)); - // there is no way to test whether the refresh for a guava cache is finished, so here we just - // add a one second sleep, usually this is enough for the refresh - Thread.sleep(1000); + + // cache refresh happens in a background thread, so we need to wait for the value to + // update before running assertions. + long now = System.currentTimeMillis(); + HDFSBlocksDistribution cached = cache.get(testRegion); + HDFSBlocksDistribution newValue; + do { + Thread.sleep(1_000); + newValue = finder.getBlockDistribution(testRegion); + } while (cached == newValue && System.currentTimeMillis() - now < 30_000); + // locality changed just for our test region, so it should no longer be the same for (RegionInfo region : REGIONS) { HDFSBlocksDistribution hbd = finder.getBlockDistribution(region);