Skip to content

Commit

Permalink
Merge pull request #528 from mattrjacobs/1.3.x-always-pass-non-null-e…
Browse files Browse the repository at this point in the history
…x-to-on-error-hook

Creating a synthetic exception in the semaphore execution and short-circuited case
  • Loading branch information
mattrjacobs committed Jan 19, 2015
2 parents 4bcb63f + 1e213bd commit e421650
Showing 1 changed file with 8 additions and 15 deletions.
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

0 comments on commit e421650

Please sign in to comment.