From 42b3a04b7dd695d9b746a9a71562deed53ab4e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Skowro=C5=84ski?= <5780288+hexmind@users.noreply.github.com> Date: Thu, 19 Sep 2019 09:54:50 +0200 Subject: [PATCH] Remove javax.xml.ws.WebServiceException (#638) --- .../resilience4j/bulkhead/BulkheadTest.java | 16 ++-- .../cache/CacheEventPublisherTest.java | 4 +- .../circuitbreaker/CircuitBreakerTest.java | 16 ++-- .../consumer/CircularEventConsumerTest.java | 5 +- .../resilience4j/core/CallableUtilsTest.java | 5 +- .../resilience4j/core/SupplierUtilsTest.java | 5 +- .../src/docs/asciidoc/core_guides/retry.adoc | 4 +- .../metrics/AbstractRetryMetricsTest.java | 11 ++- .../resilience4j/metrics/TimerTest.java | 11 +-- .../ratelimiter/RateLimiterTest.java | 5 +- .../reactor/retry/RetryOperatorTest.java | 12 +-- .../retry/RetryEventPublisherTest.java | 13 ++-- .../internal/CompletionStageRetryTest.java | 12 +-- .../retry/internal/EventPublisherTest.java | 10 +-- .../retry/internal/RunnableRetryTest.java | 22 +++--- .../retry/internal/SupplierRetryTest.java | 70 ++++++++--------- .../transformer/RetryTransformerTest.java | 76 +++++++++---------- .../test/HelloWorldException.java | 12 +++ .../resilience4j/test/HelloWorldService.java | 3 +- 19 files changed, 158 insertions(+), 154 deletions(-) create mode 100644 resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldException.java diff --git a/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadTest.java b/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadTest.java index b96d367bf1..12cd825787 100644 --- a/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadTest.java +++ b/resilience4j-bulkhead/src/test/java/io/github/resilience4j/bulkhead/BulkheadTest.java @@ -18,6 +18,7 @@ */ package io.github.resilience4j.bulkhead; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.vavr.CheckedConsumer; import io.vavr.CheckedFunction0; @@ -30,7 +31,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; @@ -498,14 +498,14 @@ public void shouldExecuteCompletionStageAndReturnWithSuccess() throws ExecutionE } @Test - public void shouldDecorateCompletionStageAndReturnWithExceptionAtSyncStage() throws ExecutionException, InterruptedException { + public void shouldDecorateCompletionStageAndReturnWithExceptionAtSyncStage() { // Given Bulkhead bulkhead = Bulkhead.of("test", config); // When Supplier> completionStageSupplier = () -> { - throw new WebServiceException("BAM! At sync stage"); + throw new HelloWorldException(); }; Supplier> decoratedCompletionStageSupplier = @@ -521,7 +521,7 @@ public void shouldDecorateCompletionStageAndReturnWithExceptionAtSyncStage() thr .exceptionally( error -> { // NOTE: Try.of does not detect a completion stage that has been completed with failure ! - assertThat(error).isInstanceOf(WebServiceException.class); + assertThat(error).isInstanceOf(HelloWorldException.class); return null; } ); @@ -529,7 +529,7 @@ public void shouldDecorateCompletionStageAndReturnWithExceptionAtSyncStage() thr } @Test - public void shouldDecorateCompletionStageAndReturnWithExceptionAtAsyncStage() throws ExecutionException, InterruptedException { + public void shouldDecorateCompletionStageAndReturnWithExceptionAtAsyncStage() { // Given Bulkhead bulkhead = Bulkhead.of("test", config); @@ -550,7 +550,7 @@ public void shouldDecorateCompletionStageAndReturnWithExceptionAtAsyncStage() th } @Test - public void shouldChainDecoratedFunctions() throws ExecutionException, InterruptedException { + public void shouldChainDecoratedFunctions() { // tag::shouldChainDecoratedFunctions[] // Given Bulkhead bulkhead = Bulkhead.of("test", config); @@ -565,7 +565,7 @@ public void shouldChainDecoratedFunctions() throws ExecutionException, Interrupt // and I chain a function with map Try result = Try.of(decoratedSupplier) - .mapTry(decoratedFunction::apply); + .mapTry(decoratedFunction); // Then assertThat(result.isSuccess()).isTrue(); @@ -647,7 +647,7 @@ public void shouldDecorateEitherSupplierAndReturnWithSuccess() { public void shouldDecorateEitherSupplierAndReturnWithException() { // Given Bulkhead bulkhead = Bulkhead.of("test", config); - BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new WebServiceException("BAM!"))); + BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new HelloWorldException())); // When Either result = bulkhead.executeEitherSupplier(helloWorldService::returnEither); diff --git a/resilience4j-cache/src/test/java/io/github/resilience4j/cache/CacheEventPublisherTest.java b/resilience4j-cache/src/test/java/io/github/resilience4j/cache/CacheEventPublisherTest.java index d08e62020f..b07dad4677 100644 --- a/resilience4j-cache/src/test/java/io/github/resilience4j/cache/CacheEventPublisherTest.java +++ b/resilience4j-cache/src/test/java/io/github/resilience4j/cache/CacheEventPublisherTest.java @@ -23,8 +23,6 @@ import org.junit.Test; import org.slf4j.Logger; -import javax.xml.ws.WebServiceException; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.*; import static org.mockito.Mockito.mock; @@ -85,7 +83,7 @@ public void shouldConsumeOnCacheMissEvent() throws Throwable { @Test public void shouldConsumeOnErrorEvent() throws Throwable { // Given the cache does not contain the key - given(cache.get("testKey")).willThrow(new WebServiceException("BLA")); + given(cache.get("testKey")).willThrow(new RuntimeException("BLA")); Cache cacheContext = Cache.of(cache); cacheContext.getEventPublisher().onError(event -> diff --git a/resilience4j-circuitbreaker/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerTest.java b/resilience4j-circuitbreaker/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerTest.java index 9b128ae013..c7b5208350 100644 --- a/resilience4j-circuitbreaker/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerTest.java +++ b/resilience4j-circuitbreaker/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerTest.java @@ -18,6 +18,7 @@ */ package io.github.resilience4j.circuitbreaker; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.vavr.CheckedConsumer; import io.vavr.CheckedFunction0; @@ -30,7 +31,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.io.IOException; import java.net.SocketTimeoutException; import java.time.Duration; @@ -575,7 +575,7 @@ public void shouldNotRecordIOExceptionAsAFailure() { CircuitBreaker circuitBreaker = CircuitBreaker.of("testName", circuitBreakerConfig); // Simulate a failure attempt - circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new WebServiceException()); + circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new HelloWorldException()); // CircuitBreaker is still CLOSED, because 1 failure is allowed assertThat(circuitBreaker.getState()).isEqualTo(CircuitBreaker.State.CLOSED); @@ -816,16 +816,16 @@ public void shouldDecorateCompletionStageAndReturnWithExceptionAtAsyncStage() { } @Test - public void shouldDecorateCompletionStageAndIgnoreWebServiceException() { + public void shouldDecorateCompletionStageAndIgnoreHelloWorldException() { // Given CircuitBreakerConfig config = CircuitBreakerConfig.custom() - .ignoreExceptions(WebServiceException.class) + .ignoreExceptions(HelloWorldException.class) .build(); CircuitBreaker circuitBreaker = CircuitBreaker.of("backendName", config); assertThat(circuitBreaker.getState()).isEqualTo(CircuitBreaker.State.CLOSED); // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM! At async stage")); + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()); // When Supplier> completionStageSupplier = @@ -835,11 +835,11 @@ public void shouldDecorateCompletionStageAndIgnoreWebServiceException() { // Then the helloWorldService should be invoked 1 time assertThatThrownBy(stringCompletionStage.toCompletableFuture()::get) - .isInstanceOf(ExecutionException.class).hasCause(new WebServiceException("BAM! At async stage")); + .isInstanceOf(ExecutionException.class).hasCause(new HelloWorldException()); BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnHelloWorld(); CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics(); - // WebServiceException should be ignored + // HelloWorldException should be ignored assertThat(metrics.getNumberOfBufferedCalls()).isEqualTo(0); assertThat(metrics.getNumberOfFailedCalls()).isEqualTo(0); } @@ -996,7 +996,7 @@ public void shouldExecuteEitherSupplierAndReturnWithFailure() { CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics(); assertThat(metrics.getNumberOfBufferedCalls()).isEqualTo(0); // Given the HelloWorldService returns Hello world - BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new WebServiceException("BAM!"))); + BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new HelloWorldException())); //When Either result = circuitBreaker.executeEitherSupplier(helloWorldService::returnEither); diff --git a/resilience4j-consumer/src/test/java/io/github/resilience4j/consumer/CircularEventConsumerTest.java b/resilience4j-consumer/src/test/java/io/github/resilience4j/consumer/CircularEventConsumerTest.java index d1f6b33132..09aa336309 100644 --- a/resilience4j-consumer/src/test/java/io/github/resilience4j/consumer/CircularEventConsumerTest.java +++ b/resilience4j-consumer/src/test/java/io/github/resilience4j/consumer/CircularEventConsumerTest.java @@ -23,7 +23,6 @@ import io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent; import org.junit.Test; -import javax.xml.ws.WebServiceException; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -75,9 +74,9 @@ public void shouldBufferAllEvents() { //When circuitBreaker.onSuccess(0, TimeUnit.NANOSECONDS); - circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new WebServiceException("Bla")); + circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("Bla")); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new IOException("Bla")); - circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new WebServiceException("Bla")); + circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("Bla")); //Then diff --git a/resilience4j-core/src/test/java/io/github/resilience4j/core/CallableUtilsTest.java b/resilience4j-core/src/test/java/io/github/resilience4j/core/CallableUtilsTest.java index 11e8dc3bf5..7dc13aa246 100644 --- a/resilience4j-core/src/test/java/io/github/resilience4j/core/CallableUtilsTest.java +++ b/resilience4j-core/src/test/java/io/github/resilience4j/core/CallableUtilsTest.java @@ -2,7 +2,6 @@ import org.junit.Test; -import javax.xml.ws.WebServiceException; import java.io.IOException; import java.util.concurrent.Callable; @@ -69,7 +68,7 @@ public void shouldRecoverCallableFromException() throws Exception { assertThat(result).isEqualTo("Bla"); } - @Test(expected = WebServiceException.class) + @Test(expected = RuntimeException.class) public void shouldRethrowException() throws Exception { Callable callable = () -> { @@ -77,7 +76,7 @@ public void shouldRethrowException() throws Exception { }; //When Callable callableWithRecovery = CallableUtils.recover(callable, (ex) -> { - throw new WebServiceException(); + throw new RuntimeException(); }); callableWithRecovery.call(); diff --git a/resilience4j-core/src/test/java/io/github/resilience4j/core/SupplierUtilsTest.java b/resilience4j-core/src/test/java/io/github/resilience4j/core/SupplierUtilsTest.java index d68e106f45..ebc26ccc2d 100644 --- a/resilience4j-core/src/test/java/io/github/resilience4j/core/SupplierUtilsTest.java +++ b/resilience4j-core/src/test/java/io/github/resilience4j/core/SupplierUtilsTest.java @@ -2,7 +2,6 @@ import org.junit.Test; -import javax.xml.ws.WebServiceException; import java.util.function.Supplier; import static org.assertj.core.api.Assertions.assertThat; @@ -68,7 +67,7 @@ public void shouldRecoverSupplierFromException() { assertThat(result).isEqualTo("Bla"); } - @Test(expected = WebServiceException.class) + @Test(expected = RuntimeException.class) public void shouldRethrowException() { Supplier supplier = () -> { @@ -76,7 +75,7 @@ public void shouldRethrowException() { }; //When Supplier supplierWithRecovery = SupplierUtils.recover(supplier, (ex) -> { - throw new WebServiceException(); + throw new RuntimeException(); }); supplierWithRecovery.get(); diff --git a/resilience4j-documentation/src/docs/asciidoc/core_guides/retry.adoc b/resilience4j-documentation/src/docs/asciidoc/core_guides/retry.adoc index 769bfe8895..093298d60c 100644 --- a/resilience4j-documentation/src/docs/asciidoc/core_guides/retry.adoc +++ b/resilience4j-documentation/src/docs/asciidoc/core_guides/retry.adoc @@ -19,7 +19,7 @@ RetryConfig config = RetryConfig.custom() .maxAttempts(2) .waitDuration(Duration.ofMillis(100)) .retryOnResult(response -> response.getStatus() == 500) - .retryOnException(e -> e instanceof WebServiceException) + .retryOnException(e -> e instanceof HelloWorldException) .retryExceptions(IOException.class, TimeoutException.class) .ignoreExceptions(BunsinessException.class, OtherBunsinessException.class) .build(); @@ -33,7 +33,7 @@ You can decorate any `Supplier / Runnable / Function` or `CheckedSupplier / Chec ---- // Given I have a HelloWorldService which throws an exception HelloWorldService helloWorldService = mock(HelloWorldService.class); -given(helloWorldService.sayHelloWorld()).willThrow(new WebServiceException("BAM!")); +given(helloWorldService.sayHelloWorld()).willThrow(new HelloWorldException()); // Create a Retry with default configuration Retry retry = Retry.ofDefaults("id"); diff --git a/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/AbstractRetryMetricsTest.java b/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/AbstractRetryMetricsTest.java index 663bb31bb5..f7e35b1691 100644 --- a/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/AbstractRetryMetricsTest.java +++ b/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/AbstractRetryMetricsTest.java @@ -18,14 +18,13 @@ import com.codahale.metrics.MetricRegistry; import io.github.resilience4j.retry.Retry; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.vavr.control.Try; import org.junit.Before; import org.junit.Test; import org.mockito.BDDMockito; -import javax.xml.ws.WebServiceException; - import static io.github.resilience4j.retry.utils.MetricNames.*; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -75,11 +74,11 @@ public void shouldRegisterMetricsWithRetry() throws Throwable { // Given the HelloWorldService returns Hello world BDDMockito.given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")) + .willThrow(new HelloWorldException()) .willReturn("Hello world") - .willThrow(new WebServiceException("BAM!")) - .willThrow(new WebServiceException("BAM!")) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()) + .willThrow(new HelloWorldException()) + .willThrow(new HelloWorldException()); // Setup circuitbreaker with retry String value1 = retry.executeSupplier(helloWorldService::returnHelloWorld); diff --git a/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/TimerTest.java b/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/TimerTest.java index e8b0633c1c..f4c2665c93 100644 --- a/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/TimerTest.java +++ b/resilience4j-metrics/src/test/java/io/github/resilience4j/metrics/TimerTest.java @@ -19,6 +19,8 @@ package io.github.resilience4j.metrics; import com.codahale.metrics.MetricRegistry; + +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.vavr.CheckedFunction0; import io.vavr.CheckedFunction1; @@ -31,7 +33,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; @@ -175,11 +176,11 @@ public void shouldExecuteCompletionStageSupplier() throws Throwable { public void shouldExecuteCompletionStageAndReturnWithExceptionAtSyncStage() throws Throwable { Supplier> completionStageSupplier = () -> { - throw new WebServiceException("BAM! At sync stage"); + throw new HelloWorldException(); }; Assertions.assertThatThrownBy(() -> timer.executeCompletionStageSupplier(completionStageSupplier)) - .isInstanceOf(WebServiceException.class); + .isInstanceOf(HelloWorldException.class); assertThat(timer.getMetrics().getNumberOfTotalCalls()).isEqualTo(1); assertThat(timer.getMetrics().getNumberOfSuccessfulCalls()).isEqualTo(0); @@ -190,7 +191,7 @@ public void shouldExecuteCompletionStageAndReturnWithExceptionAtSyncStage() thro @Test public void shouldExecuteCompletionStageAndReturnWithExceptionAtASyncStage() throws Throwable { // Given the HelloWorldService returns Hello world - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")); + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()); // And measure the call with a Timer Supplier> completionStageSupplier = () -> CompletableFuture.supplyAsync(helloWorldService::returnHelloWorld); @@ -198,7 +199,7 @@ public void shouldExecuteCompletionStageAndReturnWithExceptionAtASyncStage() thr CompletionStage stringCompletionStage = timer.executeCompletionStageSupplier(completionStageSupplier); Assertions.assertThatThrownBy(() -> stringCompletionStage.toCompletableFuture().get()) - .isInstanceOf(ExecutionException.class).hasCause(new WebServiceException("BAM!")); + .isInstanceOf(ExecutionException.class).hasCause(new HelloWorldException()); assertThat(timer.getMetrics().getNumberOfTotalCalls()).isEqualTo(1); assertThat(timer.getMetrics().getNumberOfSuccessfulCalls()).isEqualTo(0); diff --git a/resilience4j-ratelimiter/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterTest.java b/resilience4j-ratelimiter/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterTest.java index 8b87cedc59..c0d9032f4e 100644 --- a/resilience4j-ratelimiter/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterTest.java +++ b/resilience4j-ratelimiter/src/test/java/io/github/resilience4j/ratelimiter/RateLimiterTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.mockito.BDDMockito; -import javax.xml.ws.WebServiceException; import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; @@ -316,7 +315,7 @@ public void decorateTrySupplier() throws Exception { @Test public void decorateEitherSupplier() throws Exception { - Supplier> supplier = mock(Supplier.class); + Supplier> supplier = mock(Supplier.class); BDDMockito.given(supplier.get()).willReturn(Either.right("Resource")); when(limit.acquirePermission()).thenReturn(true); @@ -342,7 +341,7 @@ public void shouldExecuteTrySupplierAndReturnRequestNotPermitted() throws Except @Test public void shouldExecuteEitherSupplierAndReturnRequestNotPermitted() throws Exception { - Supplier> supplier = mock(Supplier.class); + Supplier> supplier = mock(Supplier.class); when(limit.acquirePermission()).thenReturn(false); diff --git a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/retry/RetryOperatorTest.java b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/retry/RetryOperatorTest.java index b5b002e709..1f97de38f8 100644 --- a/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/retry/RetryOperatorTest.java +++ b/resilience4j-reactor/src/test/java/io/github/resilience4j/reactor/retry/RetryOperatorTest.java @@ -18,6 +18,7 @@ import io.github.resilience4j.retry.Retry; import io.github.resilience4j.retry.RetryConfig; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import org.junit.Before; import org.junit.Test; @@ -27,7 +28,6 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import javax.xml.ws.WebServiceException; import java.io.IOException; import java.time.Duration; @@ -53,8 +53,8 @@ public void returnOnCompleteUsingMono() { given(helloWorldService.returnHelloWorld()) .willReturn("Hello world") - .willThrow(new WebServiceException("BAM!")) - .willThrow(new WebServiceException("BAM!")) + .willThrow(new HelloWorldException()) + .willThrow(new HelloWorldException()) .willReturn("Hello world"); //When @@ -128,7 +128,7 @@ public void returnOnErrorUsingMono() { RetryOperator retryOperator = RetryOperator.of(retry); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When StepVerifier.create(Mono.fromCallable(helloWorldService::returnHelloWorld) @@ -160,7 +160,7 @@ public void doNotRetryFromPredicateUsingMono() { .maxAttempts(3).build(); Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When StepVerifier.create(Mono.fromCallable(helloWorldService::returnHelloWorld) @@ -235,7 +235,7 @@ public void shouldFailWithExceptionFlux() { RetryOperator retryOperator = RetryOperator.of(retry); //When - StepVerifier.create(Flux.error(new WebServiceException("BAM!")).compose(retryOperator)) + StepVerifier.create(Flux.error(new HelloWorldException()).compose(retryOperator)) .expectSubscription() .expectError(RetryExceptionWrapper.class) .verify(Duration.ofMillis(50)); diff --git a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryEventPublisherTest.java b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryEventPublisherTest.java index 2ecb747744..134a1f0c00 100644 --- a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryEventPublisherTest.java +++ b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/RetryEventPublisherTest.java @@ -18,14 +18,13 @@ */ package io.github.resilience4j.retry; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.vavr.control.Try; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; -import javax.xml.ws.WebServiceException; - import static io.vavr.API.$; import static io.vavr.API.Case; import static io.vavr.API.Match; @@ -61,7 +60,7 @@ public void shouldReturnTheSameConsumer() { public void shouldConsumeOnSuccessEvent() { // Given the HelloWorldService returns Hello world given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")) + .willThrow(new HelloWorldException()) .willReturn("Hello world"); retry.getEventPublisher() @@ -77,7 +76,7 @@ public void shouldConsumeOnSuccessEvent() { @Test public void shouldConsumeOnRetryEvent() { given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); retry.getEventPublisher() .onRetry(event -> @@ -92,7 +91,7 @@ public void shouldConsumeOnRetryEvent() { @Test public void shouldConsumeOnErrorEvent() { given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); retry.getEventPublisher() .onError(event -> @@ -108,11 +107,11 @@ public void shouldConsumeOnErrorEvent() { @Test public void shouldConsumeIgnoredErrorEvent() { given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); RetryConfig retryConfig = RetryConfig.custom() .retryOnException(throwable -> Match(throwable).of( - Case($(instanceOf(WebServiceException.class)), false), + Case($(instanceOf(HelloWorldException.class)), false), Case($(), true))) .build(); retry = Retry.of("testName", retryConfig); diff --git a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/CompletionStageRetryTest.java b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/CompletionStageRetryTest.java index ca4d544a6a..0e7ffa4803 100644 --- a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/CompletionStageRetryTest.java +++ b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/CompletionStageRetryTest.java @@ -21,6 +21,7 @@ import io.github.resilience4j.retry.Retry; import io.github.resilience4j.retry.RetryConfig; import io.github.resilience4j.test.AsyncHelloWorldService; +import io.github.resilience4j.test.HelloWorldException; import io.vavr.control.Try; import org.assertj.core.api.Assertions; import org.junit.Assert; @@ -29,7 +30,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import java.util.concurrent.Executors; @@ -138,7 +138,7 @@ public void shouldRethrowExceptionInCaseOfExceptionAtSyncStage() { @Test public void shouldRetryInCaseOfAnExceptionAtAsyncStage() { CompletableFuture failedFuture = new CompletableFuture<>(); - failedFuture.completeExceptionally(new WebServiceException("BAM!")); + failedFuture.completeExceptionally(new HelloWorldException()); // Given the HelloWorldService throws an exception BDDMockito.given(helloWorldService.returnHelloWorld()) @@ -164,7 +164,7 @@ public void shouldRetryInCaseOfAnExceptionAtAsyncStage() { private void shouldCompleteFutureAfterAttemptsInCaseOfExceptionAtSyncStage(int noOfAttempts) { // Given the HelloWorldService throws an exception BDDMockito.given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); // Create a Retry with default configuration Retry retryContext = Retry.of( @@ -185,7 +185,7 @@ private void shouldCompleteFutureAfterAttemptsInCaseOfExceptionAtSyncStage(int n // Then the helloWorldService should be invoked n + 1 times BDDMockito.then(helloWorldService).should(Mockito.times(noOfAttempts)).returnHelloWorld(); Assertions.assertThat(resultTry.isFailure()).isTrue(); - Assertions.assertThat(resultTry.getCause().getCause()).isInstanceOf(WebServiceException.class); + Assertions.assertThat(resultTry.getCause().getCause()).isInstanceOf(HelloWorldException.class); } @Test @@ -205,7 +205,7 @@ public void shouldCompleteFutureAfterThreeAttemptsInCaseOfExceptionAtAsyncStage( private void shouldCompleteFutureAfterAttemptsInCaseOfExceptionAtAsyncStage(int noOfAttempts) { CompletableFuture failedFuture = new CompletableFuture<>(); - failedFuture.completeExceptionally(new WebServiceException("BAM!")); + failedFuture.completeExceptionally(new HelloWorldException()); // Given the HelloWorldService throws an exception BDDMockito.given(helloWorldService.returnHelloWorld()) @@ -230,7 +230,7 @@ private void shouldCompleteFutureAfterAttemptsInCaseOfExceptionAtAsyncStage(int // Then the helloWorldService should be invoked n + 1 times BDDMockito.then(helloWorldService).should(Mockito.times(noOfAttempts)).returnHelloWorld(); Assertions.assertThat(resultTry.isFailure()).isTrue(); - Assertions.assertThat(resultTry.getCause().getCause()).isInstanceOf(WebServiceException.class); + Assertions.assertThat(resultTry.getCause().getCause()).isInstanceOf(HelloWorldException.class); } private void shouldCompleteFutureAfterAttemptsInCaseOfRetyOnResultAtAsyncStage(int noOfAttempts, diff --git a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/EventPublisherTest.java b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/EventPublisherTest.java index 92a7e3a717..e04aa7fda4 100644 --- a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/EventPublisherTest.java +++ b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/EventPublisherTest.java @@ -21,6 +21,7 @@ import io.github.resilience4j.retry.Retry; import io.github.resilience4j.retry.RetryConfig; import io.github.resilience4j.retry.event.RetryEvent; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.reactivex.subscribers.TestSubscriber; import io.vavr.CheckedRunnable; @@ -31,7 +32,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.io.IOException; import static io.github.resilience4j.adapter.RxJava2Adapter.toFlowable; @@ -51,7 +51,7 @@ public void setUp(){ @Test public void shouldReturnAfterThreeAttempts() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).given(helloWorldService).sayHelloWorld(); // Create a Retry with default configuration Retry retry = Retry.ofDefaults("id"); @@ -69,7 +69,7 @@ public void shouldReturnAfterThreeAttempts() { // and the result should be a failure Assertions.assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - Assertions.assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + Assertions.assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); Assertions.assertThat(sleptTime).isEqualTo(RetryConfig.DEFAULT_WAIT_DURATION*2); testSubscriber.assertValueCount(3) @@ -79,7 +79,7 @@ public void shouldReturnAfterThreeAttempts() { @Test public void shouldReturnAfterTwoAttempts() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).willDoNothing().given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).willDoNothing().given(helloWorldService).sayHelloWorld(); // Create a Retry with default configuration Retry retry = Retry.ofDefaults("id"); @@ -104,7 +104,7 @@ public void shouldReturnAfterTwoAttempts() { @Test public void shouldIgnoreError() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).willDoNothing().given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).willDoNothing().given(helloWorldService).sayHelloWorld(); // Create a Retry with default configuration RetryConfig config = RetryConfig.custom() diff --git a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/RunnableRetryTest.java b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/RunnableRetryTest.java index 46a139ac0c..873f8eb650 100644 --- a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/RunnableRetryTest.java +++ b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/RunnableRetryTest.java @@ -21,6 +21,7 @@ import io.github.resilience4j.retry.IntervalFunction; import io.github.resilience4j.retry.Retry; import io.github.resilience4j.retry.RetryConfig; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.vavr.CheckedRunnable; import io.vavr.Predicates; @@ -31,7 +32,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.time.Duration; import static io.vavr.API.*; @@ -65,7 +65,7 @@ public void shouldNotRetry() { @Test public void testDecorateRunnable() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).given(helloWorldService).sayHelloWorld(); // Create a Retry with default configuration Retry retry = Retry.ofDefaults("id"); @@ -80,7 +80,7 @@ public void testDecorateRunnable() { // and the result should be a failure Assertions.assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - Assertions.assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + Assertions.assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); Assertions.assertThat(sleptTime).isEqualTo(RetryConfig.DEFAULT_WAIT_DURATION*2); } @@ -99,7 +99,7 @@ public void testExecuteRunnable() { @Test public void shouldReturnAfterThreeAttempts() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).given(helloWorldService).sayHelloWorld(); // Create a Retry with default configuration Retry retry = Retry.ofDefaults("id"); @@ -114,14 +114,14 @@ public void shouldReturnAfterThreeAttempts() { // and the result should be a failure Assertions.assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - Assertions.assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + Assertions.assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); Assertions.assertThat(sleptTime).isEqualTo(RetryConfig.DEFAULT_WAIT_DURATION*2); } @Test public void shouldReturnAfterOneAttempt() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).given(helloWorldService).sayHelloWorld(); // Create a Retry with default configuration RetryConfig config = RetryConfig.custom().maxAttempts(1).build(); @@ -137,19 +137,19 @@ public void shouldReturnAfterOneAttempt() { // and the result should be a failure Assertions.assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - Assertions.assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + Assertions.assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); Assertions.assertThat(sleptTime).isEqualTo(0); } @Test public void shouldReturnAfterOneAttemptAndIgnoreException() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).given(helloWorldService).sayHelloWorld(); // Create a Retry with default configuration RetryConfig config = RetryConfig.custom() .retryOnException(throwable -> Match(throwable).of( - Case($(Predicates.instanceOf(WebServiceException.class)), false), + Case($(Predicates.instanceOf(HelloWorldException.class)), false), Case($(), true))) .build(); Retry retry = Retry.of("id", config); @@ -165,14 +165,14 @@ public void shouldReturnAfterOneAttemptAndIgnoreException() { // and the result should be a failure Assertions.assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - Assertions.assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + Assertions.assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); Assertions.assertThat(sleptTime).isEqualTo(0); } @Test public void shouldTakeIntoAccountBackoffFunction() { // Given the HelloWorldService throws an exception - BDDMockito.willThrow(new WebServiceException("BAM!")).given(helloWorldService).sayHelloWorld(); + BDDMockito.willThrow(new HelloWorldException()).given(helloWorldService).sayHelloWorld(); // Create a Retry with a backoff function squaring the interval RetryConfig config = RetryConfig diff --git a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/SupplierRetryTest.java b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/SupplierRetryTest.java index d808d81c89..c4f3f2607e 100644 --- a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/SupplierRetryTest.java +++ b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/SupplierRetryTest.java @@ -22,6 +22,7 @@ import io.github.resilience4j.retry.Retry; import io.github.resilience4j.retry.RetryConfig; import io.github.resilience4j.test.AsyncHelloWorldService; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.vavr.API; import io.vavr.CheckedFunction0; @@ -34,7 +35,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.util.concurrent.Callable; import java.util.concurrent.CompletionStage; import java.util.concurrent.Executors; @@ -136,7 +136,7 @@ public void shouldNotRetryDecoratedEither() { .maxAttempts(2).build(); Retry retry = Retry.of("id", tryAgain); // Decorate the invocation of the HelloWorldService - Either result = retry.executeEitherSupplier(helloWorldService::returnEither); + Either result = retry.executeEitherSupplier(helloWorldService::returnEither); // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnEither(); @@ -169,7 +169,7 @@ public void shouldRetryDecoratedEither() { .maxAttempts(2).build(); Retry retry = Retry.of("id", tryAgain); // Decorate the invocation of the HelloWorldService - Either result = retry.executeEitherSupplier(helloWorldService::returnEither); + Either result = retry.executeEitherSupplier(helloWorldService::returnEither); BDDMockito.then(helloWorldService).should(Mockito.times(2)).returnEither(); assertThat(result.get()).isEqualTo("Hello world"); @@ -178,7 +178,7 @@ public void shouldRetryDecoratedEither() { @Test public void shouldFailToRetryDecoratedTry() { // Given the HelloWorldService returns Hello world - BDDMockito.given(helloWorldService.returnTry()).willReturn(Try.failure(new WebServiceException("BAM!"))); + BDDMockito.given(helloWorldService.returnTry()).willReturn(Try.failure(new HelloWorldException())); // Create a Retry with default configuration final RetryConfig tryAgain = RetryConfig.custom() .maxAttempts(2).build(); @@ -188,32 +188,32 @@ public void shouldFailToRetryDecoratedTry() { BDDMockito.then(helloWorldService).should(Mockito.times(2)).returnTry(); assertThat(result.isFailure()).isTrue(); - assertThat(result.getCause()).isInstanceOf(WebServiceException.class); + assertThat(result.getCause()).isInstanceOf(HelloWorldException.class); } @Test public void shouldFailToRetryDecoratedEither() { // Given the HelloWorldService returns Hello world - BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new WebServiceException("BAM!"))); + BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new HelloWorldException())); // Create a Retry with default configuration final RetryConfig tryAgain = RetryConfig.custom() .maxAttempts(2).build(); Retry retry = Retry.of("id", tryAgain); // Decorate the invocation of the HelloWorldService - Either result = retry.executeEitherSupplier(helloWorldService::returnEither); + Either result = retry.executeEitherSupplier(helloWorldService::returnEither); BDDMockito.then(helloWorldService).should(Mockito.times(2)).returnEither(); assertThat(result.isLeft()).isTrue(); - assertThat(result.getLeft()).isInstanceOf(WebServiceException.class); + assertThat(result.getLeft()).isInstanceOf(HelloWorldException.class); } @Test public void shouldIgnoreExceptionOfDecoratedTry() { // Given the HelloWorldService returns Hello world - BDDMockito.given(helloWorldService.returnTry()).willReturn(Try.failure(new WebServiceException("BAM!"))); + BDDMockito.given(helloWorldService.returnTry()).willReturn(Try.failure(new HelloWorldException())); // Create a Retry with default configuration final RetryConfig tryAgain = RetryConfig.custom() - .ignoreExceptions(WebServiceException.class) + .ignoreExceptions(HelloWorldException.class) .maxAttempts(2).build(); Retry retry = Retry.of("id", tryAgain); // Decorate the invocation of the HelloWorldService @@ -222,31 +222,31 @@ public void shouldIgnoreExceptionOfDecoratedTry() { // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnTry(); assertThat(result.isFailure()).isTrue(); - assertThat(result.getCause()).isInstanceOf(WebServiceException.class); + assertThat(result.getCause()).isInstanceOf(HelloWorldException.class); } @Test public void shouldIgnoreExceptionOfDecoratedEither() { // Given the HelloWorldService returns Hello world - BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new WebServiceException("BAM!"))); + BDDMockito.given(helloWorldService.returnEither()).willReturn(Either.left(new HelloWorldException())); // Create a Retry with default configuration final RetryConfig tryAgain = RetryConfig.custom() - .ignoreExceptions(WebServiceException.class) + .ignoreExceptions(HelloWorldException.class) .maxAttempts(2).build(); Retry retry = Retry.of("id", tryAgain); // Decorate the invocation of the HelloWorldService - Either result = retry.executeEitherSupplier(helloWorldService::returnEither); + Either result = retry.executeEitherSupplier(helloWorldService::returnEither); // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnEither(); assertThat(result.isLeft()).isTrue(); - assertThat(result.getLeft()).isInstanceOf(WebServiceException.class); + assertThat(result.getLeft()).isInstanceOf(HelloWorldException.class); } @Test public void testDecorateSupplier() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -267,9 +267,9 @@ public void testDecorateSupplier() { public void testDecorateSupplierAndInvokeTwice() { // Given the HelloWorldService throws an exception BDDMockito.given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")) + .willThrow(new HelloWorldException()) .willReturn("Hello world") - .willThrow(new WebServiceException("BAM!")) + .willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -292,7 +292,7 @@ public void testDecorateSupplierAndInvokeTwice() { @Test public void testDecorateCallable() throws Exception { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -312,7 +312,7 @@ public void testDecorateCallable() throws Exception { @Test public void testDecorateCallableWithRetryResult() throws Exception { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -334,7 +334,7 @@ public void testDecorateCallableWithRetryResult() throws Exception { @Test public void testExecuteCallable() throws Exception { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -353,7 +353,7 @@ public void testExecuteCallable() throws Exception { @Test public void testExecuteSupplier() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -371,7 +371,7 @@ public void testExecuteSupplier() { @Test public void testExecuteSupplierWithResult() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -391,7 +391,7 @@ public void testExecuteSupplierWithResult() { @Test public void shouldReturnSuccessfullyAfterSecondAttempt() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()) .willReturn("Hello world"); // Create a Retry with default configuration @@ -412,7 +412,7 @@ public void shouldReturnSuccessfullyAfterSecondAttempt() { @Test public void shouldReturnAfterThreeAttempts() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")); + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()); // Create a Retry with default configuration Retry retry = Retry.ofDefaults("id"); @@ -428,14 +428,14 @@ public void shouldReturnAfterThreeAttempts() { // and the result should be a failure assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); assertThat(sleptTime).isEqualTo(RetryConfig.DEFAULT_WAIT_DURATION * 2); } @Test public void shouldReturnAfterOneAttempt() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")); + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()); // Create a Retry with custom configuration RetryConfig config = RetryConfig.custom().maxAttempts(1).build(); @@ -452,19 +452,19 @@ public void shouldReturnAfterOneAttempt() { // and the result should be a failure assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); assertThat(sleptTime).isEqualTo(0); } @Test public void shouldReturnAfterOneAttemptAndIgnoreException() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")); + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()); // Create a Retry with default configuration RetryConfig config = RetryConfig.custom() .retryOnException(throwable -> API.Match(throwable).of( - API.Case($(Predicates.instanceOf(WebServiceException.class)), false), + API.Case($(Predicates.instanceOf(HelloWorldException.class)), false), API.Case($(), true))) .build(); Retry retry = Retry.of("id", config); @@ -480,14 +480,14 @@ public void shouldReturnAfterOneAttemptAndIgnoreException() { // and the result should be a failure assertThat(result.isFailure()).isTrue(); // and the returned exception should be of type RuntimeException - assertThat(result.failed().get()).isInstanceOf(WebServiceException.class); + assertThat(result.failed().get()).isInstanceOf(HelloWorldException.class); assertThat(sleptTime).isEqualTo(0); } @Test public void shouldReturnAfterThreeAttemptsAndRecover() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")); + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()); // Create a Retry with default configuration Retry retry = Retry.ofDefaults("id"); @@ -510,9 +510,9 @@ public void shouldReturnAfterThreeAttemptsAndRecover() { @Test public void shouldReturnAfterThreeAttemptsAndRecoverWithResult() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")) + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()) .willReturn("Hello world") - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); // Create a Retry with default configuration final RetryConfig tryAgain = RetryConfig.custom().retryOnResult(s -> s.contains("Hello world")) @@ -536,7 +536,7 @@ public void shouldReturnAfterThreeAttemptsAndRecoverWithResult() { @Test public void shouldTakeIntoAccountBackoffFunction() { // Given the HelloWorldService throws an exception - BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new WebServiceException("BAM!")); + BDDMockito.given(helloWorldService.returnHelloWorld()).willThrow(new HelloWorldException()); // Create a Retry with a backoff function doubling the interval RetryConfig config = RetryConfig.custom().intervalFunction(IntervalFunction.ofExponentialBackoff(500, 2.0)) diff --git a/resilience4j-rxjava2/src/test/java/io/github/resilience4j/retry/transformer/RetryTransformerTest.java b/resilience4j-rxjava2/src/test/java/io/github/resilience4j/retry/transformer/RetryTransformerTest.java index 6569f493b7..d53471d175 100644 --- a/resilience4j-rxjava2/src/test/java/io/github/resilience4j/retry/transformer/RetryTransformerTest.java +++ b/resilience4j-rxjava2/src/test/java/io/github/resilience4j/retry/transformer/RetryTransformerTest.java @@ -18,6 +18,7 @@ import io.github.resilience4j.retry.Retry; import io.github.resilience4j.retry.RetryConfig; +import io.github.resilience4j.test.HelloWorldException; import io.github.resilience4j.test.HelloWorldService; import io.reactivex.*; import org.junit.Before; @@ -25,7 +26,6 @@ import org.mockito.BDDMockito; import org.mockito.Mockito; -import javax.xml.ws.WebServiceException; import java.io.IOException; import java.time.Duration; @@ -51,8 +51,8 @@ public void returnOnCompleteUsingSingle() { given(helloWorldService.returnHelloWorld()) .willReturn("Hello world") - .willThrow(new WebServiceException("BAM!")) - .willThrow(new WebServiceException("BAM!")) + .willThrow(new HelloWorldException()) + .willThrow(new HelloWorldException()) .willReturn("Hello world"); //When @@ -136,20 +136,20 @@ public void returnOnErrorUsingSingle() { Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Single.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); Single.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -169,13 +169,13 @@ public void doNotRetryFromPredicateUsingSingle() { .maxAttempts(3).build(); Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Single.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -245,8 +245,8 @@ public void returnOnCompleteUsingMaybe() { given(helloWorldService.returnHelloWorld()) .willReturn("Hello world") - .willThrow(new WebServiceException("BAM!")) - .willThrow(new WebServiceException("BAM!")) + .willThrow(new HelloWorldException()) + .willThrow(new HelloWorldException()) .willReturn("Hello world"); //When @@ -281,20 +281,20 @@ public void returnOnErrorUsingMaybe() { Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Maybe.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); Maybe.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -314,13 +314,13 @@ public void doNotRetryFromPredicateUsingMaybe() { .maxAttempts(3).build(); Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Maybe.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -389,8 +389,8 @@ public void returnOnCompleteUsingCompletable() { Retry retry = Retry.of("testName", config); RetryTransformer retryTransformer = RetryTransformer.of(retry); doNothing() - .doThrow(new WebServiceException("BAM!")) - .doThrow(new WebServiceException("BAM!")) + .doThrow(new HelloWorldException()) + .doThrow(new HelloWorldException()) .doNothing() .when(helloWorldService).sayHelloWorld(); @@ -423,20 +423,20 @@ public void returnOnErrorUsingCompletable() { RetryConfig config = retryConfig(); Retry retry = Retry.of("testName", config); RetryTransformer retryTransformer = RetryTransformer.of(retry); - doThrow(new WebServiceException("BAM!")).when(helloWorldService).sayHelloWorld(); + doThrow(new HelloWorldException()).when(helloWorldService).sayHelloWorld(); //When Completable.fromRunnable(helloWorldService::sayHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); Completable.fromRunnable(helloWorldService::sayHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -455,13 +455,13 @@ public void doNotRetryFromPredicateUsingCompletable() { .waitDuration(Duration.ofMillis(50)) .maxAttempts(3).build(); Retry retry = Retry.of("testName", config); - doThrow(new WebServiceException("BAM!")).when(helloWorldService).sayHelloWorld(); + doThrow(new HelloWorldException()).when(helloWorldService).sayHelloWorld(); //When Completable.fromRunnable(helloWorldService::sayHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -480,20 +480,20 @@ public void returnOnCompleteUsingObservable() { RetryTransformer retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -512,20 +512,20 @@ public void returnOnErrorUsingObservable() { RetryTransformer retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -545,13 +545,13 @@ public void doNotRetryFromPredicateUsingObservable() { .maxAttempts(3).build(); Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Observable.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -621,20 +621,20 @@ public void returnOnCompleteUsingFlowable() { RetryTransformer retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -653,20 +653,20 @@ public void returnOnErrorUsingFlowable() { RetryTransformer retryTransformer = RetryTransformer.of(retry); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(retryTransformer) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then @@ -686,13 +686,13 @@ public void doNotRetryFromPredicateUsingFlowable() { .maxAttempts(3).build(); Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) - .willThrow(new WebServiceException("BAM!")); + .willThrow(new HelloWorldException()); //When Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() - .assertError(WebServiceException.class) + .assertError(HelloWorldException.class) .assertNotComplete() .assertSubscribed(); //Then diff --git a/resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldException.java b/resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldException.java new file mode 100644 index 0000000000..ef754a18b4 --- /dev/null +++ b/resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldException.java @@ -0,0 +1,12 @@ +package io.github.resilience4j.test; + +public class HelloWorldException extends RuntimeException { + + public HelloWorldException() { + super("BAM!"); + } + + public HelloWorldException(String message) { + super(message); + } +} diff --git a/resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldService.java b/resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldService.java index 0cc318ccef..28697c6901 100644 --- a/resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldService.java +++ b/resilience4j-test/src/main/java/io/github/resilience4j/test/HelloWorldService.java @@ -21,14 +21,13 @@ import io.vavr.control.Either; import io.vavr.control.Try; -import javax.xml.ws.WebServiceException; import java.io.IOException; public interface HelloWorldService { String returnHelloWorld(); - Either returnEither(); + Either returnEither(); Try returnTry();