use of io.github.resilience4j.ratelimiter.RateLimiterRegistry in project resilience4j by resilience4j.
the class RateLimiterMetricsTest method shouldUseCustomPrefix.
@Test
public void shouldUseCustomPrefix() throws Throwable {
// Given
RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.ofDefaults();
RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("testLimit");
metricRegistry.registerAll(RateLimiterMetrics.ofIterable("testPre", rateLimiterRegistry.getAllRateLimiters()));
// Given the HelloWorldService returns Hello world
BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world");
// When
String value = rateLimiter.executeSupplier(helloWorldService::returnHelloWorld);
// Then
assertThat(value).isEqualTo("Hello world");
// Then the helloWorldService should be invoked 1 time
BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld();
assertThat(metricRegistry.getMetrics()).hasSize(2);
assertThat(metricRegistry.getGauges().get("testPre.testLimit.number_of_waiting_threads").getValue()).isEqualTo(0);
assertThat(metricRegistry.getGauges().get("testPre.testLimit.available_permissions").getValue()).isIn(DEFAULT_LIMIT_FOR_PERIOD, DEFAULT_LIMIT_FOR_PERIOD - 1);
}
use of io.github.resilience4j.ratelimiter.RateLimiterRegistry in project resilience4j by resilience4j.
the class InMemoryRateLimiterRegistryTest method rateLimiterNewWithNullNameAndConfigSupplier.
@Test
public void rateLimiterNewWithNullNameAndConfigSupplier() throws Exception {
exception.expect(NullPointerException.class);
exception.expectMessage(NAME_MUST_NOT_BE_NULL);
RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(config);
registry.rateLimiter(null, () -> config);
}
use of io.github.resilience4j.ratelimiter.RateLimiterRegistry in project resilience4j by resilience4j.
the class InMemoryRateLimiterRegistryTest method rateLimiterNewWithNullNameAndNonDefaultConfig.
@Test
public void rateLimiterNewWithNullNameAndNonDefaultConfig() throws Exception {
exception.expect(NullPointerException.class);
exception.expectMessage(NAME_MUST_NOT_BE_NULL);
RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(config);
registry.rateLimiter(null, config);
}
Aggregations