Skip to content

Commit cec25ed

Browse files
author
Matt Jacobs
committed
Fixed up hook ordering in unit tests
1 parent 4a9503d commit cec25ed

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@ private R getFallbackOrThrowException(HystrixEventType eventType, FailureType fa
16321632
metrics.markFallbackSuccess();
16331633
// record the executionResult
16341634
executionResult = executionResult.addEvents(HystrixEventType.FALLBACK_SUCCESS);
1635+
16351636
return executionHook.onComplete(this, fallback);
16361637
} catch (UnsupportedOperationException fe) {
16371638
logger.debug("No fallback for HystrixCommand. ", fe); // debug only since we're throwing the exception and someone higher will do something with it
@@ -5346,7 +5347,7 @@ public void testExecutionHookSuccessfulCommand() {
53465347
assertEquals(1, command.builder.executionHook.threadComplete.get());
53475348

53485349
// expected hook execution sequence
5349-
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5350+
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onComplete - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
53505351

53515352
/* test with queue() */
53525353
command = new SuccessfulTestCommand();
@@ -5382,7 +5383,7 @@ public void testExecutionHookSuccessfulCommand() {
53825383
assertEquals(1, command.builder.executionHook.threadComplete.get());
53835384

53845385
// expected hook execution sequence
5385-
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5386+
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onComplete - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
53865387
}
53875388

53885389
/**
@@ -5437,7 +5438,7 @@ public void testExecutionHookSuccessfulCommandViaFireAndForget() {
54375438
assertEquals(1, command.builder.executionHook.threadComplete.get());
54385439

54395440
// expected hook execution sequence
5440-
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5441+
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onComplete - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
54415442
}
54425443

54435444
/**
@@ -5486,7 +5487,7 @@ public void testExecutionHookSuccessfulCommandWithMultipleGetsOnFuture() {
54865487
assertEquals(1, command.builder.executionHook.threadComplete.get());
54875488

54885489
// expected hook execution sequence
5489-
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5490+
assertEquals("onStart - onThreadStart - onRunStart - onRunSuccess - onComplete - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
54905491
}
54915492

54925493
/**
@@ -5531,7 +5532,7 @@ public void testExecutionHookRunFailureWithoutFallback() {
55315532
assertEquals(1, command.builder.executionHook.threadComplete.get());
55325533

55335534
// expected hook execution sequence
5534-
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5535+
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
55355536

55365537
/* test with queue() */
55375538
command = new UnknownFailureTestCommandWithoutFallback();
@@ -5570,7 +5571,7 @@ public void testExecutionHookRunFailureWithoutFallback() {
55705571
assertEquals(1, command.builder.executionHook.threadComplete.get());
55715572

55725573
// expected hook execution sequence
5573-
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5574+
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
55745575

55755576
}
55765577

@@ -5609,7 +5610,7 @@ public void testExecutionHookRunFailureWithFallback() {
56095610
assertEquals(1, command.builder.executionHook.threadComplete.get());
56105611

56115612
// expected hook execution sequence
5612-
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackSuccess - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5613+
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackSuccess - onComplete - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
56135614

56145615
/* test with queue() */
56155616
command = new KnownFailureTestCommandWithFallback(new TestCircuitBreaker());
@@ -5690,7 +5691,7 @@ public void testExecutionHookRunFailureWithFallbackFailure() {
56905691
assertEquals(1, command.builder.executionHook.threadComplete.get());
56915692

56925693
// expected hook execution sequence
5693-
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5694+
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
56945695

56955696
/* test with queue() */
56965697
command = new KnownFailureTestCommandWithFallbackFailure();
@@ -5729,7 +5730,7 @@ public void testExecutionHookRunFailureWithFallbackFailure() {
57295730
assertEquals(1, command.builder.executionHook.threadComplete.get());
57305731

57315732
// expected hook execution sequence
5732-
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5733+
assertEquals("onStart - onThreadStart - onRunStart - onRunError - onFallbackStart - onFallbackError - onError - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
57335734
}
57345735

57355736
/**
@@ -5780,7 +5781,7 @@ public void testExecutionHookTimeoutWithoutFallback() {
57805781
assertEquals(1, command.builder.executionHook.threadComplete.get());
57815782

57825783
// expected hook execution sequence
5783-
assertEquals("onStart - onThreadStart - onRunStart - onFallbackStart - onFallbackError - onError - onRunSuccess - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5784+
assertEquals("onStart - onThreadStart - onRunStart - onFallbackStart - onFallbackError - onError - onRunSuccess - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
57845785
}
57855786

57865787
/**
@@ -5828,7 +5829,7 @@ public void testExecutionHookTimeoutWithFallback() {
58285829
assertEquals(1, command.builder.executionHook.threadComplete.get());
58295830

58305831
// expected hook execution sequence
5831-
assertEquals("onStart - onThreadStart - onRunStart - onFallbackStart - onFallbackSuccess - onRunSuccess - onThreadComplete - onComplete - ", command.builder.executionHook.executionSequence.toString());
5832+
assertEquals("onStart - onThreadStart - onRunStart - onFallbackStart - onFallbackSuccess - onComplete - onRunSuccess - onThreadComplete - ", command.builder.executionHook.executionSequence.toString());
58325833
}
58335834

58345835
/**
@@ -5931,7 +5932,7 @@ public void testExecutionHookShortCircuitedWithFallbackViaQueue() {
59315932
assertEquals(0, command.builder.executionHook.threadComplete.get());
59325933

59335934
// expected hook execution sequence
5934-
assertEquals("onStart - onFallbackStart - onFallbackError - onError - onComplete - ", command.builder.executionHook.executionSequence.toString());
5935+
assertEquals("onStart - onFallbackStart - onFallbackError - onError - ", command.builder.executionHook.executionSequence.toString());
59355936
}
59365937

59375938
/**
@@ -5979,7 +5980,7 @@ public void testExecutionHookShortCircuitedWithFallbackViaExecute() {
59795980
assertEquals(0, command.builder.executionHook.threadComplete.get());
59805981

59815982
// expected hook execution sequence
5982-
assertEquals("onStart - onFallbackStart - onFallbackError - onError - onComplete - ", command.builder.executionHook.executionSequence.toString());
5983+
assertEquals("onStart - onFallbackStart - onFallbackError - onError - ", command.builder.executionHook.executionSequence.toString());
59835984
}
59845985

59855986
/**
@@ -6108,7 +6109,7 @@ public void testExecutionHookFailureWithSemaphoreIsolation() {
61086109
assertEquals(0, command.builder.executionHook.threadComplete.get());
61096110

61106111
// expected hook execution sequence
6111-
assertEquals("onStart - onFallbackStart - onFallbackError - onError - onComplete - ", command.builder.executionHook.executionSequence.toString());
6112+
assertEquals("onStart - onFallbackStart - onFallbackError - onError - ", command.builder.executionHook.executionSequence.toString());
61126113
}
61136114

61146115
/**
@@ -6146,7 +6147,7 @@ public void testExecutionHookFailedOnHystrixBadRequestWithSemaphoreIsolation() {
61466147
// we should not have a response from execute()
61476148
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
61486149
// we should not have an exception since run() succeeded
6149-
assertNull(command.builder.executionHook.endExecuteFailureException);
6150+
assertNotNull(command.builder.executionHook.endExecuteFailureException);
61506151

61516152
// thread execution
61526153
assertEquals(0, command.builder.executionHook.threadStart.get());

hystrix-core/src/main/java/com/netflix/hystrix/exception/HystrixRuntimeException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class HystrixRuntimeException extends RuntimeException {
3131
private final FailureType failureCause;
3232

3333
public static enum FailureType {
34-
COMMAND_EXCEPTION, TIMEOUT, SHORTCIRCUIT, REJECTED_THREAD_EXECUTION, REJECTED_SEMAPHORE_EXECUTION, REJECTED_SEMAPHORE_FALLBACK
34+
COMMAND_EXCEPTION, TIMEOUT, SHORTCIRCUIT, REJECTED_THREAD_EXECUTION, REJECTED_SEMAPHORE_EXECUTION, BAD_REQUEST_EXCEPTION, REJECTED_SEMAPHORE_FALLBACK
3535
}
3636

3737
public HystrixRuntimeException(FailureType failureCause, Class<? extends HystrixCommand> commandClass, String message, Exception cause, Throwable fallbackException) {

0 commit comments

Comments
 (0)