From 9bbc73f12d840bb419d80978b3840b14b72d5b0d Mon Sep 17 00:00:00 2001 From: Julien Hoarau Date: Fri, 16 Mar 2018 19:37:42 +1100 Subject: [PATCH] #212 Add more tests checking we get the right exception (#214) Check that we are getting the resilience exception even when the source will throw an exception (not on subscribe) --- .../reactor/CombinedOperatorsTest.java | 12 ++++++++ .../bulkhead/operator/FluxBulkheadTest.java | 14 +++++++++ .../bulkhead/operator/MonoBulkheadTest.java | 14 +++++++++ .../operator/MonoCircuitBreakerTest.java | 12 ++++++++ .../operator/FluxRateLimiterTest.java | 30 ++++++++++++++++++- .../operator/MonoRateLimiterTest.java | 14 ++++++++- 6 files changed, 94 insertions(+), 2 deletions(-) diff --git a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/CombinedOperatorsTest.java b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/CombinedOperatorsTest.java index 41c5b60ee2..04659b55a0 100644 --- a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/CombinedOperatorsTest.java +++ b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/CombinedOperatorsTest.java @@ -80,4 +80,16 @@ public void shouldEmitErrorWithCircuitBreakerOpenExceptionEvenWhenErrorDuringSub ).expectError(CircuitBreakerOpenException.class) .verify(Duration.ofSeconds(1)); } + + @Test + public void shouldEmitErrorWithCircuitBreakerOpenExceptionEvenWhenErrorNotOnSubscribe() { + circuitBreaker.transitionToOpenState(); + StepVerifier.create( + Flux.error(new IOException("BAM!"), true) + .transform(CircuitBreakerOperator.of(circuitBreaker)) + .transform(BulkheadOperator.of(bulkhead, Schedulers.immediate())) + .transform(RateLimiterOperator.of(rateLimiter, Schedulers.immediate())) + ).expectError(CircuitBreakerOpenException.class) + .verify(Duration.ofSeconds(1)); + } } diff --git a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/FluxBulkheadTest.java b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/FluxBulkheadTest.java index 839ff30f02..f6b0530dab 100644 --- a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/FluxBulkheadTest.java +++ b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/FluxBulkheadTest.java @@ -84,4 +84,18 @@ public void shouldEmitBulkheadFullExceptionEvenWhenErrorDuringSubscribe() { assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); } + + @Test + public void shouldEmitBulkheadFullExceptionEvenWhenErrorNotOnSubscribe() { + bulkhead.isCallPermitted(); + + StepVerifier.create( + Flux.error(new IOException("BAM!"), true) + .transform(BulkheadOperator.of(bulkhead, Schedulers.immediate()))) + .expectSubscription() + .expectError(BulkheadFullException.class) + .verify(Duration.ofSeconds(1)); + + assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); + } } \ No newline at end of file diff --git a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/MonoBulkheadTest.java b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/MonoBulkheadTest.java index b0523f9a36..c44db32b4a 100644 --- a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/MonoBulkheadTest.java +++ b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/bulkhead/operator/MonoBulkheadTest.java @@ -83,4 +83,18 @@ public void shouldEmitBulkheadFullExceptionEvenWhenErrorDuringSubscribe() { assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); } + + @Test + public void shouldEmitBulkheadFullExceptionEvenWhenErrorNotOnSubscribe() { + bulkhead.isCallPermitted(); + + StepVerifier.create( + Mono.error(new IOException("BAM!")).delayElement(Duration.ofMillis(1)) + .transform(BulkheadOperator.of(bulkhead, Schedulers.immediate()))) + .expectSubscription() + .expectError(BulkheadFullException.class) + .verify(Duration.ofSeconds(1)); + + assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); + } } \ No newline at end of file diff --git a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/circuitbreaker/operator/MonoCircuitBreakerTest.java b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/circuitbreaker/operator/MonoCircuitBreakerTest.java index 045644597f..66f0c2eef3 100644 --- a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/circuitbreaker/operator/MonoCircuitBreakerTest.java +++ b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/circuitbreaker/operator/MonoCircuitBreakerTest.java @@ -47,6 +47,18 @@ public void shouldPropagateError() { assertSingleFailedCall(); } + @Test + public void shouldEmitCircuitBreakerOpenExceptionEvenWhenErrorNotOnSubscribe() { + circuitBreaker.transitionToForcedOpenState(); + StepVerifier.create( + Mono.error(new IOException("BAM!")).delayElement(Duration.ofMillis(1)) + .transform(CircuitBreakerOperator.of(circuitBreaker))) + .expectError(CircuitBreakerOpenException.class) + .verify(Duration.ofSeconds(1)); + + assertNoRegisteredCall(); + } + @Test public void shouldEmitCircuitBreakerOpenExceptionEvenWhenErrorDuringSubscribe() { circuitBreaker.transitionToForcedOpenState(); diff --git a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/FluxRateLimiterTest.java b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/FluxRateLimiterTest.java index da9e749d8a..3213bffcea 100644 --- a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/FluxRateLimiterTest.java +++ b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/FluxRateLimiterTest.java @@ -51,7 +51,7 @@ public void shouldPropagateError() { } @Test - public void shouldEmitErrorWithBulkheadFullException() { + public void shouldEmitRequestNotPermittedException() { saturateRateLimiter(); StepVerifier.create( @@ -63,4 +63,32 @@ public void shouldEmitErrorWithBulkheadFullException() { assertNoPermitLeft(); } + + @Test + public void shouldEmitRequestNotPermittedExceptionEvenWhenErrorDuringSubscribe() { + saturateRateLimiter(); + + StepVerifier.create( + Flux.error(new IOException("BAM!")) + .transform(RateLimiterOperator.of(rateLimiter))) + .expectSubscription() + .expectError(RequestNotPermitted.class) + .verify(Duration.ofSeconds(1)); + + assertNoPermitLeft(); + } + + @Test + public void shouldEmitRequestNotPermittedExceptionEvenWhenErrorNotOnSubscribe() { + saturateRateLimiter(); + + StepVerifier.create( + Flux.error(new IOException("BAM!"), true) + .transform(RateLimiterOperator.of(rateLimiter))) + .expectSubscription() + .expectError(RequestNotPermitted.class) + .verify(Duration.ofSeconds(1)); + + assertNoPermitLeft(); + } } \ No newline at end of file diff --git a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/MonoRateLimiterTest.java b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/MonoRateLimiterTest.java index 49f43df5cc..21f44bb0f5 100644 --- a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/MonoRateLimiterTest.java +++ b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/ratelimiter/operator/MonoRateLimiterTest.java @@ -64,7 +64,7 @@ public void shouldEmitErrorWithBulkheadFullException() { } @Test - public void shouldEmitCircuitBreakerOpenExceptionEvenWhenErrorDuringSubscribe() { + public void shouldEmitRequestNotPermittedExceptionEvenWhenErrorDuringSubscribe() { saturateRateLimiter(); StepVerifier.create( Mono.error(new IOException("BAM!")) @@ -74,4 +74,16 @@ public void shouldEmitCircuitBreakerOpenExceptionEvenWhenErrorDuringSubscribe() assertNoPermitLeft(); } + + @Test + public void shouldEmitRequestNotPermittedExceptionEvenWhenErrorNotOnSubscribe() { + saturateRateLimiter(); + StepVerifier.create( + Mono.error(new IOException("BAM!")).delayElement(Duration.ofMillis(1)) + .transform(RateLimiterOperator.of(rateLimiter, Schedulers.immediate()))) + .expectError(RequestNotPermitted.class) + .verify(Duration.ofSeconds(1)); + + assertNoPermitLeft(); + } } \ No newline at end of file