RateLimitingThrottlingStrategy extends ThrottlingStrategy<T> { @Override public CompletionStage<Boolean> accept(ServiceRequestContext ctx, T request) { return completedFuture(rateLimiter.tryAcquire()); } RateLimitingThrottlingStrategy(double requestPerSecond, @Nullable String name);   RateLimitingThrottlingStrategy(double requestPerSecond); @VisibleForTesting  RateLimitingThrottlingStrategy(RateLimiter rateLimiter); @Override CompletionStage<Boolean> accept(ServiceRequestContext ctx, T request);  }
@Test public void rateLimit() { final ThrottlingStrategy<Request> strategy = new RateLimitingThrottlingStrategy<>(rateLimiter); when(rateLimiter.tryAcquire()).thenReturn(true) .thenReturn(false) .thenReturn(true); assertThat(strategy.accept(null, null).toCompletableFuture().join()).isEqualTo(true); assertThat(strategy.accept(null, null).toCompletableFuture().join()).isEqualTo(false); assertThat(strategy.accept(null, null).toCompletableFuture().join()).isEqualTo(true); }