bziobrowski commented on code in PR #14226:
URL: https://github.com/apache/pinot/pull/14226#discussion_r1808315270


##########
pinot-broker/src/test/java/com/google/common/util/concurrent/TestRateLimiter.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * 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 com.google.common.util.concurrent;
+
+/**
+ * Workaround for package-scope limitation of RateLimiter methods that is 
required for reliable testing.
+ */
+public class TestRateLimiter {
+
+  private TestRateLimiter() {
+  }
+
+  public interface TimeSource {
+    long getMicros();
+
+    void advanceByMillis(long millis);
+
+    void reset();
+  }
+
+  public static class MovableTimeSource implements TimeSource {
+
+    private long _micros;
+
+    public MovableTimeSource() {
+      _micros = System.nanoTime() / 1000;
+    }
+
+    // push time forward at least by 10 second on each run, otherwise rate 
limiter might throttle next acquire()
+    public void reset() {
+      _micros = _micros + 1000001L;
+    }

Review Comment:
   I agree the name is unfortunate but it's a consequence of how rate limiter 
and existing tests work. 
   It turns out rate limiter set to L permits can allow 2 * L requests per 
second if we start testing it at full capacity.
   Tests like HelixExternalViewBased*. first run L queries within a second to 
check that rate is accepted and then immediately test 2*L to go over the limit. 
This reset() method is meant to make rate limiter restore permits at the start 
of second round round.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to