Java Code Examples for io.github.resilience4j.ratelimiter.RateLimiterRegistry#ofDefaults()

The following examples show how to use io.github.resilience4j.ratelimiter.RateLimiterRegistry#ofDefaults() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaggedRateLimiterMetricsTest.java    From resilience4j with Apache License 2.0 6 votes vote down vote up
@Test
public void customMetricNamesGetApplied() {
    MeterRegistry meterRegistry = new SimpleMeterRegistry();
    RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.ofDefaults();
    rateLimiterRegistry.rateLimiter("backendA");
    TaggedRateLimiterMetrics.ofRateLimiterRegistry(
        RateLimiterMetricNames.custom()
            .availablePermissionsMetricName("custom_available_permissions")
            .waitingThreadsMetricName("custom_waiting_threads")
            .build(),
        rateLimiterRegistry
    ).bindTo(meterRegistry);

    Set<String> metricNames = meterRegistry.getMeters()
        .stream()
        .map(Meter::getId)
        .map(Meter.Id::getName)
        .collect(Collectors.toSet());

    assertThat(metricNames).hasSameElementsAs(Arrays.asList(
        "custom_available_permissions",
        "custom_waiting_threads"
    ));
}
 
Example 2
Source File: RateLimiterMetricsCollectorTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    registry = new CollectorRegistry();
    rateLimiterRegistry = RateLimiterRegistry.ofDefaults();
    rateLimiter = rateLimiterRegistry.rateLimiter("backendA");

    RateLimiterMetricsCollector.ofRateLimiterRegistry(rateLimiterRegistry).register(registry);
}
 
Example 3
Source File: TaggedRateLimiterMetricsTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    meterRegistry = new SimpleMeterRegistry();
    rateLimiterRegistry = RateLimiterRegistry.ofDefaults();

    rateLimiter = rateLimiterRegistry.rateLimiter("backendA");
    taggedRateLimiterMetrics = TaggedRateLimiterMetrics
        .ofRateLimiterRegistry(rateLimiterRegistry);
    taggedRateLimiterMetrics.bindTo(meterRegistry);
}
 
Example 4
Source File: RateLimiterMetricsTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected RateLimiter givenMetricRegistry(String prefix, MetricRegistry metricRegistry) {
    RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.ofDefaults();
    RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("testLimit");
    metricRegistry.registerAll(
        RateLimiterMetrics.ofIterable(prefix, rateLimiterRegistry.getAllRateLimiters()));

    return rateLimiter;
}
 
Example 5
Source File: RateLimiterMetricsTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected RateLimiter givenMetricRegistry(MetricRegistry metricRegistry) {
    RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.ofDefaults();
    RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("testLimit");
    metricRegistry.registerAll(RateLimiterMetrics.ofRateLimiterRegistry(rateLimiterRegistry));

    return rateLimiter;
}
 
Example 6
Source File: RateLimiterConfigurationSpringTest.java    From resilience4j with Apache License 2.0 4 votes vote down vote up
@Bean
public RateLimiterRegistry rateLimiterRegistry() {
    rateLimiterRegistry = RateLimiterRegistry.ofDefaults();
    return rateLimiterRegistry;
}