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;
}
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);
}
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);
}
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);
}
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();
}
Aggregations