#2622: Let ThrottleTest work independently of real time

This commit is contained in:
killme
2019-04-13 13:18:19 +02:00
committed by md_5
parent 191afb6a6c
commit 9bce83704a
2 changed files with 26 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
package net.md_5.bungee;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ticker;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@@ -13,8 +15,15 @@ public class ConnectionThrottle
private final int throttleLimit;
public ConnectionThrottle(int throttleTime, int throttleLimit)
{
this(Ticker.systemTicker(), throttleTime, throttleLimit);
}
@VisibleForTesting
ConnectionThrottle(Ticker ticker, int throttleTime, int throttleLimit)
{
this.throttle = CacheBuilder.newBuilder()
.ticker(ticker)
.concurrencyLevel( Runtime.getRuntime().availableProcessors() )
.initialCapacity( 100 )
.expireAfterWrite( throttleTime, TimeUnit.MILLISECONDS )