Last active
August 29, 2015 14:07
-
-
Save jsanda/4cb39f5119bb85f94ce5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class RateLimitTest { | |
| @Test | |
| public void throttle() { | |
| RateLimiter rateLimiter = RateLimiter.create(5, 5, TimeUnit.SECONDS); | |
| for (int i = 0; i < 25; ++i) { | |
| rateLimiter.acquire(); | |
| System.out.println("i = " + i); | |
| } | |
| rateLimiter.setRate(1); | |
| for (int i = 25; i < 50; ++i) { | |
| rateLimiter.acquire(); | |
| System.out.println("i = " + i); | |
| } | |
| rateLimiter = RateLimiter.create(5, 10, TimeUnit.SECONDS); | |
| for (int i = 51; i < 100; ++i) { | |
| rateLimiter.acquire(); | |
| System.out.println("i = " + i); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This test exhibits the behavior I expected. The output is noticeably faster after a few second until i == 25, at which point the output is much slower. Once i == 51 though, the output does start to speed back up. I think this will work for ramping back up.