Search in sources :

Example 1 with RateLimiterConfig

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);
}
Also used : RateLimiterConfig(io.github.resilience4j.ratelimiter.RateLimiterConfig) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with RateLimiterConfig

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);
}
Also used : RateLimiterConfig(io.github.resilience4j.ratelimiter.RateLimiterConfig) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with RateLimiterConfig

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);
}
Also used : RateLimiterConfig(io.github.resilience4j.ratelimiter.RateLimiterConfig) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) Test(org.junit.Test)

Example 4 with 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);
}
Also used : RateLimiterConfig(io.github.resilience4j.ratelimiter.RateLimiterConfig) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) Test(org.junit.Test)

Example 5 with RateLimiterConfig

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);
}
Also used : RateLimiterConfig(io.github.resilience4j.ratelimiter.RateLimiterConfig) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) RateLimiter(io.github.resilience4j.ratelimiter.RateLimiter) Test(org.junit.Test)

Aggregations

RateLimiterConfig (io.github.resilience4j.ratelimiter.RateLimiterConfig)20 Test (org.junit.Test)12 RateLimiter (io.github.resilience4j.ratelimiter.RateLimiter)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 RateLimiterRegistry (io.github.resilience4j.ratelimiter.RateLimiterRegistry)4 RequestNotPermitted (io.github.resilience4j.ratelimiter.RequestNotPermitted)2 Duration (java.time.Duration)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Inject (com.google.inject.Inject)1 AtomicRateLimiter (io.github.resilience4j.ratelimiter.internal.AtomicRateLimiter)1 RateLimiterOperator (io.github.resilience4j.ratelimiter.operator.RateLimiterOperator)1 RecoveryFunction (io.github.resilience4j.ratpack.recovery.RecoveryFunction)1 Flowable (io.reactivex.Flowable)1 Observable (io.reactivex.Observable)1 Single (io.reactivex.Single)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)1 MethodInvocation (org.aopalliance.intercept.MethodInvocation)1