Skip to content

Commit

Permalink
Merge pull request #527 from mattrjacobs/always-pass-non-null-ex-to-o…
Browse files Browse the repository at this point in the history
…n-error-hook

Creating a synthetic exception in the semaphore execution and short-circuited case
  • Loading branch information
mattrjacobs committed Jan 19, 2015
2 parents f4e0bb6 + e20fe47 commit f0c4c90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void call() {
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
getFallbackOrThrowException(HystrixEventType.SEMAPHORE_REJECTED, FailureType.REJECTED_SEMAPHORE_EXECUTION, "could not acquire a semaphore for execution").
getFallbackOrThrowException(HystrixEventType.SEMAPHORE_REJECTED, FailureType.REJECTED_SEMAPHORE_EXECUTION, "could not acquire a semaphore for execution", new RuntimeException("could not acquire a semaphore for execution")).
map(new Func1<R, R>() {

@Override
Expand All @@ -420,7 +420,7 @@ public R call(R t1) {
metrics.markShortCircuited();
// short-circuit and go directly to fallback (or throw an exception if no fallback implemented)
try {
getFallbackOrThrowException(HystrixEventType.SHORT_CIRCUITED, FailureType.SHORTCIRCUIT, "short-circuited")
getFallbackOrThrowException(HystrixEventType.SHORT_CIRCUITED, FailureType.SHORTCIRCUIT, "short-circuited", new RuntimeException("Hystrix circuit short-circuited and is OPEN"))
.map(new Func1<R, R>() {

@Override
Expand Down Expand Up @@ -772,13 +772,6 @@ public void call() {
}
}

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

/**
* @throws HystrixRuntimeException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4426,7 +4426,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 @@ -4496,7 +4496,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 @@ -4751,7 +4751,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 @@ -4879,7 +4879,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 @@ -4915,7 +4915,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 @@ -4987,7 +4987,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
Original file line number Diff line number Diff line change
Expand Up @@ -4012,7 +4012,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 @@ -4082,7 +4082,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 @@ -4337,7 +4337,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 @@ -4465,7 +4465,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 @@ -4501,7 +4501,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 @@ -4573,7 +4573,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 f0c4c90

Please sign in to comment.