use of io.github.resilience4j.ratelimiter.RateLimiterConfig in project resilience4j by resilience4j.
the class AtomicRateLimiterTest method changeDefaultTimeoutDuration.
@Test
public void changeDefaultTimeoutDuration() throws Exception {
RateLimiterConfig rateLimiterConfig = rateLimiter.getRateLimiterConfig();
then(rateLimiterConfig.getTimeoutDuration()).isEqualTo(Duration.ZERO);
then(rateLimiterConfig.getTimeoutDurationInNanos()).isEqualTo(0L);
then(rateLimiterConfig.getLimitForPeriod()).isEqualTo(PERMISSIONS_RER_CYCLE);
then(rateLimiterConfig.getLimitRefreshPeriod()).isEqualTo(Duration.ofNanos(CYCLE_IN_NANOS));
then(rateLimiterConfig.getLimitRefreshPeriodInNanos()).isEqualTo(CYCLE_IN_NANOS);
rateLimiter.changeTimeoutDuration(Duration.ofSeconds(1));
then(rateLimiterConfig != rateLimiter.getRateLimiterConfig()).isTrue();
rateLimiterConfig = rateLimiter.getRateLimiterConfig();
then(rateLimiterConfig.getTimeoutDuration()).isEqualTo(Duration.ofSeconds(1));
then(rateLimiterConfig.getTimeoutDurationInNanos()).isEqualTo(Duration.ofSeconds(1).toNanos());
then(rateLimiterConfig.getLimitForPeriod()).isEqualTo(PERMISSIONS_RER_CYCLE);
then(rateLimiterConfig.getLimitRefreshPeriod()).isEqualTo(Duration.ofNanos(CYCLE_IN_NANOS));
then(rateLimiterConfig.getLimitRefreshPeriodInNanos()).isEqualTo(CYCLE_IN_NANOS);
}
use of io.github.resilience4j.ratelimiter.RateLimiterConfig in project resilience4j by resilience4j.
the class AtomicRateLimiterTest method changeLimitForPeriod.
@Test
public void changeLimitForPeriod() throws Exception {
RateLimiterConfig rateLimiterConfig = rateLimiter.getRateLimiterConfig();
then(rateLimiterConfig.getTimeoutDuration()).isEqualTo(Duration.ZERO);
then(rateLimiterConfig.getTimeoutDurationInNanos()).isEqualTo(0L);
then(rateLimiterConfig.getLimitForPeriod()).isEqualTo(PERMISSIONS_RER_CYCLE);
then(rateLimiterConfig.getLimitRefreshPeriod()).isEqualTo(Duration.ofNanos(CYCLE_IN_NANOS));
then(rateLimiterConfig.getLimitRefreshPeriodInNanos()).isEqualTo(CYCLE_IN_NANOS);
rateLimiter.changeLimitForPeriod(35);
then(rateLimiterConfig != rateLimiter.getRateLimiterConfig()).isTrue();
rateLimiterConfig = rateLimiter.getRateLimiterConfig();
then(rateLimiterConfig.getTimeoutDuration()).isEqualTo(Duration.ZERO);
then(rateLimiterConfig.getTimeoutDurationInNanos()).isEqualTo(0L);
then(rateLimiterConfig.getLimitForPeriod()).isEqualTo(35);
then(rateLimiterConfig.getLimitRefreshPeriod()).isEqualTo(Duration.ofNanos(CYCLE_IN_NANOS));
then(rateLimiterConfig.getLimitRefreshPeriodInNanos()).isEqualTo(CYCLE_IN_NANOS);
}
use of io.github.resilience4j.ratelimiter.RateLimiterConfig in project resilience4j by resilience4j.
the class InMemoryRateLimiterRegistryTest method rateLimiterNewWithNullNonDefaultConfig.
@Test
public void rateLimiterNewWithNullNonDefaultConfig() throws Exception {
exception.expect(NullPointerException.class);
exception.expectMessage(CONFIG_MUST_NOT_BE_NULL);
RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(config);
RateLimiterConfig rateLimiterConfig = null;
registry.rateLimiter("name", rateLimiterConfig);
}
use of io.github.resilience4j.ratelimiter.RateLimiterConfig in project resilience4j by resilience4j.
the class InMemoryRateLimiterRegistryTest method rateLimiterNewWithNullConfigSupplier.
@Test
public void rateLimiterNewWithNullConfigSupplier() throws Exception {
exception.expect(NullPointerException.class);
exception.expectMessage("Supplier must not be null");
RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(config);
Supplier<RateLimiterConfig> rateLimiterConfigSupplier = null;
registry.rateLimiter("name", rateLimiterConfigSupplier);
}
use of io.github.resilience4j.ratelimiter.RateLimiterConfig in project resilience4j by resilience4j.
the class InMemoryRateLimiterRegistryTest method rateLimiterPositiveWithSupplier.
@Test
@SuppressWarnings("unchecked")
public void rateLimiterPositiveWithSupplier() throws Exception {
RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(config);
Supplier<RateLimiterConfig> rateLimiterConfigSupplier = mock(Supplier.class);
when(rateLimiterConfigSupplier.get()).thenReturn(config);
RateLimiter firstRateLimiter = registry.rateLimiter("test", rateLimiterConfigSupplier);
verify(rateLimiterConfigSupplier, times(1)).get();
RateLimiter sameAsFirst = registry.rateLimiter("test", rateLimiterConfigSupplier);
verify(rateLimiterConfigSupplier, times(1)).get();
RateLimiter anotherLimit = registry.rateLimiter("test1", rateLimiterConfigSupplier);
verify(rateLimiterConfigSupplier, times(2)).get();
then(firstRateLimiter).isEqualTo(sameAsFirst);
then(firstRateLimiter).isNotEqualTo(anotherLimit);
}
Aggregations