Search in sources :

Example 21 with TimeLimiter

use of io.github.resilience4j.timelimiter.TimeLimiter 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 22 with TimeLimiter

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

the class TimeLimiterMetricsTest method shouldRecordErrors.

@Test
public void shouldRecordErrors() {
    TimeLimiter timeLimiter = TimeLimiter.of(TimeLimiterConfig.ofDefaults());
    metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiter(timeLimiter));
    timeLimiter.onError(new RuntimeException());
    timeLimiter.onError(new RuntimeException());
    assertThat(metricRegistry).hasMetricsSize(3);
    assertThat(metricRegistry).counter(DEFAULT_PREFIX + SUCCESSFUL).hasValue(0L);
    assertThat(metricRegistry).counter(DEFAULT_PREFIX + FAILED).hasValue(2L);
    assertThat(metricRegistry).counter(DEFAULT_PREFIX + TIMEOUT).hasValue(0L);
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) Test(org.junit.Test)

Example 23 with TimeLimiter

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

the class TimeLimiterMetricsTest method shouldRecordTimeouts.

@Test
public void shouldRecordTimeouts() {
    TimeLimiter timeLimiter = TimeLimiter.of(TimeLimiterConfig.custom().timeoutDuration(Duration.ZERO).build());
    metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiter(timeLimiter));
    timeLimiter.onError(new TimeoutException());
    timeLimiter.onError(new TimeoutException());
    assertThat(metricRegistry).hasMetricsSize(3);
    assertThat(metricRegistry).counter(DEFAULT_PREFIX + SUCCESSFUL).hasValue(0L);
    assertThat(metricRegistry).counter(DEFAULT_PREFIX + FAILED).hasValue(0L);
    assertThat(metricRegistry).counter(DEFAULT_PREFIX + TIMEOUT).hasValue(2L);
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 24 with TimeLimiter

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

the class AbstractTimeLimiterMetricsTest method shouldUseCustomPrefix.

@Test
public void shouldUseCustomPrefix() throws Exception {
    TimeLimiter timeLimiter = given("testPre", metricRegistry);
    String expectedPrefix = "testPre.testLimit.";
    Supplier<CompletableFuture<String>> futureSupplier = () -> CompletableFuture.completedFuture("Hello world");
    String result = timeLimiter.decorateFutureSupplier(futureSupplier).call();
    then(result).isEqualTo("Hello world");
    assertThat(metricRegistry).hasMetricsSize(3);
    assertThat(metricRegistry).counter(expectedPrefix + SUCCESSFUL).hasValue(1L);
    assertThat(metricRegistry).counter(expectedPrefix + FAILED).hasValue(0L);
    assertThat(metricRegistry).counter(expectedPrefix + TIMEOUT).hasValue(0L);
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 25 with TimeLimiter

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

the class TaggedTimeLimiterMetricsPublisherTest method shouldAddCustomTags.

@Test
public void shouldAddCustomTags() {
    TimeLimiter timeLimiterF = timeLimiterRegistry.timeLimiter("backendF", Map.of("key1", "value1"));
    timeLimiterF.onSuccess();
    assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap).containsKeys("backendA", "backendF");
    assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap.get("backendF")).hasSize(3);
    assertThat(meterRegistry.getMeters()).hasSize(6);
    RequiredSearch match = meterRegistry.get(DEFAULT_TIME_LIMITER_CALLS).tags("key1", "value1");
    assertThat(match).isNotNull();
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) Test(org.junit.Test)

Aggregations

TimeLimiter (io.github.resilience4j.timelimiter.TimeLimiter)37 Test (org.junit.Test)31 TimeLimiterRegistry (io.github.resilience4j.timelimiter.TimeLimiterRegistry)9 Duration (java.time.Duration)7 ThreadPoolBulkhead (io.github.resilience4j.bulkhead.ThreadPoolBulkhead)4 CircuitBreaker (io.github.resilience4j.circuitbreaker.CircuitBreaker)4 Counter (io.micrometer.core.instrument.Counter)4 ContextAwareScheduledThreadPoolExecutor (io.github.resilience4j.core.ContextAwareScheduledThreadPoolExecutor)3 TimeLimiterConfig (io.github.resilience4j.timelimiter.TimeLimiterConfig)3 TimeLimiterEvent (io.github.resilience4j.timelimiter.event.TimeLimiterEvent)3 DefaultEventConsumerRegistry (io.github.resilience4j.consumer.DefaultEventConsumerRegistry)2 TestThreadLocalContextPropagatorWithHolder (io.github.resilience4j.test.TestContextPropagators.TestThreadLocalContextPropagatorWithHolder)2 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 Awaitility.matches (com.jayway.awaitility.Awaitility.matches)1 Awaitility.waitAtMost (com.jayway.awaitility.Awaitility.waitAtMost)1 Bulkhead (io.github.resilience4j.bulkhead.Bulkhead)1 BulkheadFullException (io.github.resilience4j.bulkhead.BulkheadFullException)1 Cache (io.github.resilience4j.cache.Cache)1 CallNotPermittedException (io.github.resilience4j.circuitbreaker.CallNotPermittedException)1