Skip to content

Commit

Permalink
Fixed up hook ordering in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Jacobs committed Jan 14, 2015
1 parent 4a9503d commit cec25ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 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 @@ -1632,6 +1632,7 @@ private R getFallbackOrThrowException(HystrixEventType eventType, FailureType fa
metrics.markFallbackSuccess();
// record the executionResult
executionResult = executionResult.addEvents(HystrixEventType.FALLBACK_SUCCESS);

return executionHook.onComplete(this, fallback);
} catch (UnsupportedOperationException fe) {
logger.debug("No fallback for HystrixCommand. ", fe); // debug only since we're throwing the exception and someone higher will do something with it
Expand Down Expand Up @@ -5346,7 +5347,7 @@ public void testExecutionHookSuccessfulCommand() {
assertEquals(1, command.builder.executionHook.threadComplete.get());

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

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

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

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

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

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

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

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

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

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

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

}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/**
Expand Down Expand Up @@ -6146,7 +6147,7 @@ public void testExecutionHookFailedOnHystrixBadRequestWithSemaphoreIsolation() {
// we should not have a response from execute()
assertNull(command.builder.executionHook.endExecuteSuccessResponse);
// we should not have an exception since run() succeeded
assertNull(command.builder.executionHook.endExecuteFailureException);
assertNotNull(command.builder.executionHook.endExecuteFailureException);

// thread execution
assertEquals(0, command.builder.executionHook.threadStart.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class HystrixRuntimeException extends RuntimeException {
private final FailureType failureCause;

public static enum FailureType {
COMMAND_EXCEPTION, TIMEOUT, SHORTCIRCUIT, REJECTED_THREAD_EXECUTION, REJECTED_SEMAPHORE_EXECUTION, REJECTED_SEMAPHORE_FALLBACK
COMMAND_EXCEPTION, TIMEOUT, SHORTCIRCUIT, REJECTED_THREAD_EXECUTION, REJECTED_SEMAPHORE_EXECUTION, BAD_REQUEST_EXCEPTION, REJECTED_SEMAPHORE_FALLBACK
}

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

0 comments on commit cec25ed

Please sign in to comment.