Search in sources :

Example 1 with RetryPolicy

use of org.apache.servicecomb.governance.policy.RetryPolicy in project java-chassis by ServiceComb.

the class OperatorTest method test_time_changed_to_duration.

@Test
public void test_time_changed_to_duration() {
    RetryPolicy retryPolicy = new RetryPolicy();
    String result;
    result = retryPolicy.stringOfDuration("100", Duration.ofMillis(10));
    Assert.assertEquals("PT0.1S", result);
    Assert.assertEquals(100, Duration.parse(result).toMillis());
    result = retryPolicy.stringOfDuration("3S", Duration.ofMillis(10));
    Assert.assertEquals("PT3S", result);
    Assert.assertEquals(3000, Duration.parse(result).toMillis());
    result = retryPolicy.stringOfDuration("1M", Duration.ofMillis(10));
    Assert.assertEquals("PT1M", result);
    Assert.assertEquals(60000, Duration.parse(result).toMillis());
    result = retryPolicy.stringOfDuration("1H", Duration.ofMillis(10));
    Assert.assertEquals("PT1H", result);
    Assert.assertEquals(3600000, Duration.parse(result).toMillis());
    result = retryPolicy.stringOfDuration("3", Duration.ofMillis(10));
    Assert.assertEquals("PT0.003S", result);
    Assert.assertEquals(3, Duration.parse(result).toMillis());
}
Also used : RetryPolicy(org.apache.servicecomb.governance.policy.RetryPolicy) Test(org.junit.Test)

Example 2 with RetryPolicy

use of org.apache.servicecomb.governance.policy.RetryPolicy 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());
}
Also used : Logger(org.slf4j.Logger) Retry(io.github.resilience4j.retry.Retry) RetryConfig(io.github.resilience4j.retry.RetryConfig) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IntervalFunction(io.github.resilience4j.core.IntervalFunction) RetryExtension(org.apache.servicecomb.governance.handler.ext.RetryExtension) GovernanceUtils(org.apache.servicecomb.governance.utils.GovernanceUtils) Component(org.springframework.stereotype.Component) GovernanceRequest(org.apache.servicecomb.governance.marker.GovernanceRequest) Duration(java.time.Duration) RetryProperties(org.apache.servicecomb.governance.properties.RetryProperties) RetryRegistry(io.github.resilience4j.retry.RetryRegistry) RetryPolicy(org.apache.servicecomb.governance.policy.RetryPolicy) RetryConfig(io.github.resilience4j.retry.RetryConfig) RetryRegistry(io.github.resilience4j.retry.RetryRegistry)

Aggregations

RetryPolicy (org.apache.servicecomb.governance.policy.RetryPolicy)2 IntervalFunction (io.github.resilience4j.core.IntervalFunction)1 Retry (io.github.resilience4j.retry.Retry)1 RetryConfig (io.github.resilience4j.retry.RetryConfig)1 RetryRegistry (io.github.resilience4j.retry.RetryRegistry)1 Duration (java.time.Duration)1 RetryExtension (org.apache.servicecomb.governance.handler.ext.RetryExtension)1 GovernanceRequest (org.apache.servicecomb.governance.marker.GovernanceRequest)1 RetryProperties (org.apache.servicecomb.governance.properties.RetryProperties)1 GovernanceUtils (org.apache.servicecomb.governance.utils.GovernanceUtils)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1