Skip to content

Commit

Permalink
Merge pull request #582 from mattrjacobs/reinstate-nonblocking-queue-…
Browse files Browse the repository at this point in the history
…tests

Add nonblocking HystrixCommandTest.queue() unit tests back
  • Loading branch information
mattrjacobs committed Jan 28, 2015
2 parents 05ce2a1 + d7de465 commit 8c16e2f
Showing 1 changed file with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3519,7 +3519,7 @@ public void run() {
private <T> void assertHooksOnSuccess(Func0<TestHystrixCommand<T>> ctor, Action1<TestHystrixCommand<T>> assertion) {
assertExecute(ctor.call(), assertion, true);
assertBlockingQueue(ctor.call(), assertion, true);
//assertNonBlockingQueue(ctor.call(), assertion, true);
assertNonBlockingQueue(ctor.call(), assertion, true, false);
assertBlockingObserve(ctor.call(), assertion, true);
assertNonBlockingObserve(ctor.call(), assertion, true);
}
Expand All @@ -3533,11 +3533,36 @@ private <T> void assertHooksOnSuccess(Func0<TestHystrixCommand<T>> ctor, Action1
private <T> void assertHooksOnFailure(Func0<TestHystrixCommand<T>> ctor, Action1<TestHystrixCommand<T>> assertion) {
assertExecute(ctor.call(), assertion, false);
assertBlockingQueue(ctor.call(), assertion, false);
//assertNonBlockingQueue(ctor.call(), assertion, false);
assertNonBlockingQueue(ctor.call(), assertion, false, false);
assertBlockingObserve(ctor.call(), assertion, false);
assertNonBlockingObserve(ctor.call(), assertion, false);
}


/**
* Run the command in multiple modes and check that the hook assertions hold in each and that the command fails
* @param ctor {@link com.netflix.hystrix.HystrixCommandTest.TestHystrixCommand} constructor
* @param assertion sequence of assertions to check after the command has completed
* @param <T> type of object returned by command
*/
private <T> void assertHooksOnFailure(Func0<TestHystrixCommand<T>> ctor, Action1<TestHystrixCommand<T>> assertion, boolean failFast) {
assertExecute(ctor.call(), assertion, false);
assertBlockingQueue(ctor.call(), assertion, false);
assertNonBlockingQueue(ctor.call(), assertion, false, failFast);
assertBlockingObserve(ctor.call(), assertion, false);
assertNonBlockingObserve(ctor.call(), assertion, false);
}

/**
* Run the command in multiple modes and check that the hook assertions hold in each and that the command fails as soon as possible
* @param ctor {@link com.netflix.hystrix.HystrixCommandTest.TestHystrixCommand} constructor
* @param assertion sequence of assertions to check after the command has completed
* @param <T> type of object returned by command
*/
private <T> void assertHooksOnFailFast(Func0<TestHystrixCommand<T>> ctor, Action1<TestHystrixCommand<T>> assertion) {
assertHooksOnFailure(ctor, assertion, true);
}

/**
* Run the command via {@link com.netflix.hystrix.HystrixCommand#execute()} and then assert
* @param command command to run
Expand Down Expand Up @@ -3603,9 +3628,24 @@ private <T> void assertBlockingQueue(TestHystrixCommand<T> command, Action1<Test
* @param isSuccess should the command succeed?
* @param <T> type of object returned by command
*/
private <T> void assertNonBlockingQueue(TestHystrixCommand<T> command, Action1<TestHystrixCommand<T>> assertion, boolean isSuccess) {
private <T> void assertNonBlockingQueue(TestHystrixCommand<T> command, Action1<TestHystrixCommand<T>> assertion, boolean isSuccess, boolean failFast) {
System.out.println("Running command.queue(), sleeping the test thread until command is complete, and then running assertions...");
Future<T> f = command.queue();
Future<T> f = null;
if (failFast) {
try {
f = command.queue();
fail("Expected a failure when queuing the command");
} catch (Exception ex) {
System.out.println("Received expected fail fast ex : " + ex);
ex.printStackTrace();
}
} else {
try {
f = command.queue();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
awaitCommandCompletion(command);

assertion.call(command);
Expand Down Expand Up @@ -4226,7 +4266,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookThreadPoolQueueFullNoFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4320,7 +4360,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookThreadPoolQueueFullUnsuccessfulFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4367,7 +4407,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookThreadPoolFullNoFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4457,7 +4497,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookThreadPoolFullUnsuccessfulFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4500,7 +4540,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookThreadShortCircuitNoFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4570,7 +4610,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookThreadShortCircuitUnsuccessfulFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4797,7 +4837,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookSemaphoreRejectedNoFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4925,7 +4965,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookSemaphoreRejectedUnsuccessfulFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -4988,7 +5028,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookSemaphoreShortCircuitNoFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down Expand Up @@ -5060,7 +5100,7 @@ public void call(TestHystrixCommand<Boolean> command) {
*/
@Test
public void testExecutionHookSemaphoreShortCircuitUnsuccessfulFallback() {
assertHooksOnFailure(
assertHooksOnFailFast(
new Func0<TestHystrixCommand<Boolean>>() {
@Override
public TestHystrixCommand<Boolean> call() {
Expand Down

0 comments on commit 8c16e2f

Please sign in to comment.