From 1e213bdddc1ce5b9053a2d07ad35ccde0482fefc Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Mon, 19 Jan 2015 13:36:04 -0800 Subject: [PATCH] Creating a synthetic exception in the semaphore execution and short-circuited case that gets passed to onError() hook --- .../com/netflix/hystrix/HystrixCommand.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java index dee01958f..b20b4559d 100755 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java @@ -819,7 +819,7 @@ public void call(Subscriber 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); @@ -1140,7 +1140,7 @@ private Subscription subscribeWithSemaphoreIsolation(final Observer 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(); @@ -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 */ @@ -6328,7 +6321,7 @@ public TestHystrixCommand call() { public void call(TestHystrixCommand 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); @@ -6398,7 +6391,7 @@ public TestHystrixCommand call() { public void call(TestHystrixCommand 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); @@ -6653,7 +6646,7 @@ public void run() { public void call(TestHystrixCommand 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); @@ -6781,7 +6774,7 @@ public void run() { public void call(TestHystrixCommand 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); @@ -6817,7 +6810,7 @@ public TestHystrixCommand call() { public void call(TestHystrixCommand 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); @@ -6889,7 +6882,7 @@ public TestHystrixCommand call() { public void call(TestHystrixCommand 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);