2121import java .util .Objects ;
2222import org .apache .hadoop .hbase .HBaseTestingUtility ;
2323import org .apache .hadoop .hbase .TableName ;
24+ import org .apache .hadoop .hbase .Waiter .ExplainingPredicate ;
2425import org .apache .hadoop .hbase .client .Get ;
2526import org .apache .hadoop .hbase .client .Put ;
2627import org .apache .hadoop .hbase .client .Table ;
@@ -42,7 +43,9 @@ public final class ThrottleQuotaTestUtil {
4243 private final static int REFRESH_TIME = 30 * 60000 ;
4344 static {
4445 envEdge .setValue (EnvironmentEdgeManager .currentTime ());
45- EnvironmentEdgeManagerTestHelper .injectEdge (envEdge );
46+ // only active the envEdge for quotas package
47+ EnvironmentEdgeManagerTestHelper .injectEdgeForPackage (envEdge ,
48+ ThrottleQuotaTestUtil .class .getPackage ().getName ());
4649 }
4750
4851 private ThrottleQuotaTestUtil () {
@@ -135,51 +138,79 @@ private static void triggerCacheRefresh(HBaseTestingUtility testUtil, boolean by
135138 RegionServerRpcQuotaManager quotaManager =
136139 rst .getRegionServer ().getRegionServerRpcQuotaManager ();
137140 QuotaCache quotaCache = quotaManager .getQuotaCache ();
138-
139141 quotaCache .triggerCacheRefresh ();
140- // sleep for cache update
141142 Thread .sleep (250 );
142-
143- for (TableName table : tables ) {
144- quotaCache .getTableLimiter (table );
145- }
146-
147- boolean isUpdated = false ;
148- while (!isUpdated ) {
149- quotaCache .triggerCacheRefresh ();
150- isUpdated = true ;
151- for (TableName table : tables ) {
152- boolean isBypass = true ;
153- if (userLimiter ) {
154- isBypass = quotaCache .getUserLimiter (User .getCurrent ().getUGI (), table ).isBypass ();
143+ testUtil .waitFor (60000 , 250 , new ExplainingPredicate <Exception >() {
144+
145+ @ Override
146+ public boolean evaluate () throws Exception {
147+ boolean isUpdated = true ;
148+ for (TableName table : tables ) {
149+ if (userLimiter ) {
150+ boolean isUserBypass =
151+ quotaCache .getUserLimiter (User .getCurrent ().getUGI (), table ).isBypass ();
152+ if (isUserBypass != bypass ) {
153+ LOG .info (
154+ "User limiter for user={}, table={} not refreshed, bypass expected {}, actual {}" ,
155+ User .getCurrent (), table , bypass , isUserBypass );
156+ envEdge .incValue (100 );
157+ isUpdated = false ;
158+ break ;
159+ }
160+ }
161+ if (tableLimiter ) {
162+ boolean isTableBypass = quotaCache .getTableLimiter (table ).isBypass ();
163+ if (isTableBypass != bypass ) {
164+ LOG .info ("Table limiter for table={} not refreshed, bypass expected {}, actual {}" ,
165+ table , bypass , isTableBypass );
166+ envEdge .incValue (100 );
167+ isUpdated = false ;
168+ break ;
169+ }
170+ }
171+ if (nsLimiter ) {
172+ boolean isNsBypass =
173+ quotaCache .getNamespaceLimiter (table .getNamespaceAsString ()).isBypass ();
174+ if (isNsBypass != bypass ) {
175+ LOG .info (
176+ "Namespace limiter for namespace={} not refreshed, bypass expected {}, actual {}" ,
177+ table .getNamespaceAsString (), bypass , isNsBypass );
178+ envEdge .incValue (100 );
179+ isUpdated = false ;
180+ break ;
181+ }
182+ }
155183 }
156- if (tableLimiter ) {
157- isBypass &= quotaCache .getTableLimiter (table ).isBypass ();
184+ if (rsLimiter ) {
185+ boolean rsIsBypass = quotaCache
186+ .getRegionServerQuotaLimiter (QuotaTableUtil .QUOTA_REGION_SERVER_ROW_KEY ).isBypass ();
187+ if (rsIsBypass != bypass ) {
188+ LOG .info ("RegionServer limiter not refreshed, bypass expected {}, actual {}" , bypass ,
189+ rsIsBypass );
190+ envEdge .incValue (100 );
191+ isUpdated = false ;
192+ }
158193 }
159- if (nsLimiter ) {
160- isBypass &= quotaCache .getNamespaceLimiter (table .getNamespaceAsString ()).isBypass ();
194+ if (exceedThrottleQuota ) {
195+ if (quotaCache .isExceedThrottleQuotaEnabled () != bypass ) {
196+ LOG .info ("ExceedThrottleQuotaEnabled not refreshed, bypass expected {}, actual {}" ,
197+ bypass , quotaCache .isExceedThrottleQuotaEnabled ());
198+ envEdge .incValue (100 );
199+ isUpdated = false ;
200+ }
161201 }
162- if (isBypass != bypass ) {
163- envEdge .incValue (100 );
164- isUpdated = false ;
165- break ;
202+ if (isUpdated ) {
203+ return true ;
166204 }
205+ quotaCache .triggerCacheRefresh ();
206+ return false ;
167207 }
168- if (rsLimiter ) {
169- boolean rsIsBypass = quotaCache
170- .getRegionServerQuotaLimiter (QuotaTableUtil .QUOTA_REGION_SERVER_ROW_KEY ).isBypass ();
171- if (rsIsBypass != bypass ) {
172- envEdge .incValue (100 );
173- isUpdated = false ;
174- }
175- }
176- if (exceedThrottleQuota ) {
177- if (quotaCache .isExceedThrottleQuotaEnabled () != bypass ) {
178- envEdge .incValue (100 );
179- isUpdated = false ;
180- }
208+
209+ @ Override
210+ public String explainFailure () throws Exception {
211+ return "Quota cache is still not refreshed" ;
181212 }
182- }
213+ });
183214
184215 LOG .debug ("QuotaCache" );
185216 LOG .debug (Objects .toString (quotaCache .getNamespaceQuotaCache ()));
0 commit comments