diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/ThrottleQuotaTestUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/ThrottleQuotaTestUtil.java index a6e93b663c04..de6f5653ad2c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/ThrottleQuotaTestUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/ThrottleQuotaTestUtil.java @@ -21,6 +21,7 @@ import java.util.Objects; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.Waiter.ExplainingPredicate; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; @@ -137,51 +138,79 @@ private static void triggerCacheRefresh(HBaseTestingUtil testUtil, boolean bypas RegionServerRpcQuotaManager quotaManager = rst.getRegionServer().getRegionServerRpcQuotaManager(); QuotaCache quotaCache = quotaManager.getQuotaCache(); - quotaCache.triggerCacheRefresh(); - // sleep for cache update Thread.sleep(250); - - for (TableName table : tables) { - quotaCache.getTableLimiter(table); - } - - boolean isUpdated = false; - while (!isUpdated) { - quotaCache.triggerCacheRefresh(); - isUpdated = true; - for (TableName table : tables) { - boolean isBypass = true; - if (userLimiter) { - isBypass = quotaCache.getUserLimiter(User.getCurrent().getUGI(), table).isBypass(); + testUtil.waitFor(60000, 250, new ExplainingPredicate() { + + @Override + public boolean evaluate() throws Exception { + boolean isUpdated = true; + for (TableName table : tables) { + if (userLimiter) { + boolean isUserBypass = + quotaCache.getUserLimiter(User.getCurrent().getUGI(), table).isBypass(); + if (isUserBypass != bypass) { + LOG.info( + "User limiter for user={}, table={} not refreshed, bypass expected {}, actual {}", + User.getCurrent(), table, bypass, isUserBypass); + envEdge.incValue(100); + isUpdated = false; + break; + } + } + if (tableLimiter) { + boolean isTableBypass = quotaCache.getTableLimiter(table).isBypass(); + if (isTableBypass != bypass) { + LOG.info("Table limiter for table={} not refreshed, bypass expected {}, actual {}", + table, bypass, isTableBypass); + envEdge.incValue(100); + isUpdated = false; + break; + } + } + if (nsLimiter) { + boolean isNsBypass = + quotaCache.getNamespaceLimiter(table.getNamespaceAsString()).isBypass(); + if (isNsBypass != bypass) { + LOG.info( + "Namespace limiter for namespace={} not refreshed, bypass expected {}, actual {}", + table.getNamespaceAsString(), bypass, isNsBypass); + envEdge.incValue(100); + isUpdated = false; + break; + } + } } - if (tableLimiter) { - isBypass &= quotaCache.getTableLimiter(table).isBypass(); + if (rsLimiter) { + boolean rsIsBypass = quotaCache + .getRegionServerQuotaLimiter(QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY).isBypass(); + if (rsIsBypass != bypass) { + LOG.info("RegionServer limiter not refreshed, bypass expected {}, actual {}", bypass, + rsIsBypass); + envEdge.incValue(100); + isUpdated = false; + } } - if (nsLimiter) { - isBypass &= quotaCache.getNamespaceLimiter(table.getNamespaceAsString()).isBypass(); + if (exceedThrottleQuota) { + if (quotaCache.isExceedThrottleQuotaEnabled() != bypass) { + LOG.info("ExceedThrottleQuotaEnabled not refreshed, bypass expected {}, actual {}", + bypass, quotaCache.isExceedThrottleQuotaEnabled()); + envEdge.incValue(100); + isUpdated = false; + } } - if (isBypass != bypass) { - envEdge.incValue(100); - isUpdated = false; - break; + if (isUpdated) { + return true; } + quotaCache.triggerCacheRefresh(); + return false; } - if (rsLimiter) { - boolean rsIsBypass = quotaCache - .getRegionServerQuotaLimiter(QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY).isBypass(); - if (rsIsBypass != bypass) { - envEdge.incValue(100); - isUpdated = false; - } - } - if (exceedThrottleQuota) { - if (quotaCache.isExceedThrottleQuotaEnabled() != bypass) { - envEdge.incValue(100); - isUpdated = false; - } + + @Override + public String explainFailure() throws Exception { + return "Quota cache is still not refreshed"; } - } + }); LOG.debug("QuotaCache"); LOG.debug(Objects.toString(quotaCache.getNamespaceQuotaCache()));