Skip to content

Commit 9ea19cf

Browse files
committed
Merge remote-tracking branch 'origin/main' into javadoc-aggregate-delombok
2 parents 4d63eb8 + 48616ac commit 9ea19cf

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

cloudplatform/resilience4j/src/main/java/com/sap/cloud/sdk/cloudplatform/resilience4j/DefaultCircuitBreakerProvider.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public CircuitBreaker getCircuitBreaker( @Nonnull final ResilienceConfiguration
6666
return circuitBreaker;
6767
}
6868

69-
@SuppressWarnings( "PMD.PreserveStackTrace" ) // The circuit breaker stack-trace doesn't contain any info
7069
@Nonnull
7170
@Override
7271
public <T> Callable<T> decorateCallable(
@@ -83,9 +82,19 @@ public <T> Callable<T> decorateCallable(
8382
return CircuitBreaker.decorateCallable(circuitBreaker, callable).call();
8483
}
8584
catch( CallNotPermittedException e ) {
86-
log.debug("Circuit breaker '{}' is open, call not permitted.", circuitBreaker.getName());
85+
val message =
86+
"CircuitBreaker '" + circuitBreaker.getName() + "' is OPEN and does not permit further calls";
87+
log.debug(message);
8788
val lastException = lastExceptions.get(circuitBreaker.getName());
88-
throw new ResilienceRuntimeException(lastException != null ? lastException : e);
89+
if( lastException == null ) {
90+
throw new ResilienceRuntimeException(message, e);
91+
}
92+
val resilienceRuntimeException =
93+
new ResilienceRuntimeException(
94+
message + ". Triggered by " + lastException.getMessage(),
95+
lastException);
96+
resilienceRuntimeException.addSuppressed(e);
97+
throw resilienceRuntimeException;
8998
}
9099
};
91100
}

cloudplatform/resilience4j/src/test/java/com/sap/cloud/sdk/cloudplatform/resilience4j/CircuitBreakerTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5+
import static org.assertj.core.api.Assertions.catchThrowable;
56
import static org.mockito.Mockito.spy;
67
import static org.mockito.Mockito.times;
78
import static org.mockito.Mockito.verify;
@@ -21,6 +22,7 @@
2122
import com.sap.cloud.sdk.cloudplatform.resilience.ResilienceRuntimeException;
2223
import com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException;
2324

25+
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
2426
import lombok.Getter;
2527
import lombok.RequiredArgsConstructor;
2628

@@ -76,12 +78,22 @@ void testCircuitBreakerOpens()
7678
assertThat(callResults).hasSize(attemptedInvocations);
7779
assertThat(callResults).startsWith(attempts.toArray(new Boolean[0]));
7880

79-
assertThatThrownBy(wrappedCallable::call)
81+
Throwable thrown = catchThrowable(wrappedCallable::call);
82+
83+
assertThat(thrown)
8084
.isExactlyInstanceOf(ResilienceRuntimeException.class)
8185
.hasCauseExactlyInstanceOf(ThreadContextExecutionException.class)
8286
.hasRootCauseExactlyInstanceOf(Exception.class)
8387
.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");
8597

8698
verify(callable, times(circuitBreakerConfiguration.closedBufferSize())).call();
8799
}

release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
### 📈 Improvements
1818

19-
-
19+
- When the circuit breaker opens, the resulting `ResilienceRuntimeException` will have the original `CallNotPermittedException` from the circuit breaker stored as a suppressed exception.
2020

2121
### 🐛 Fixed Issues
2222

0 commit comments

Comments
 (0)