diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index 7c80cb8b4..d07e2ff6b 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -613,6 +613,7 @@ public Observable call(Throwable t) { */ try { metrics.markBadRequest(System.currentTimeMillis() - invocationStartTime); + executionResult = executionResult.addEvents(HystrixEventType.BAD_REQUEST); Exception decorated = executionHook.onError(_self, FailureType.BAD_REQUEST_EXCEPTION, (Exception) t); if (decorated instanceof HystrixBadRequestException) { diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/CommonHystrixCommandTests.java b/hystrix-core/src/test/java/com/netflix/hystrix/CommonHystrixCommandTests.java index fad4b1a0a..b8469a9d1 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/CommonHystrixCommandTests.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/CommonHystrixCommandTests.java @@ -157,6 +157,20 @@ public void onNext(Object t) { } } + protected void assertSaneHystrixRequestLog(final int numCommands) { + HystrixRequestLog currentRequestLog = HystrixRequestLog.getCurrentRequest(); + + try { + assertEquals(numCommands, currentRequestLog.getAllExecutedCommands().size()); + assertFalse(currentRequestLog.getExecutedCommandsAsString().contains("Executed")); + assertTrue(currentRequestLog.getAllExecutedCommands().iterator().next().getExecutionEvents().size() >= 1); + //Most commands should have 1 execution event, but fallbacks / responses from cache can cause more than 1. They should never have 0 + } catch (Throwable ex) { + System.out.println("Problematic Request log : " + currentRequestLog.getExecutedCommandsAsString() + " , expected : " + numCommands); + throw new RuntimeException(ex); + } + } + /** * Threadpool with 1 thread, queue of size 1 */ diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java index 8ffd760d2..e7ba1a3dd 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.fail; import java.io.IOException; +import java.util.Iterator; import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CountDownLatch; @@ -120,7 +121,7 @@ public void testExecutionSuccess() { assertEquals(0, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } catch (Exception e) { e.printStackTrace(); @@ -159,6 +160,7 @@ public void testExecutionMultipleTimes() { // we want to get here } assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); + assertSaneHystrixRequestLog(1); } /** @@ -201,7 +203,7 @@ public void testExecutionHystrixFailureWithNoFallback() { assertEquals(100, command.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -242,7 +244,7 @@ public void testExecutionFailureWithNoFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -279,7 +281,7 @@ public void testExecutionFailureWithFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -317,7 +319,7 @@ public void testExecutionFailureWithFallbackFailure() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -354,7 +356,7 @@ public void testQueueSuccess() { assertEquals(0, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -397,7 +399,7 @@ public void testQueueKnownFailureWithNoFallback() { assertEquals(100, command.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -439,7 +441,7 @@ public void testQueueUnknownFailureWithNoFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -476,7 +478,7 @@ public void testQueueFailureWithFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -517,7 +519,7 @@ public void testQueueFailureWithFallbackFailure() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -553,7 +555,7 @@ public void testObserveSuccess() { assertEquals(0, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } catch (Exception e) { e.printStackTrace(); @@ -772,7 +774,7 @@ public void testCircuitBreakerTripsAfterFailures() { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); } /** @@ -830,7 +832,7 @@ public void testCircuitBreakerTripsAfterFailuresViaQueue() { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); } catch (Exception e) { e.printStackTrace(); fail("We should have received fallbacks."); @@ -903,7 +905,7 @@ public void testCircuitBreakerAcrossMultipleCommandsButSameCircuitBreaker() { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); } /** @@ -984,7 +986,7 @@ public void testCircuitBreakerAcrossMultipleCommandsAndDifferentDependency() { assertEquals(100, circuitBreaker_two.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker_two.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); } /** @@ -1017,7 +1019,7 @@ public void testExecutionSuccessWithCircuitBreakerDisabled() { assertEquals(0, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1065,7 +1067,7 @@ public void testExecutionTimeoutWithNoFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1103,7 +1105,7 @@ public void testExecutionTimeoutWithFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1145,7 +1147,7 @@ public void testExecutionTimeoutFallbackFailure() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1197,7 +1199,7 @@ public void testCountersOnExecutionTimeout() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1245,7 +1247,7 @@ public void testQueuedExecutionTimeoutWithNoFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1280,7 +1282,7 @@ public void testQueuedExecutionTimeoutWithFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1324,7 +1326,7 @@ public void testQueuedExecutionTimeoutFallbackFailure() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1372,7 +1374,7 @@ public void testObservedExecutionTimeoutWithNoFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1407,7 +1409,7 @@ public void testObservedExecutionTimeoutWithFallback() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1451,7 +1453,7 @@ public void testObservedExecutionTimeoutFallbackFailure() { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1500,7 +1502,7 @@ public void testShortCircuitFallbackCounter() { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } /** @@ -1582,7 +1584,7 @@ public void run() { assertEquals(50, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } /** @@ -1643,7 +1645,13 @@ public void run() { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(1, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); //pool-filler still going - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + //This is a case where we knowingly walk away from an executing Hystrix thread (the pool-filler). It should have an in-flight status ("Executed"). You should avoid this in a production environment + HystrixRequestLog requestLog = HystrixRequestLog.getCurrentRequest(); + assertEquals(2, requestLog.getAllExecutedCommands().size()); + assertTrue(requestLog.getExecutedCommandsAsString().contains("Executed")); + Iterator> commandIterator = requestLog.getAllExecutedCommands().iterator(); + assertEquals(0, commandIterator.next().getExecutionEvents().size()); //still in flight and unresolved + assertEquals(2, commandIterator.next().getExecutionEvents().size()); //THREAD_POOL_REJECTED , FALLBACK_SUCCESS } /** @@ -1705,7 +1713,13 @@ public void run() { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(1, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); //pool-filler still going - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + //This is a case where we knowingly walk away from an executing Hystrix thread (the pool-filler). It should have an in-flight status ("Executed"). You should avoid this in a production environment + HystrixRequestLog requestLog = HystrixRequestLog.getCurrentRequest(); + assertEquals(2, requestLog.getAllExecutedCommands().size()); + assertTrue(requestLog.getExecutedCommandsAsString().contains("Executed")); + Iterator> commandIterator = requestLog.getAllExecutedCommands().iterator(); + assertEquals(0, commandIterator.next().getExecutionEvents().size()); //still in flight and unresolved + assertEquals(2, commandIterator.next().getExecutionEvents().size()); //THREAD_POOL_REJECTED , FALLBACK_SUCCESS } /** @@ -1781,7 +1795,7 @@ public void run() { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } /** @@ -1863,7 +1877,7 @@ public void testTimedOutCommandDoesNotExecute() { assertEquals(100, s2.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, s2.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } @Test @@ -1943,7 +1957,7 @@ public void testFallbackSemaphore() { assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } @Test @@ -2014,7 +2028,7 @@ public void run() { assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } @Test @@ -2094,7 +2108,7 @@ public void run() { assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } @Test @@ -2160,7 +2174,7 @@ public void run() { System.out.println("**** DONE"); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } @Test @@ -2228,7 +2242,7 @@ public void run() { System.out.println("**** DONE"); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } /** @@ -2444,7 +2458,7 @@ public void testRequestCache1() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } /** @@ -2498,7 +2512,7 @@ public void testRequestCache2() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } /** @@ -2561,7 +2575,7 @@ public void testRequestCache3() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } /** @@ -2630,7 +2644,7 @@ public void testRequestCacheWithSlowExecution() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); System.out.println("HystrixRequestLog: " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); } @@ -2693,7 +2707,7 @@ public void testNoRequestCache3() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } /** @@ -2758,7 +2772,7 @@ public void testRequestCacheViaQueueSemaphore1() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } /** @@ -2819,7 +2833,7 @@ public void testNoRequestCacheViaQueueSemaphore1() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } /** @@ -2876,7 +2890,7 @@ public void testRequestCacheViaExecuteSemaphore1() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } /** @@ -2933,7 +2947,7 @@ public void testNoRequestCacheViaExecuteSemaphore1() { assertEquals(0, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(3, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(3); } @Test @@ -3000,7 +3014,7 @@ public void testNoRequestCacheOnTimeoutThrowsException() throws Exception { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); } @Test @@ -3040,9 +3054,9 @@ public void testRequestCacheOnTimeoutCausesNullPointerException() throws Excepti assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(5, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(5); - HystrixInvokableInfo[] executeCommands = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo[] {}); + HystrixInvokableInfo[] executeCommands = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo[]{}); System.out.println(":executeCommands[0].getExecutionEvents()" + executeCommands[0].getExecutionEvents()); assertEquals(2, executeCommands[0].getExecutionEvents().size()); @@ -3125,7 +3139,7 @@ public void testRequestCacheOnTimeoutThrowsException() throws Exception { assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); } @Test @@ -3196,7 +3210,7 @@ public void testRequestCacheOnThreadRejectionThrowsException() throws Exception assertEquals(100, circuitBreaker.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(4, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(4); } /** @@ -3272,6 +3286,8 @@ public void testBadRequestExceptionViaExecuteInThread() { assertEquals(1, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } /** @@ -3301,6 +3317,8 @@ public void testBadRequestExceptionViaQueueInThread() { assertEquals(1, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } /** @@ -3338,6 +3356,8 @@ public void testBadRequestExceptionViaQueueInThreadOnResponseFromCache() { assertEquals(1, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(2); } /** @@ -3363,6 +3383,8 @@ public void testBadRequestExceptionViaExecuteInSemaphore() { assertEquals(1, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } /** @@ -3392,6 +3414,8 @@ public void testBadRequestExceptionViaQueueInSemaphore() { assertEquals(1, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } /** @@ -3419,6 +3443,8 @@ public void testCheckedExceptionViaExecute() { assertEquals(0, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } /** @@ -3474,6 +3500,8 @@ public void onNext(Boolean args) { assertEquals(0, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } @Test @@ -3504,7 +3532,7 @@ public void testSemaphoreExecutionWithTimeout() { assertEquals(100, cmd.metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, cmd.metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } } @@ -3536,6 +3564,8 @@ public void testRecoverableErrorWithNoFallbackThrowsError() { assertEquals(0, command.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, command.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } @Test @@ -3557,6 +3587,8 @@ public void testRecoverableErrorMaskedByFallbackButLogged() { assertEquals(1, command.metrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS)); assertEquals(0, command.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } @Test @@ -3583,6 +3615,8 @@ public void testUnrecoverableErrorThrownWithNoFallback() { assertEquals(0, command.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, command.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } @Test //even though fallback is implemented, that logic never fires, as this is an unrecoverable error and should be directly propagated to the caller @@ -3612,6 +3646,8 @@ public void testUnrecoverableErrorThrownWithFallback() { assertEquals(0, command.metrics.getRollingCount(HystrixRollingNumberEvent.FALLBACK_REJECTION)); assertEquals(0, command.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } // @Test @@ -3761,7 +3797,6 @@ public void run() { assertEquals(0, cmd.metrics.getCurrentConcurrentExecutionCount()); } - @Override protected void assertHooksOnSuccess(Func0> ctor, Action1> assertion) { assertExecute(ctor.call(), assertion, true); @@ -3946,7 +3981,7 @@ public void testExecutionFailureWithFallbackImplementedButDisabled() { assertEquals(100, commandDisabled.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, commandDisabled.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(2, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(2); } @Test @@ -4042,7 +4077,7 @@ public void call(Throwable t1) { assertEquals(100, command.getBuilder().metrics.getHealthCounts().getErrorPercentage()); assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount()); - assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size()); + assertSaneHystrixRequestLog(1); } @Test @@ -4065,6 +4100,8 @@ public void testExceptionConvertedToBadRequestExceptionInExecutionHookBypassesCi assertEquals(1, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST)); assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount()); + + assertSaneHystrixRequestLog(1); } @Test