Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a synthetic exception in the semaphore execution and short-circuited case #528

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ public void call(Subscriber<? super R> observer) {
metrics.markShortCircuited();
// short-circuit and go directly to fallback (or throw an exception if no fallback implemented)
try {
observer.onNext(getFallbackOrThrowException(HystrixEventType.SHORT_CIRCUITED, FailureType.SHORTCIRCUIT, "short-circuited"));
observer.onNext(getFallbackOrThrowException(HystrixEventType.SHORT_CIRCUITED, FailureType.SHORTCIRCUIT, "short-circuited", new RuntimeException("Hystrix circuit short-circuited and is OPEN")));
observer.onCompleted();
} catch (Exception e) {
observer.onError(e);
Expand Down Expand Up @@ -1140,7 +1140,7 @@ private Subscription subscribeWithSemaphoreIsolation(final Observer<? super R> o
metrics.markSemaphoreRejection();
logger.debug("HystrixCommand Execution Rejection by Semaphore."); // debug only since we're throwing the exception and someone higher will do something with it
// retrieve a fallback or throw an exception if no fallback available
observer.onNext(getFallbackOrThrowException(HystrixEventType.SEMAPHORE_REJECTED, FailureType.REJECTED_SEMAPHORE_EXECUTION, "could not acquire a semaphore for execution"));
observer.onNext(getFallbackOrThrowException(HystrixEventType.SEMAPHORE_REJECTED, FailureType.REJECTED_SEMAPHORE_EXECUTION, "could not acquire a semaphore for execution", new RuntimeException("could not acquire a semaphore for execution")));
observer.onCompleted();
// empty subscription since we executed synchronously
return Subscriptions.empty();
Expand Down Expand Up @@ -1616,13 +1616,6 @@ private TryableSemaphore getExecutionSemaphore() {
}
}

/**
* @throws HystrixRuntimeException
*/
private R getFallbackOrThrowException(HystrixEventType eventType, FailureType failureType, String message) {
return getFallbackOrThrowException(eventType, failureType, message, null);
}

/**
* @throws HystrixRuntimeException
*/
Expand Down Expand Up @@ -6328,7 +6321,7 @@ public TestHystrixCommand<Boolean> call() {
public void call(TestHystrixCommand<Boolean> command) {
assertEquals(1, command.builder.executionHook.startExecute.get());
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
assertNull(command.builder.executionHook.endExecuteFailureException); //by design, ex=null in this case
assertEquals(RuntimeException.class, command.builder.executionHook.endExecuteFailureException.getClass());
assertEquals(FailureType.SHORTCIRCUIT, command.builder.executionHook.endExecuteFailureType);
assertEquals(0, command.builder.executionHook.startRun.get());
assertNull(command.builder.executionHook.runSuccessResponse);
Expand Down Expand Up @@ -6398,7 +6391,7 @@ public TestHystrixCommand<Boolean> call() {
public void call(TestHystrixCommand<Boolean> command) {
assertEquals(1, command.builder.executionHook.startExecute.get());
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
assertNull(command.builder.executionHook.endExecuteFailureException); //by design, ex=null in this case
assertEquals(RuntimeException.class, command.builder.executionHook.endExecuteFailureException.getClass());
assertEquals(FailureType.SHORTCIRCUIT, command.builder.executionHook.endExecuteFailureType);
assertEquals(0, command.builder.executionHook.startRun.get());
assertNull(command.builder.executionHook.runSuccessResponse);
Expand Down Expand Up @@ -6653,7 +6646,7 @@ public void run() {
public void call(TestHystrixCommand<Boolean> command) {
assertEquals(1, command.builder.executionHook.startExecute.get());
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
assertNull(command.builder.executionHook.endExecuteFailureException); //by design, null=ex in this case
assertEquals(RuntimeException.class, command.builder.executionHook.endExecuteFailureException.getClass());
assertEquals(FailureType.REJECTED_SEMAPHORE_EXECUTION, command.builder.executionHook.endExecuteFailureType);
assertEquals(0, command.builder.executionHook.startRun.get());
assertNull(command.builder.executionHook.runSuccessResponse);
Expand Down Expand Up @@ -6781,7 +6774,7 @@ public void run() {
public void call(TestHystrixCommand<Boolean> command) {
assertEquals(1, command.builder.executionHook.startExecute.get());
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
assertNull(command.builder.executionHook.endExecuteFailureException); //by design, ex=null in this case
assertEquals(RuntimeException.class, command.builder.executionHook.endExecuteFailureException.getClass());
assertEquals(FailureType.REJECTED_SEMAPHORE_EXECUTION, command.builder.executionHook.endExecuteFailureType);
assertEquals(0, command.builder.executionHook.startRun.get());
assertNull(command.builder.executionHook.runSuccessResponse);
Expand Down Expand Up @@ -6817,7 +6810,7 @@ public TestHystrixCommand<Boolean> call() {
public void call(TestHystrixCommand<Boolean> command) {
assertEquals(1, command.builder.executionHook.startExecute.get());
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
assertNull(command.builder.executionHook.endExecuteFailureException); //by design, ex=null in this case
assertEquals(RuntimeException.class, command.builder.executionHook.endExecuteFailureException.getClass());
assertEquals(FailureType.SHORTCIRCUIT, command.builder.executionHook.endExecuteFailureType);
assertEquals(0, command.builder.executionHook.startRun.get());
assertNull(command.builder.executionHook.runSuccessResponse);
Expand Down Expand Up @@ -6889,7 +6882,7 @@ public TestHystrixCommand<Boolean> call() {
public void call(TestHystrixCommand<Boolean> command) {
assertEquals(1, command.builder.executionHook.startExecute.get());
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
assertNull(command.builder.executionHook.endExecuteFailureException); //by design, ex=null in this case
assertEquals(RuntimeException.class, command.builder.executionHook.endExecuteFailureException.getClass());
assertEquals(FailureType.SHORTCIRCUIT, command.builder.executionHook.endExecuteFailureType);
assertEquals(0, command.builder.executionHook.startRun.get());
assertNull(command.builder.executionHook.runSuccessResponse);
Expand Down