Search in sources :

Example 1 with RateLimiterRegistry

use of io.github.resilience4j.ratelimiter.RateLimiterRegistry 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 2 with RateLimiterRegistry

use of io.github.resilience4j.ratelimiter.RateLimiterRegistry in project resilience4j by resilience4j.

the class InMemoryRateLimiterRegistryTest method rateLimiterGetAllRateLimiters.

@Test
public void rateLimiterGetAllRateLimiters() {
    RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(config);
    registry.rateLimiter("foo");
    assertThat(registry.getAllRateLimiters().size()).isEqualTo(1);
    assertThat(registry.getAllRateLimiters().get(0).getName()).isEqualTo("foo");
}
Also used : RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) Test(org.junit.Test)

Example 3 with RateLimiterRegistry

use of io.github.resilience4j.ratelimiter.RateLimiterRegistry in project resilience4j by resilience4j.

the class InMemoryRateLimiterRegistryTest method rateLimiterNewWithNullName.

@Test
public void rateLimiterNewWithNullName() throws Exception {
    exception.expect(NullPointerException.class);
    exception.expectMessage(NAME_MUST_NOT_BE_NULL);
    RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(config);
    registry.rateLimiter(null);
}
Also used : RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) Test(org.junit.Test)

Example 4 with RateLimiterRegistry

use of io.github.resilience4j.ratelimiter.RateLimiterRegistry 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 RateLimiterRegistry

use of io.github.resilience4j.ratelimiter.RateLimiterRegistry 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

RateLimiterRegistry (io.github.resilience4j.ratelimiter.RateLimiterRegistry)13 Test (org.junit.Test)12 RateLimiter (io.github.resilience4j.ratelimiter.RateLimiter)5 RateLimiterConfig (io.github.resilience4j.ratelimiter.RateLimiterConfig)3 InMemoryRateLimiterRegistry (io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry)2 Meter (io.micrometer.core.instrument.Meter)1 Bean (org.springframework.context.annotation.Bean)1