gortiz commented on code in PR #14226: URL: https://github.com/apache/pinot/pull/14226#discussion_r1808478935
########## 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 see that what you are doing here is precisely to call a method with package visibility. As said in the other discussion, I strongly think we need to find new ways to run tests without sleeping threads, but whether the way you suggest here is the correct approach is something we would need to discuss. Therefore I encourage you to modify this PR to remove this new feature and just use sleep in your tests in order to reduce the complexity of the PR and be able to merge it soon. In the short/medium term we can discuss how to improve these tests in another PR. -- 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