Search in sources :

Example 1 with TimeLimiterRegistry

use of io.github.resilience4j.timelimiter.TimeLimiterRegistry in project resilience4j by resilience4j.

the class TimeLimiterMetricsTest method given.

@Override
protected TimeLimiter given(String prefix, MetricRegistry metricRegistry) {
    TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults();
    TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter("testLimit");
    metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiterRegistry(prefix, timeLimiterRegistry));
    return timeLimiter;
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry)

Example 2 with TimeLimiterRegistry

use of io.github.resilience4j.timelimiter.TimeLimiterRegistry in project resilience4j by resilience4j.

the class TaggedTimeLimiterMetricsTest method customMetricNamesGetApplied.

@Test
public void customMetricNamesGetApplied() {
    MeterRegistry meterRegistry = new SimpleMeterRegistry();
    TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.ofDefaults();
    timeLimiterRegistry.timeLimiter("backendA");
    TaggedTimeLimiterMetrics.ofTimeLimiterRegistry(TimeLimiterMetricNames.custom().callsMetricName("custom_calls").build(), timeLimiterRegistry).bindTo(meterRegistry);
    Set<String> metricNames = meterRegistry.getMeters().stream().map(Meter::getId).map(Meter.Id::getName).collect(Collectors.toSet());
    assertThat(metricNames).hasSameElementsAs(Arrays.asList("custom_calls"));
}
Also used : TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) Meter(io.micrometer.core.instrument.Meter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.Test)

Example 3 with TimeLimiterRegistry

use of io.github.resilience4j.timelimiter.TimeLimiterRegistry in project resilience4j by resilience4j.

the class TimeLimiterConfiguration method timeLimiterRegistry.

@Bean
public TimeLimiterRegistry timeLimiterRegistry(TimeLimiterConfigurationProperties timeLimiterConfigurationProperties, EventConsumerRegistry<TimeLimiterEvent> timeLimiterEventConsumerRegistry, RegistryEventConsumer<TimeLimiter> timeLimiterRegistryEventConsumer, @Qualifier("compositeTimeLimiterCustomizer") CompositeCustomizer<TimeLimiterConfigCustomizer> compositeTimeLimiterCustomizer) {
    TimeLimiterRegistry timeLimiterRegistry = createTimeLimiterRegistry(timeLimiterConfigurationProperties, timeLimiterRegistryEventConsumer, compositeTimeLimiterCustomizer);
    registerEventConsumer(timeLimiterRegistry, timeLimiterEventConsumerRegistry, timeLimiterConfigurationProperties);
    initTimeLimiterRegistry(timeLimiterRegistry, timeLimiterConfigurationProperties, compositeTimeLimiterCustomizer);
    return timeLimiterRegistry;
}
Also used : TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry)

Example 4 with TimeLimiterRegistry

use of io.github.resilience4j.timelimiter.TimeLimiterRegistry in project resilience4j by resilience4j.

the class InMemoryTimeLimiterRegistryTest method timeLimiterPositive.

@Test
public void timeLimiterPositive() {
    TimeLimiterRegistry registry = TimeLimiterRegistry.of(config);
    TimeLimiter firstTimeLimiter = registry.timeLimiter("test");
    TimeLimiter anotherLimit = registry.timeLimiter("test1");
    TimeLimiter sameAsFirst = registry.timeLimiter("test");
    then(firstTimeLimiter).isEqualTo(sameAsFirst);
    then(firstTimeLimiter).isNotEqualTo(anotherLimit);
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) Test(org.junit.Test)

Example 5 with TimeLimiterRegistry

use of io.github.resilience4j.timelimiter.TimeLimiterRegistry in project resilience4j by resilience4j.

the class InMemoryTimeLimiterRegistryTest method timeLimiterNewWithNullNameAndConfigSupplier.

@Test
public void timeLimiterNewWithNullNameAndConfigSupplier() {
    exception.expect(NullPointerException.class);
    exception.expectMessage(NAME_MUST_NOT_BE_NULL);
    TimeLimiterRegistry registry = new InMemoryTimeLimiterRegistry(config);
    registry.timeLimiter(null, () -> config);
}
Also used : TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) Test(org.junit.Test)

Aggregations

TimeLimiterRegistry (io.github.resilience4j.timelimiter.TimeLimiterRegistry)17 Test (org.junit.Test)13 TimeLimiter (io.github.resilience4j.timelimiter.TimeLimiter)8 DefaultEventConsumerRegistry (io.github.resilience4j.consumer.DefaultEventConsumerRegistry)2 TimeLimiterConfig (io.github.resilience4j.timelimiter.TimeLimiterConfig)2 TimeLimiterEvent (io.github.resilience4j.timelimiter.event.TimeLimiterEvent)2 Meter (io.micrometer.core.instrument.Meter)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 Requires (io.micronaut.context.annotation.Requires)1 CollectorRegistry (io.prometheus.client.CollectorRegistry)1 TimeoutException (java.util.concurrent.TimeoutException)1 Singleton (javax.inject.Singleton)1