-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ray Mattingly
committed
Feb 16, 2024
1 parent
0ed0d5f
commit b603cb3
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.quotas; | ||
|
||
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.waitMinuteQuota; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.apache.hadoop.hbase.testclassification.RegionServerTests; | ||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.junit.After; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category({ RegionServerTests.class, MediumTests.class }) | ||
public class TestQuotaCache { | ||
|
||
private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); | ||
private static final int REFRESH_TIME = 30_000; | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL); | ||
EnvironmentEdgeManager.reset(); | ||
TEST_UTIL.shutdownMiniCluster(); | ||
} | ||
|
||
@BeforeClass | ||
public static void setUpBeforeClass() throws Exception { | ||
TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true); | ||
TEST_UTIL.getConfiguration().setInt(QuotaCache.REFRESH_CONF_KEY, REFRESH_TIME); | ||
TEST_UTIL.getConfiguration().setInt(QuotaUtil.QUOTA_DEFAULT_USER_MACHINE_READ_NUM, 1000); | ||
|
||
TEST_UTIL.startMiniCluster(1); | ||
TEST_UTIL.waitTableAvailable(QuotaTableUtil.QUOTA_TABLE_NAME); | ||
} | ||
|
||
@Test | ||
public void testDefaultUserRefreshFrequency() throws Exception { | ||
QuotaCache.TEST_BLOCK_REFRESH = true; | ||
|
||
QuotaCache quotaCache = | ||
ThrottleQuotaTestUtil.getQuotaCaches(TEST_UTIL).stream().findAny().get(); | ||
UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); | ||
|
||
UserQuotaState userQuotaState = quotaCache.getUserQuotaState(ugi); | ||
assertEquals(userQuotaState.getLastUpdate(), 0); | ||
|
||
QuotaCache.TEST_BLOCK_REFRESH = false; | ||
// new user should have refreshed immediately | ||
TEST_UTIL.waitFor(5_000, () -> userQuotaState.getLastUpdate() != 0); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
long lastUpdate = userQuotaState.getLastUpdate(); | ||
|
||
// refresh should not apply to recently refreshed quota | ||
quotaCache.triggerCacheRefresh(); | ||
This comment has been minimized.
Sorry, something went wrong.
bbeaudreault
Contributor
|
||
Thread.sleep(250); | ||
long newLastUpdate = userQuotaState.getLastUpdate(); | ||
assertEquals(lastUpdate, newLastUpdate); | ||
|
||
quotaCache.triggerCacheRefresh(); | ||
waitMinuteQuota(); | ||
// should refresh after time has passed | ||
TEST_UTIL.waitFor(5_000, () -> lastUpdate != userQuotaState.getLastUpdate()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
is there a rhyme or reason for this wait time of 5s? looks like the refresh period is 30s. since you set TEST_BLOCK_REFRESH to false after calling getUserQuotaState, it's theoretically possible that the immediate refresh might have triggered and been skipped