Search in sources :

Example 11 with TimeLimiterRegistry

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

the class TimeLimiterMetricsTest method given.

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

Example 12 with TimeLimiterRegistry

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

the class TaggedTimeLimiterMetricsPublisherTest method customMetricNamesGetApplied.

@Test
public void customMetricNamesGetApplied() {
    MeterRegistry meterRegistry = new SimpleMeterRegistry();
    TaggedTimeLimiterMetricsPublisher taggedTimeLimiterMetricsPublisher = new TaggedTimeLimiterMetricsPublisher(TimeLimiterMetricNames.custom().callsMetricName("custom_calls").build(), meterRegistry);
    TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.of(TimeLimiterConfig.ofDefaults(), taggedTimeLimiterMetricsPublisher);
    timeLimiterRegistry.timeLimiter("backendA");
    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 13 with TimeLimiterRegistry

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

the class InMemoryTimeLimiterRegistryTest method timeLimiterPositiveWithSupplier.

@Test
@SuppressWarnings("unchecked")
public void timeLimiterPositiveWithSupplier() {
    TimeLimiterRegistry registry = new InMemoryTimeLimiterRegistry(config);
    Supplier<TimeLimiterConfig> timeLimiterConfigSupplier = mock(Supplier.class);
    given(timeLimiterConfigSupplier.get()).willReturn(config);
    TimeLimiter firstTimeLimiter = registry.timeLimiter("test", timeLimiterConfigSupplier);
    verify(timeLimiterConfigSupplier, times(1)).get();
    TimeLimiter sameAsFirst = registry.timeLimiter("test", timeLimiterConfigSupplier);
    verify(timeLimiterConfigSupplier, times(1)).get();
    TimeLimiter anotherLimit = registry.timeLimiter("test1", timeLimiterConfigSupplier);
    verify(timeLimiterConfigSupplier, times(2)).get();
    then(firstTimeLimiter).isEqualTo(sameAsFirst);
    then(firstTimeLimiter).isNotEqualTo(anotherLimit);
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) TimeLimiterConfig(io.github.resilience4j.timelimiter.TimeLimiterConfig) Test(org.junit.Test)

Example 14 with TimeLimiterRegistry

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

the class InMemoryTimeLimiterRegistryTest method timeLimiterNewWithNullNameAndNonDefaultConfig.

@Test
public void timeLimiterNewWithNullNameAndNonDefaultConfig() {
    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)

Example 15 with TimeLimiterRegistry

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

the class InMemoryTimeLimiterRegistryTest method timeLimiterNewWithNullName.

@Test
public void timeLimiterNewWithNullName() {
    exception.expect(NullPointerException.class);
    exception.expectMessage(NAME_MUST_NOT_BE_NULL);
    TimeLimiterRegistry registry = new InMemoryTimeLimiterRegistry(config);
    registry.timeLimiter(null);
}
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