Skip to content

Commit

Permalink
Remove javax.xml.ws.WebServiceException (ReactiveX#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexmind authored and RobWin committed Sep 19, 2019
1 parent fe24182 commit 42b3a04
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<CompletionStage<String>> completionStageSupplier = () -> {
throw new WebServiceException("BAM! At sync stage");
throw new HelloWorldException();
};

Supplier<CompletionStage<String>> decoratedCompletionStageSupplier =
Expand All @@ -521,15 +521,15 @@ 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;
}
);
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

@Test
public void shouldDecorateCompletionStageAndReturnWithExceptionAtAsyncStage() throws ExecutionException, InterruptedException {
public void shouldDecorateCompletionStageAndReturnWithExceptionAtAsyncStage() {

// Given
Bulkhead bulkhead = Bulkhead.of("test", config);
Expand All @@ -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);
Expand All @@ -565,7 +565,7 @@ public void shouldChainDecoratedFunctions() throws ExecutionException, Interrupt

// and I chain a function with map
Try<String> result = Try.of(decoratedSupplier)
.mapTry(decoratedFunction::apply);
.mapTry(decoratedFunction);

// Then
assertThat(result.isSuccess()).isTrue();
Expand Down Expand Up @@ -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<Exception, String> result = bulkhead.executeEitherSupplier(helloWorldService::returnEither);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> cacheContext = Cache.of(cache);
cacheContext.getEventPublisher().onError(event ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<CompletionStage<String>> completionStageSupplier =
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<Exception, String> result = circuitBreaker.executeEitherSupplier(helloWorldService::returnEither);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.Test;

import javax.xml.ws.WebServiceException;
import java.io.IOException;
import java.util.concurrent.Callable;

Expand Down Expand Up @@ -69,15 +68,15 @@ public void shouldRecoverCallableFromException() throws Exception {
assertThat(result).isEqualTo("Bla");
}

@Test(expected = WebServiceException.class)
@Test(expected = RuntimeException.class)
public void shouldRethrowException() throws Exception {

Callable<String> callable = () -> {
throw new IOException("BAM!");
};
//When
Callable<String> callableWithRecovery = CallableUtils.recover(callable, (ex) -> {
throw new WebServiceException();
throw new RuntimeException();
});

callableWithRecovery.call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,15 +67,15 @@ public void shouldRecoverSupplierFromException() {
assertThat(result).isEqualTo("Bla");
}

@Test(expected = WebServiceException.class)
@Test(expected = RuntimeException.class)
public void shouldRethrowException() {

Supplier<String> supplier = () -> {
throw new RuntimeException("BAM!");
};
//When
Supplier<String> supplierWithRecovery = SupplierUtils.recover(supplier, (ex) -> {
throw new WebServiceException();
throw new RuntimeException();
});

supplierWithRecovery.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -175,11 +176,11 @@ public void shouldExecuteCompletionStageSupplier() throws Throwable {
public void shouldExecuteCompletionStageAndReturnWithExceptionAtSyncStage() throws Throwable {

Supplier<CompletionStage<String>> 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);
Expand All @@ -190,15 +191,15 @@ 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<CompletionStage<String>> completionStageSupplier =
() -> CompletableFuture.supplyAsync(helloWorldService::returnHelloWorld);

CompletionStage<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -316,7 +315,7 @@ public void decorateTrySupplier() throws Exception {

@Test
public void decorateEitherSupplier() throws Exception {
Supplier<Either<WebServiceException, String>> supplier = mock(Supplier.class);
Supplier<Either<RuntimeException, String>> supplier = mock(Supplier.class);
BDDMockito.given(supplier.get()).willReturn(Either.right("Resource"));

when(limit.acquirePermission()).thenReturn(true);
Expand All @@ -342,7 +341,7 @@ public void shouldExecuteTrySupplierAndReturnRequestNotPermitted() throws Except

@Test
public void shouldExecuteEitherSupplierAndReturnRequestNotPermitted() throws Exception {
Supplier<Either<WebServiceException, String>> supplier = mock(Supplier.class);
Supplier<Either<RuntimeException, String>> supplier = mock(Supplier.class);

when(limit.acquirePermission()).thenReturn(false);

Expand Down
Loading

0 comments on commit 42b3a04

Please sign in to comment.