13
0
geforkt von Mirrors/Velocity

Add ratelimit tests

Dieser Commit ist enthalten in:
MatrixTunnel 2018-08-10 18:57:10 -07:00
Ursprung d752edc92d
Commit 6e4f90dfae

Datei anzeigen

@ -12,7 +12,14 @@ import static org.junit.jupiter.api.Assertions.*;
class RatelimiterTest { class RatelimiterTest {
@Test @Test
void attempt() { void attemptZero() {
Ratelimiter noRatelimiter = new Ratelimiter(0);
assertTrue(noRatelimiter.attempt(InetAddress.getLoopbackAddress()));
assertTrue(noRatelimiter.attempt(InetAddress.getLoopbackAddress()));
}
@Test
void attemptOne() {
long base = System.nanoTime(); long base = System.nanoTime();
AtomicLong extra = new AtomicLong(); AtomicLong extra = new AtomicLong();
Ticker testTicker = new Ticker() { Ticker testTicker = new Ticker() {
@ -27,4 +34,5 @@ class RatelimiterTest {
extra.addAndGet(TimeUnit.SECONDS.toNanos(2)); extra.addAndGet(TimeUnit.SECONDS.toNanos(2));
assertTrue(ratelimiter.attempt(InetAddress.getLoopbackAddress())); assertTrue(ratelimiter.attempt(InetAddress.getLoopbackAddress()));
} }
} }