From 0da9f7d66877694dd2870ef41ef81ea880a9e572 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Sun, 21 Dec 2025 22:33:13 +0800 Subject: [PATCH] HBASE-29793 TestDefaultHandlerUsageQuota fails 100% on flaky dashboard --- .../quotas/TestDefaultHandlerUsageQuota.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestDefaultHandlerUsageQuota.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestDefaultHandlerUsageQuota.java index 52ee9f1dd7c0..dd7f16fc2032 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestDefaultHandlerUsageQuota.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestDefaultHandlerUsageQuota.java @@ -17,10 +17,11 @@ */ package org.apache.hadoop.hbase.quotas; +import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh; + import java.io.IOException; import java.util.UUID; import java.util.concurrent.TimeUnit; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -31,24 +32,21 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestDefaultHandlerUsageQuota { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestDefaultHandlerUsageQuota.class); + private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final TableName TABLE_NAME = TableName.valueOf(UUID.randomUUID().toString()); - private static final int REFRESH_TIME = 5; private static final byte[] FAMILY = Bytes.toBytes("cf"); private static final byte[] QUALIFIER = Bytes.toBytes("q"); - @AfterClass + @AfterAll public static void tearDown() throws Exception { ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL); EnvironmentEdgeManager.reset(); @@ -56,11 +54,10 @@ public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { // quotas enabled, using block bytes scanned TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true); - TEST_UTIL.getConfiguration().setInt(QuotaCache.REFRESH_CONF_KEY, REFRESH_TIME); // Set default to very strict TEST_UTIL.getConfiguration() .setInt(QuotaUtil.QUOTA_DEFAULT_USER_MACHINE_REQUEST_HANDLER_USAGE_MS, 10); @@ -73,6 +70,9 @@ public static void setUp() throws Exception { TEST_UTIL.createTable(TABLE_NAME, FAMILY); TEST_UTIL.waitTableAvailable(TABLE_NAME); TEST_UTIL.flush(TABLE_NAME); + // increase the tick so we can calculate a positive rpc request time, and then consume all the + // available quota and make request fail next time + ThrottleQuotaTestUtil.envEdge.setValue(System.currentTimeMillis() + 1000); } @Test @@ -90,11 +90,13 @@ public void testDefaultHandlerUsageLimits() throws Exception { TEST_UTIL.waitFor(60_000, () -> runPutTest(100) < 100); } - private void configureLenientThrottle() throws IOException { + private void configureLenientThrottle() throws Exception { try (Admin admin = TEST_UTIL.getAdmin()) { admin.setQuota(QuotaSettingsFactory.throttleUser(getUserName(), - ThrottleType.REQUEST_HANDLER_USAGE_MS, 100_000, TimeUnit.SECONDS)); + ThrottleType.REQUEST_HANDLER_USAGE_MS, 100_000_000, TimeUnit.SECONDS)); } + triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAME); + ThrottleQuotaTestUtil.envEdge.setValue(System.currentTimeMillis() + 1000); } private static String getUserName() throws IOException { @@ -105,6 +107,8 @@ private void unsetQuota() throws Exception { try (Admin admin = TEST_UTIL.getAdmin()) { admin.setQuota(QuotaSettingsFactory.unthrottleUser(getUserName())); } + triggerUserCacheRefresh(TEST_UTIL, false, TABLE_NAME); + ThrottleQuotaTestUtil.envEdge.setValue(System.currentTimeMillis() + 1000); } private long runPutTest(int attempts) throws Exception {