Lines Matching defs:limiter
54 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
55 limiter.acquire(); // R0.00, since it's the first request
56 limiter.acquire(); // R0.20
57 limiter.acquire(); // R0.20
68 RateLimiter limiter = RateLimiter.create(5.0, 5, SECONDS);
69 assertEquals(5.0, limiter.getRate());
70 limiter.setRate(10.0);
71 assertEquals(10.0, limiter.getRate());
74 limiter.setRate(0.0);
78 limiter.setRate(-10.0);
84 RateLimiter limiter = RateLimiter.create(999);
86 limiter.acquire(0);
91 limiter.acquire(-1);
96 limiter.tryAcquire(0);
101 limiter.tryAcquire(-1);
106 limiter.tryAcquire(0, 1, SECONDS);
111 limiter.tryAcquire(-1, 1, SECONDS);
118 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
119 limiter.acquire(); // R0.00
121 limiter.acquire(); // R0.00, ...which is granted immediately
122 limiter.acquire(); // R0.20
127 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
128 assertEquals(0.0, limiter.acquire(), EPSILON); // R0.00
130 assertEquals(0.0, limiter.acquire(), EPSILON); // R0.00, ...which is granted immediately
131 assertEquals(0.2, limiter.acquire(), EPSILON); // R0.20
136 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
137 assertEquals(0.0, limiter.acquire(), EPSILON);
139 assertEquals(0.0, limiter.acquire(), EPSILON);
140 assertEquals(0.0, limiter.acquire(), EPSILON);
141 assertEquals(0.2, limiter.acquire(), EPSILON);
145 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
148 limiter.acquire(1); // R0.00, since it's the first request
150 limiter.acquire(1); // R0.00, from capacity
151 limiter.acquire(3); // R0.00, from capacity
152 limiter.acquire(1); // R0.00, concluding a burst of 5 permits
154 limiter.acquire(); // R0.20, capacity exhausted
178 RateLimiter limiter = RateLimiter.create(stopwatch, 2.0, 4000, MILLISECONDS);
180 limiter.acquire(); // #1
185 limiter.acquire(); // // #4
190 limiter.acquire(); // #7
203 RateLimiter limiter = RateLimiter.create(stopwatch, 2.0, 4000, MILLISECONDS);
205 limiter.acquire(); // // #1
209 limiter.acquire(); // #3
212 limiter.setRate(4.0); // double the rate!
213 limiter.acquire(); // #4, we repay the debt of the last acquire (imposed by the old rate)
215 limiter.acquire(); // #5
219 limiter.acquire(); // #7, showing off the warmup starting from totally cold
249 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
250 assertTrue(limiter.tryAcquire(0, SECONDS));
251 assertFalse(limiter.tryAcquire(0, SECONDS));
252 assertFalse(limiter.tryAcquire(0, SECONDS));
254 assertFalse(limiter.tryAcquire(0, SECONDS));
258 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
259 assertTrue(limiter.tryAcquire(0, SECONDS));
260 assertTrue(limiter.tryAcquire(200, MILLISECONDS));
261 assertFalse(limiter.tryAcquire(100, MILLISECONDS));
263 assertTrue(limiter.tryAcquire(100, MILLISECONDS));
267 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
268 assertTrue(limiter.tryAcquire(0, MICROSECONDS));
270 assertTrue(limiter.tryAcquire(Long.MAX_VALUE, MICROSECONDS));
274 RateLimiter limiter = RateLimiter.create(stopwatch, 5.0);
275 assertTrue(limiter.tryAcquire(5, 0, SECONDS));
277 assertFalse(limiter.tryAcquire(1, Long.MIN_VALUE, SECONDS));
279 assertTrue(limiter.tryAcquire(1, -1, SECONDS));
294 RateLimiter limiter = RateLimiter.create(stopwatch, Double.POSITIVE_INFINITY);
295 limiter.acquire(Integer.MAX_VALUE / 4);
296 limiter.acquire(Integer.MAX_VALUE / 2);
297 limiter.acquire(Integer.MAX_VALUE);
300 limiter.setRate(2.0);
301 limiter.acquire();
302 limiter.acquire();
303 limiter.acquire();
304 limiter.acquire();
305 limiter.acquire();
313 limiter.setRate(Double.POSITIVE_INFINITY);
314 limiter.acquire();
315 limiter.acquire();
316 limiter.acquire();
322 RateLimiter limiter = RateLimiter.create(stopwatch, Double.POSITIVE_INFINITY);
324 limiter.setRate(2.0);
326 limiter.acquire();
337 RateLimiter limiter = RateLimiter.create(
339 limiter.acquire(Integer.MAX_VALUE / 4);
340 limiter.acquire(Integer.MAX_VALUE / 2);
341 limiter.acquire(Integer.MAX_VALUE);
344 limiter.setRate(1.0);
345 limiter.acquire();
346 limiter.acquire();
347 limiter.acquire();
350 limiter.setRate(Double.POSITIVE_INFINITY);
351 limiter.acquire();
352 limiter.acquire();
353 limiter.acquire();
358 RateLimiter limiter = RateLimiter.create(stopwatch, Double.POSITIVE_INFINITY, 10, SECONDS);
360 limiter.setRate(1.0);
362 limiter.acquire();
372 RateLimiter limiter = RateLimiter.create(stopwatch, 1.0);
377 limiter.setRate(rate);
378 long burst = measureTotalTimeMillis(limiter, oneSecWorthOfWork, new Random());
381 long afterBurst = measureTotalTimeMillis(limiter, oneSecWorthOfWork, new Random());