use of io.github.resilience4j.retry.RetryRegistry in project resilience4j by resilience4j.
the class RetryMetricsTest method shouldUseCustomPrefix.
@Test
public void shouldUseCustomPrefix() throws Throwable {
// Given
RetryRegistry retryRegistry = RetryRegistry.ofDefaults();
Retry retry = retryRegistry.retry("testName");
metricRegistry.registerAll(RetryMetrics.ofRetryRegistry("testPrefix", retryRegistry));
// Given the HelloWorldService returns Hello world
BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world");
String value = retry.executeSupplier(helloWorldService::returnHelloWorld);
// Then
assertThat(value).isEqualTo("Hello world");
// Then the helloWorldService should be invoked 1 time
BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld();
assertThat(metricRegistry.getMetrics()).hasSize(4);
assertThat(metricRegistry.getGauges().get("testPrefix.testName." + SUCCESSFUL_CALLS_WITH_RETRY).getValue()).isEqualTo(0L);
assertThat(metricRegistry.getGauges().get("testPrefix.testName." + SUCCESSFUL_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(1L);
assertThat(metricRegistry.getGauges().get("testPrefix.testName." + FAILED_CALLS_WITH_RETRY).getValue()).isEqualTo(0L);
assertThat(metricRegistry.getGauges().get("testPrefix.testName." + FAILED_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(0L);
}
use of io.github.resilience4j.retry.RetryRegistry in project resilience4j by resilience4j.
the class RetryMetricsTest method shouldRegisterMetricsWithoutRetry.
@Test
public void shouldRegisterMetricsWithoutRetry() throws Throwable {
// Given
RetryRegistry retryRegistry = RetryRegistry.ofDefaults();
Retry retry = retryRegistry.retry("testName");
metricRegistry.registerAll(RetryMetrics.ofRetryRegistry(retryRegistry));
// Given the HelloWorldService returns Hello world
BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world");
// Setup circuitbreaker with retry
String value = retry.executeSupplier(helloWorldService::returnHelloWorld);
// Then
assertThat(value).isEqualTo("Hello world");
// Then the helloWorldService should be invoked 1 time
BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld();
assertThat(metricRegistry.getMetrics()).hasSize(4);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + SUCCESSFUL_CALLS_WITH_RETRY).getValue()).isEqualTo(0L);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + SUCCESSFUL_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(1L);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + FAILED_CALLS_WITH_RETRY).getValue()).isEqualTo(0L);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + FAILED_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(0L);
}
use of io.github.resilience4j.retry.RetryRegistry in project java-chassis by ServiceComb.
the class InvokerUtils method getOrCreateCompatibleRetry.
private static Retry getOrCreateCompatibleRetry(Invocation invocation) {
RetryConfig retryConfig = RetryConfig.custom().maxAttempts(GovernanceConfiguration.getRetryNextServer(invocation.getMicroserviceName()) + GovernanceConfiguration.getRetrySameServer(invocation.getMicroserviceName()) + 1).retryOnResult(InvokerUtils::canRetryForStatusCode).retryOnException(InvokerUtils::canRetryForException).waitDuration(Duration.ofMillis(0)).build();
RetryRegistry retryRegistry = RetryRegistry.of(retryConfig);
return retryRegistry.retry(invocation.getMicroserviceName());
}
use of io.github.resilience4j.retry.RetryRegistry in project java-chassis by ServiceComb.
the class RetryHandler method getRetry.
private Retry getRetry(RetryPolicy retryPolicy) {
LOGGER.info("applying new policy: {}", retryPolicy.toString());
RetryConfig config = RetryConfig.custom().maxAttempts(retryPolicy.getMaxAttempts() + 1).retryOnResult(response -> retryExtension.isRetry(retryPolicy.getRetryOnResponseStatus(), response)).retryOnException(e -> retryExtension.isRetry(e)).intervalFunction(getIntervalFunction(retryPolicy)).build();
RetryRegistry registry = RetryRegistry.of(config);
return registry.retry(retryPolicy.getName());
}
use of io.github.resilience4j.retry.RetryRegistry in project resilience4j by resilience4j.
the class RetryMetricsTest method shouldRegisterMetricsWithRetry.
@Test
public void shouldRegisterMetricsWithRetry() throws Throwable {
// Given
RetryRegistry retryRegistry = RetryRegistry.ofDefaults();
Retry retry = retryRegistry.retry("testName");
metricRegistry.registerAll(RetryMetrics.ofRetryRegistry(retryRegistry));
// Given the HelloWorldService returns Hello world
BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")).willReturn("Hello world").willThrow(new WebServiceException("BAM!")).willThrow(new WebServiceException("BAM!")).willThrow(new WebServiceException("BAM!"));
// Setup circuitbreaker with retry
String value1 = retry.executeSupplier(helloWorldService::returnHelloWorld);
Try.ofSupplier(Retry.decorateSupplier(retry, helloWorldService::returnHelloWorld));
// Then
assertThat(value1).isEqualTo("Hello world");
// Then the helloWorldService should be invoked 1 time
BDDMockito.then(helloWorldService).should(times(5)).returnHelloWorld();
assertThat(metricRegistry.getMetrics()).hasSize(4);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + SUCCESSFUL_CALLS_WITH_RETRY).getValue()).isEqualTo(1L);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + SUCCESSFUL_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(0L);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + FAILED_CALLS_WITH_RETRY).getValue()).isEqualTo(1L);
assertThat(metricRegistry.getGauges().get("resilience4j.retry.testName." + FAILED_CALLS_WITHOUT_RETRY).getValue()).isEqualTo(0L);
}
Aggregations