Java Code Examples for io.github.resilience4j.timelimiter.TimeLimiter#onSuccess()
The following examples show how to use
io.github.resilience4j.timelimiter.TimeLimiter#onSuccess() .
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: TaggedTimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldAddMetricsForANewlyCreatedTimeLimiter() { TimeLimiter newTimeLimiter = timeLimiterRegistry.timeLimiter("backendB"); newTimeLimiter.onSuccess(); assertThat(taggedTimeLimiterMetrics.meterIdMap).containsKeys("backendA", "backendB"); assertThat(taggedTimeLimiterMetrics.meterIdMap.get("backendA")).hasSize(3); assertThat(taggedTimeLimiterMetrics.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); }
Example 2
Source File: TaggedTimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldRecordSuccesses() { TimeLimiter timeLimiter = TimeLimiter.of(TimeLimiterConfig.ofDefaults()); metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiter(timeLimiter)); timeLimiter.onSuccess(); timeLimiter.onSuccess(); assertThat(metricRegistry).hasMetricsSize(3); assertThat(metricRegistry).counter(DEFAULT_PREFIX + SUCCESSFUL) .hasValue(2L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + FAILED) .hasValue(0L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + TIMEOUT) .hasValue(0L); }
Example 4
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(); }
Example 5
Source File: TaggedTimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldAddCustomTags() { TimeLimiter timeLimiterF = timeLimiterRegistry.timeLimiter("backendF", io.vavr.collection.HashMap.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(); }
Example 6
Source File: TaggedTimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@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); }