Java Code Examples for io.github.resilience4j.timelimiter.TimeLimiter#onError()
The following examples show how to use
io.github.resilience4j.timelimiter.TimeLimiter#onError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@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); }
Example 2
Source File: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: TimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void customMetricNamesOverrideDefaultOnes() { TimeLimiterMetricsPublisher.MetricNames names = TimeLimiterMetricsPublisher.MetricNames .custom() .callsMetricName("custom_calls") .build(); CollectorRegistry customRegistry = new CollectorRegistry(); TimeLimiterMetricsPublisher timeLimiterMetricsPublisher = new TimeLimiterMetricsPublisher( names); timeLimiterMetricsPublisher.register(customRegistry); TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry .of(TimeLimiterConfig.ofDefaults(), timeLimiterMetricsPublisher); TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter("backendA"); timeLimiter.onSuccess(); timeLimiter.onError(new RuntimeException()); timeLimiter.onError(new TimeoutException()); Double successfulCalls = getSampleValue(customRegistry, "custom_calls", KIND_SUCCESSFUL); Double failedCalls = getSampleValue(customRegistry, "custom_calls", KIND_FAILED); Double timeoutCalls = getSampleValue(customRegistry, "custom_calls", KIND_TIMEOUT); assertThat(successfulCalls).isNotNull(); assertThat(failedCalls).isNotNull(); assertThat(timeoutCalls).isNotNull(); }