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);
}
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");
}
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);
}
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);
}
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);
}
Aggregations