use of io.github.resilience4j.timelimiter.TimeLimiter in project resilience4j by resilience4j.
the class AbstractTimeLimiterMetricsTest method shouldRegisterMetrics.
@Test
public void shouldRegisterMetrics() throws Exception {
TimeLimiter timeLimiter = given(metricRegistry);
String expectedPrefix = "resilience4j.timelimiter.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 shouldAddMetricsForANewlyCreatedTimeLimiter.
@Test
public void shouldAddMetricsForANewlyCreatedTimeLimiter() {
TimeLimiter newTimeLimiter = timeLimiterRegistry.timeLimiter("backendB");
newTimeLimiter.onSuccess();
assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap).containsKeys("backendA", "backendB");
assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap.get("backendA")).hasSize(3);
assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap.get("backendB")).hasSize(3);
assertThat(meterRegistry.getMeters()).hasSize(6);
Collection<Counter> counters = meterRegistry.get(DEFAULT_TIME_LIMITER_CALLS).counters();
Optional<Counter> successful = findMeterByKindAndNameTags(counters, "successful", newTimeLimiter.getName());
assertThat(successful).map(Counter::count).contains(1d);
}
use of io.github.resilience4j.timelimiter.TimeLimiter in project resilience4j by resilience4j.
the class TaggedTimeLimiterMetricsPublisherTest method testReplaceNewMeter.
@Test
public void testReplaceNewMeter() {
TimeLimiter oldOne = TimeLimiter.of("backendC", TimeLimiterConfig.ofDefaults());
// add meters of old
taggedTimeLimiterMetricsPublisher.addMetrics(meterRegistry, oldOne);
// one success call
oldOne.onSuccess();
assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap).containsKeys("backendC");
assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap.get("backendC")).hasSize(3);
Collection<Counter> counters = meterRegistry.get(DEFAULT_TIME_LIMITER_CALLS).counters();
Optional<Counter> successful = findMeterByKindAndNameTags(counters, "successful", oldOne.getName());
assertThat(successful).map(Counter::count).contains(1d);
TimeLimiter newOne = TimeLimiter.of("backendC", TimeLimiterConfig.ofDefaults());
// add meters of new
taggedTimeLimiterMetricsPublisher.addMetrics(meterRegistry, newOne);
// three success call
newOne.onSuccess();
newOne.onSuccess();
newOne.onSuccess();
assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap).containsKeys("backendC");
assertThat(taggedTimeLimiterMetricsPublisher.meterIdMap.get("backendC")).hasSize(3);
counters = meterRegistry.get(DEFAULT_TIME_LIMITER_CALLS).counters();
successful = findMeterByKindAndNameTags(counters, "successful", newOne.getName());
assertThat(successful).map(Counter::count).contains(3d);
}
use of io.github.resilience4j.timelimiter.TimeLimiter in project resilience4j by resilience4j.
the class TaggedTimeLimiterMetrics method bindTo.
@Override
public void bindTo(MeterRegistry registry) {
for (TimeLimiter timeLimiter : timeLimiterRegistry.getAllTimeLimiters()) {
addMetrics(registry, timeLimiter);
}
timeLimiterRegistry.getEventPublisher().onEntryAdded(event -> addMetrics(registry, event.getAddedEntry()));
timeLimiterRegistry.getEventPublisher().onEntryRemoved(event -> removeMetrics(registry, event.getRemovedEntry().getName()));
timeLimiterRegistry.getEventPublisher().onEntryReplaced(event -> {
removeMetrics(registry, event.getOldEntry().getName());
addMetrics(registry, event.getNewEntry());
});
}
use of io.github.resilience4j.timelimiter.TimeLimiter 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);
}
Aggregations