From bf2d962141c5e292b2dfae1af0d348eadb45ca63 Mon Sep 17 00:00:00 2001 From: MRomeh Date: Tue, 9 Jul 2019 15:28:45 +0200 Subject: [PATCH] Issue #515: Aspects ordering update (#534) * #515 ordering update * #515 aspects ordering update * #515 unit test update * #515 test coverage increase --- .../CircuitBreakerAutoConfigurationTest.java | 3 +-- .../RateLimiterAutoConfigurationTest.java | 3 +-- .../retry/RetryAutoConfigurationTest.java | 3 +-- .../src/test/resources/application.yaml | 3 +++ .../CircuitBreakerAutoConfigurationTest.java | 5 ++--- .../RateLimiterAutoConfigurationTest.java | 3 +-- .../RetryAutoConfigurationAsyncTest.java | 3 +-- .../RetryAutoConfigurationReactorTest.java | 3 +-- .../RetryAutoConfigurationRxJavaTest.java | 3 +-- .../retry/RetryAutoConfigurationTest.java | 3 +-- .../src/test/resources/application.yaml | 3 +++ .../BulkheadConfigurationProperties.java | 2 +- ...CircuitBreakerConfigurationProperties.java | 14 +++++++++++--- .../RateLimiterConfigurationProperties.java | 16 +++++++++++++--- .../RetryConfigurationProperties.java | 14 ++++++++++++-- .../CircuitBreakerConfigurationTest.java | 15 +++++++++------ .../RateLimiterConfigurationTest.java | 19 +++++++++++-------- .../configure/RetryConfigurationTest.java | 19 +++++++++++-------- 18 files changed, 84 insertions(+), 50 deletions(-) diff --git a/resilience4j-spring-boot/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java b/resilience4j-spring-boot/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java index 09778f5042..aaf1e3d5bc 100644 --- a/resilience4j-spring-boot/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java +++ b/resilience4j-spring-boot/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java @@ -27,7 +27,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -119,7 +118,7 @@ public void testCircuitBreakerAutoConfiguration() throws IOException { // setRecordExceptions evaluates to false. assertThat(circuitBreaker.getCircuitBreakerConfig().getRecordFailurePredicate().test(new Exception())).isFalse(); - assertThat(circuitBreakerAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 2); + assertThat(circuitBreakerAspect.getOrder()).isEqualTo(400); // expect all shared configs share the same values and are from the application.yml file CircuitBreaker sharedA = circuitBreakerRegistry.circuitBreaker("backendSharedA"); diff --git a/resilience4j-spring-boot/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java b/resilience4j-spring-boot/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java index fb13d2a8e2..db133d4439 100644 --- a/resilience4j-spring-boot/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java +++ b/resilience4j-spring-boot/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java @@ -30,7 +30,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -129,6 +128,6 @@ public void testRateLimiterAutoConfiguration() throws IOException { .until(() -> rateLimiter.getMetrics().getAvailablePermissions() == 10); - assertThat(rateLimiterAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 1); + assertThat(rateLimiterAspect.getOrder()).isEqualTo(401); } } diff --git a/resilience4j-spring-boot/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java b/resilience4j-spring-boot/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java index c08f23093c..f1b4d2b18e 100644 --- a/resilience4j-spring-boot/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java +++ b/resilience4j-spring-boot/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java @@ -26,7 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -99,6 +98,6 @@ public void testRetryAutoConfiguration() throws IOException { assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IgnoredException())).isFalse(); // expect aspect configured as defined in application.yml - assertThat(retryAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 3); + assertThat(retryAspect.getOrder()).isEqualTo(399); } } diff --git a/resilience4j-spring-boot/src/test/resources/application.yaml b/resilience4j-spring-boot/src/test/resources/application.yaml index 4198c3ae06..36002763db 100644 --- a/resilience4j-spring-boot/src/test/resources/application.yaml +++ b/resilience4j-spring-boot/src/test/resources/application.yaml @@ -1,4 +1,5 @@ resilience4j.retry: + retryAspectOrder: 399 backends: retryBackendA: maxRetryAttempts: 3 @@ -17,6 +18,7 @@ resilience4j.retry: ignoreExceptions: - io.github.resilience4j.circuitbreaker.IgnoredException resilience4j.circuitbreaker: + circuitBreakerAspectOrder: 400 configs: default: ringBufferSizeInClosedState: 100 @@ -52,6 +54,7 @@ resilience4j.circuitbreaker: baseConfig: default resilience4j.ratelimiter: + rateLimiterAspectOrder: 401 limiters: backendA: limitForPeriod: 10 diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java index 1f659809a6..513349eb11 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java @@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -125,7 +124,7 @@ public void testCircuitBreakerAutoConfiguration() throws IOException { // setRecordExceptions evaluates to false. assertThat(circuitBreaker.getCircuitBreakerConfig().getRecordFailurePredicate().test(new Exception())).isFalse(); - assertThat(circuitBreakerAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 2); + assertThat(circuitBreakerAspect.getOrder()).isEqualTo(400); // expect all shared configs share the same values and are from the application.yml file CircuitBreaker sharedA = circuitBreakerRegistry.circuitBreaker("backendSharedA"); @@ -246,7 +245,7 @@ public void testCircuitBreakerAutoConfigurationReactive() throws IOException { assertThat(healthResponse.getBody().getDetails().get("backendACircuitBreaker")).isNotNull(); assertThat(healthResponse.getBody().getDetails().get("backendBCircuitBreaker")).isNull(); - assertThat(circuitBreakerAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 2); + assertThat(circuitBreakerAspect.getOrder()).isEqualTo(400); assertThat(circuitBreaker.getMetrics().getNumberOfBufferedCalls()).isEqualTo(2); assertThat(circuitBreaker.getMetrics().getNumberOfSuccessfulCalls()).isEqualTo(1); assertThat(circuitBreaker.getMetrics().getNumberOfFailedCalls()).isEqualTo(1); diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java index 5a7e48d164..5f7c422c5f 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterAutoConfigurationTest.java @@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -119,6 +118,6 @@ public void testRateLimiterAutoConfiguration() throws IOException { .until(() -> rateLimiter.getMetrics().getAvailablePermissions() == 10); - assertThat(rateLimiterAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 1); + assertThat(rateLimiterAspect.getOrder()).isEqualTo(401); } } diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationAsyncTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationAsyncTest.java index eacf95695d..550544b885 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationAsyncTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationAsyncTest.java @@ -31,7 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -111,7 +110,7 @@ public void testRetryAutoConfigurationAsync() throws Throwable { assertThat(retry.getMetrics().getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(1); assertThat(retry.getMetrics().getNumberOfSuccessfulCallsWithoutRetryAttempt()).isEqualTo(1); assertThat(retry.getMetrics().getNumberOfSuccessfulCallsWithRetryAttempt()).isEqualTo(0); - assertThat(retryAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 3); + assertThat(retryAspect.getOrder()).isEqualTo(399); } diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationReactorTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationReactorTest.java index 03048048bf..4233965623 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationReactorTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationReactorTest.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -101,7 +100,7 @@ public void testRetryAutoConfigurationReactor() throws IOException { assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IllegalArgumentException())).isTrue(); assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IgnoredException())).isFalse(); - assertThat(retryAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 3); + assertThat(retryAspect.getOrder()).isEqualTo(399); assertThat(retry.getMetrics().getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); assertThat(retry.getMetrics().getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(1); diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationRxJavaTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationRxJavaTest.java index f2b0013c09..eefb02ab70 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationRxJavaTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationRxJavaTest.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -101,7 +100,7 @@ public void testRetryAutoConfigurationRxJava2() throws IOException { assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IllegalArgumentException())).isTrue(); assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IgnoredException())).isFalse(); - assertThat(retryAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 3); + assertThat(retryAspect.getOrder()).isEqualTo(399); assertThat(retry.getMetrics().getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(0); assertThat(retry.getMetrics().getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(1); diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java index c0e4303062..27630e826f 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/retry/RetryAutoConfigurationTest.java @@ -27,7 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.Ordered; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -104,6 +103,6 @@ public void testRetryAutoConfiguration() throws IOException { assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IOException())).isTrue(); assertThat(retry.getRetryConfig().getExceptionPredicate().test(new IgnoredException())).isFalse(); - assertThat(retryAspect.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 3); + assertThat(retryAspect.getOrder()).isEqualTo(399); } } diff --git a/resilience4j-spring-boot2/src/test/resources/application.yaml b/resilience4j-spring-boot2/src/test/resources/application.yaml index 79173e35a5..ada7188052 100644 --- a/resilience4j-spring-boot2/src/test/resources/application.yaml +++ b/resilience4j-spring-boot2/src/test/resources/application.yaml @@ -1,4 +1,5 @@ resilience4j.retry: + retryAspectOrder: 399 configs: default: maxRetryAttempts: 3 @@ -23,6 +24,7 @@ resilience4j.retry: - io.github.resilience4j.circuitbreaker.IgnoredException resilience4j.circuitbreaker: + circuitBreakerAspectOrder: 400 configs: default: ringBufferSizeInClosedState: 100 @@ -57,6 +59,7 @@ resilience4j.circuitbreaker: baseConfig: default resilience4j.ratelimiter: + rateLimiterAspectOrder: 401 configs: default: limitForPeriod: 10 diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfigurationProperties.java b/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfigurationProperties.java index d1424fb39a..7f9e874917 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfigurationProperties.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/BulkheadConfigurationProperties.java @@ -20,7 +20,7 @@ public class BulkheadConfigurationProperties extends io.github.resilience4j.common.bulkhead.configuration.BulkheadConfigurationProperties { /** - * As of release 0.16.0 as we set an implicit spring aspect order now which is retry then circuit breaker then rate limiter then bulkhead + * As of release 0.16.0 as we set an implicit spring aspect order for bulkhead to cover the async case of threadPool bulkhead */ public int getBulkheadAspectOrder() { return Ordered.LOWEST_PRECEDENCE; diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationProperties.java b/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationProperties.java index 7301468dd4..4150716349 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationProperties.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationProperties.java @@ -21,12 +21,20 @@ @Configuration public class CircuitBreakerConfigurationProperties extends io.github.resilience4j.common.circuitbreaker.configuration.CircuitBreakerConfigurationProperties { - + private int circuitBreakerAspectOrder = Ordered.LOWEST_PRECEDENCE - 2; /** - * As of release 0.16.0 as we set an implicit spring aspect order now which is retry then circuit breaker then rate limiter then bulkhead + * As of release 0.16.0 as we set an implicit spring aspect order now which is retry then circuit breaker then rate limiter then bulkhead but + * user can override it still if he has different use case but bulkhead will be first aspect all the time due to the implicit order we have it for bulkhead */ public int getCircuitBreakerAspectOrder() { - return Ordered.LOWEST_PRECEDENCE - 2; + return circuitBreakerAspectOrder; + } + + /** + * @param circuitBreakerAspectOrder circuit breaker aspect order + */ + public void setCircuitBreakerAspectOrder(int circuitBreakerAspectOrder) { + this.circuitBreakerAspectOrder = circuitBreakerAspectOrder; } diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationProperties.java b/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationProperties.java index 9b2fbba685..74a8da0192 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationProperties.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationProperties.java @@ -18,11 +18,21 @@ import org.springframework.core.Ordered; public class RateLimiterConfigurationProperties extends io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties { - + private int rateLimiterAspectOrder = Ordered.LOWEST_PRECEDENCE - 1; /** - * As of release 0.16.0 as we set an implicit spring aspect order now which is retry then circuit breaker then rate limiter then bulkhead + * As of release 0.16.0 as we set an implicit spring aspect order now which is retry then circuit breaker then rate limiter then bulkhead but + * user can override it still if he has different use case but bulkhead will be first aspect all the time due to the implicit order we have it for bulkhead */ public int getRateLimiterAspectOrder() { - return Ordered.LOWEST_PRECEDENCE - 1; + return rateLimiterAspectOrder; + } + + /** + * set rate limiter aspect order + * + * @param rateLimiterAspectOrder the aspect order + */ + public void setRateLimiterAspectOrder(int rateLimiterAspectOrder) { + this.rateLimiterAspectOrder = rateLimiterAspectOrder; } } diff --git a/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfigurationProperties.java b/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfigurationProperties.java index a957e5802c..6c035a29ba 100644 --- a/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfigurationProperties.java +++ b/resilience4j-spring/src/main/java/io/github/resilience4j/retry/configure/RetryConfigurationProperties.java @@ -21,12 +21,22 @@ * Main spring properties for retry configuration */ public class RetryConfigurationProperties extends io.github.resilience4j.common.retry.configuration.RetryConfigurationProperties { - + private int retryAspectOrder = Ordered.LOWEST_PRECEDENCE - 3; /** * As of release 0.16.0 as we set an implicit spring aspect order now which is retry then circuit breaker then rate limiter then bulkhead + * but the user can override it still if he has different use case but bulkhead will be first aspect all the time due to the implicit order we have it for bulkhead */ public int getRetryAspectOrder() { - return Ordered.LOWEST_PRECEDENCE - 3; + return retryAspectOrder; + } + + /** + * set retry aspect order + * + * @param retryAspectOrder retry aspect target order + */ + public void setRetryAspectOrder(int retryAspectOrder) { + this.retryAspectOrder = retryAspectOrder; } } diff --git a/resilience4j-spring/src/test/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationTest.java b/resilience4j-spring/src/test/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationTest.java index d6b5e49869..628dd6816d 100644 --- a/resilience4j-spring/src/test/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationTest.java +++ b/resilience4j-spring/src/test/java/io/github/resilience4j/circuitbreaker/configure/CircuitBreakerConfigurationTest.java @@ -1,16 +1,17 @@ package io.github.resilience4j.circuitbreaker.configure; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + import io.github.resilience4j.circuitbreaker.CircuitBreaker; import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; import io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent; import io.github.resilience4j.consumer.DefaultEventConsumerRegistry; import io.github.resilience4j.core.ConfigurationNotFoundException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * test custom init of circuit breaker registry @@ -28,6 +29,7 @@ public void testCreateCircuitBreakerRegistry() { instanceProperties2.setRingBufferSizeInClosedState(1337); CircuitBreakerConfigurationProperties circuitBreakerConfigurationProperties = new CircuitBreakerConfigurationProperties(); + circuitBreakerConfigurationProperties.setCircuitBreakerAspectOrder(400); circuitBreakerConfigurationProperties.getInstances().put("backend1", instanceProperties1); circuitBreakerConfigurationProperties.getInstances().put("backend2", instanceProperties2); @@ -38,6 +40,7 @@ public void testCreateCircuitBreakerRegistry() { CircuitBreakerRegistry circuitBreakerRegistry = circuitBreakerConfiguration.circuitBreakerRegistry(eventConsumerRegistry); //Then + assertThat(circuitBreakerConfigurationProperties.getCircuitBreakerAspectOrder()).isEqualTo(400); assertThat(circuitBreakerRegistry.getAllCircuitBreakers().size()).isEqualTo(2); CircuitBreaker circuitBreaker1 = circuitBreakerRegistry.circuitBreaker("backend1"); assertThat(circuitBreaker1).isNotNull(); diff --git a/resilience4j-spring/src/test/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationTest.java b/resilience4j-spring/src/test/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationTest.java index 862d8b6f04..af4e4a4833 100644 --- a/resilience4j-spring/src/test/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationTest.java +++ b/resilience4j-spring/src/test/java/io/github/resilience4j/ratelimiter/configure/RateLimiterConfigurationTest.java @@ -1,18 +1,19 @@ package io.github.resilience4j.ratelimiter.configure; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.time.Duration; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + import io.github.resilience4j.consumer.DefaultEventConsumerRegistry; import io.github.resilience4j.core.ConfigurationNotFoundException; import io.github.resilience4j.ratelimiter.RateLimiter; import io.github.resilience4j.ratelimiter.RateLimiterRegistry; import io.github.resilience4j.ratelimiter.event.RateLimiterEvent; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * test custom init of rate limiter configuration @@ -34,6 +35,7 @@ public void testRateLimiterRegistry() { RateLimiterConfigurationProperties rateLimiterConfigurationProperties = new RateLimiterConfigurationProperties(); rateLimiterConfigurationProperties.getInstances().put("backend1", instanceProperties1); rateLimiterConfigurationProperties.getInstances().put("backend2", instanceProperties2); + rateLimiterConfigurationProperties.setRateLimiterAspectOrder(300); RateLimiterConfiguration rateLimiterConfiguration = new RateLimiterConfiguration(); DefaultEventConsumerRegistry eventConsumerRegistry = new DefaultEventConsumerRegistry<>(); @@ -42,6 +44,7 @@ public void testRateLimiterRegistry() { RateLimiterRegistry rateLimiterRegistry = rateLimiterConfiguration.rateLimiterRegistry(rateLimiterConfigurationProperties, eventConsumerRegistry); //Then + assertThat(rateLimiterConfigurationProperties.getRateLimiterAspectOrder()).isEqualTo(300); assertThat(rateLimiterRegistry.getAllRateLimiters().size()).isEqualTo(2); RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("backend1"); assertThat(rateLimiter).isNotNull(); diff --git a/resilience4j-spring/src/test/java/io/github/resilience4j/retry/configure/RetryConfigurationTest.java b/resilience4j-spring/src/test/java/io/github/resilience4j/retry/configure/RetryConfigurationTest.java index a139ccbbb9..ca6ccf71a8 100644 --- a/resilience4j-spring/src/test/java/io/github/resilience4j/retry/configure/RetryConfigurationTest.java +++ b/resilience4j-spring/src/test/java/io/github/resilience4j/retry/configure/RetryConfigurationTest.java @@ -1,18 +1,19 @@ package io.github.resilience4j.retry.configure; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.time.Duration; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + import io.github.resilience4j.consumer.DefaultEventConsumerRegistry; import io.github.resilience4j.core.ConfigurationNotFoundException; import io.github.resilience4j.retry.Retry; import io.github.resilience4j.retry.RetryRegistry; import io.github.resilience4j.retry.event.RetryEvent; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * test custom init of retry configuration @@ -32,6 +33,7 @@ public void testRetryRegistry() { RetryConfigurationProperties retryConfigurationProperties = new RetryConfigurationProperties(); retryConfigurationProperties.getInstances().put("backend1", instanceProperties1); retryConfigurationProperties.getInstances().put("backend2", instanceProperties2); + retryConfigurationProperties.setRetryAspectOrder(200); RetryConfiguration retryConfiguration = new RetryConfiguration(); DefaultEventConsumerRegistry eventConsumerRegistry = new DefaultEventConsumerRegistry<>(); @@ -40,6 +42,7 @@ public void testRetryRegistry() { RetryRegistry retryRegistry = retryConfiguration.retryRegistry(retryConfigurationProperties, eventConsumerRegistry); //Then + assertThat(retryConfigurationProperties.getRetryAspectOrder()).isEqualTo(200); assertThat(retryRegistry.getAllRetries().size()).isEqualTo(2); Retry retry1 = retryRegistry.retry("backend1"); assertThat(retry1).isNotNull();