|
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 4 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 5 | +import static org.assertj.core.api.Assertions.catchThrowable; |
5 | 6 | import static org.mockito.Mockito.spy; |
6 | 7 | import static org.mockito.Mockito.times; |
7 | 8 | import static org.mockito.Mockito.verify; |
|
21 | 22 | import com.sap.cloud.sdk.cloudplatform.resilience.ResilienceRuntimeException; |
22 | 23 | import com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException; |
23 | 24 |
|
| 25 | +import io.github.resilience4j.circuitbreaker.CallNotPermittedException; |
24 | 26 | import lombok.Getter; |
25 | 27 | import lombok.RequiredArgsConstructor; |
26 | 28 |
|
@@ -76,12 +78,22 @@ void testCircuitBreakerOpens() |
76 | 78 | assertThat(callResults).hasSize(attemptedInvocations); |
77 | 79 | assertThat(callResults).startsWith(attempts.toArray(new Boolean[0])); |
78 | 80 |
|
79 | | - assertThatThrownBy(wrappedCallable::call) |
| 81 | + Throwable thrown = catchThrowable(wrappedCallable::call); |
| 82 | + |
| 83 | + assertThat(thrown) |
80 | 84 | .isExactlyInstanceOf(ResilienceRuntimeException.class) |
81 | 85 | .hasCauseExactlyInstanceOf(ThreadContextExecutionException.class) |
82 | 86 | .hasRootCauseExactlyInstanceOf(Exception.class) |
83 | 87 | .hasMessage( |
84 | | - "com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: java.lang.Exception: Simulated failure, attempt nr: 3"); |
| 88 | + "CircuitBreaker 'circuitbreaker.test.2' is OPEN and does not permit further calls. Triggered by java.lang.Exception: Simulated failure, attempt nr: 3"); |
| 89 | + |
| 90 | + assertThat(thrown.getCause()).hasMessage("java.lang.Exception: Simulated failure, attempt nr: 3"); |
| 91 | + |
| 92 | + assertThat(thrown.getSuppressed().length).isEqualTo(1); |
| 93 | + Throwable suppressed = thrown.getSuppressed()[0]; |
| 94 | + assertThat(suppressed) |
| 95 | + .isExactlyInstanceOf(CallNotPermittedException.class) |
| 96 | + .hasMessage("CircuitBreaker 'circuitbreaker.test.2' is OPEN and does not permit further calls"); |
85 | 97 |
|
86 | 98 | verify(callable, times(circuitBreakerConfiguration.closedBufferSize())).call(); |
87 | 99 | } |
|
0 commit comments