use of es.moki.ratelimitj.core.limiter.request.RequestLimitRule in project ratelimitj by mokies.
the class HazelcastRequestRateLimiterInternalTest method shouldEventuallyCleanUpExpiredKeys.
@Test
void shouldEventuallyCleanUpExpiredKeys() throws Exception {
ImmutableSet<RequestLimitRule> rules = ImmutableSet.of(RequestLimitRule.of(2, TimeUnit.SECONDS, 5));
RequestRateLimiter requestRateLimiter = getRateLimiter(rules, timeBandit);
String key = "ip:127.0.0.5";
IntStream.rangeClosed(1, 5).forEach(value -> {
timeBandit.addUnixTimeMilliSeconds(100L);
assertThat(requestRateLimiter.overLimitWhenIncremented(key)).isFalse();
});
IMap<Object, Object> map = hz.getMap(key);
while (map.size() != 0) {
Thread.sleep(10);
}
assertThat(map.size()).isZero();
}
use of es.moki.ratelimitj.core.limiter.request.RequestLimitRule in project ratelimitj by mokies.
the class RedisRateLimiterFactoryTest method shouldReturnTheSameInstanceForSameSetOfRules.
@Test
void shouldReturnTheSameInstanceForSameSetOfRules() {
RequestLimitRule rule1a = RequestLimitRule.of(1, TimeUnit.MINUTES, 10);
RequestLimitRule rule1b = RequestLimitRule.of(1, TimeUnit.HOURS, 100);
RequestRateLimiter rateLimiter1 = factory.getInstance(ImmutableSet.of(rule1a, rule1b));
RequestLimitRule rule2a = RequestLimitRule.of(1, TimeUnit.MINUTES, 10);
RequestLimitRule rule2b = RequestLimitRule.of(1, TimeUnit.HOURS, 100);
RequestRateLimiter rateLimiter2 = factory.getInstance(ImmutableSet.of(rule2a, rule2b));
assertThat(rateLimiter1).isSameAs(rateLimiter2);
}
use of es.moki.ratelimitj.core.limiter.request.RequestLimitRule in project ratelimitj by mokies.
the class RedisRateLimiterFactoryTest method shouldNotReturnTheSameInstanceForSameRules.
@Test
void shouldNotReturnTheSameInstanceForSameRules() {
RequestLimitRule rule1 = RequestLimitRule.of(1, TimeUnit.MINUTES, 22);
RequestRateLimiter rateLimiter1 = factory.getInstance(ImmutableSet.of(rule1));
RequestLimitRule rule2 = RequestLimitRule.of(1, TimeUnit.MINUTES, 33);
RequestRateLimiter rateLimiter2 = factory.getInstance(ImmutableSet.of(rule2));
assertThat(rateLimiter1).isNotSameAs(rateLimiter2);
}
Aggregations