Skip to content

Commit

Permalink
Merge pull request Netflix#954 from mattrjacobs/fix-unit-tests-after-…
Browse files Browse the repository at this point in the history
…concurrency-strategy-fix

Fix test assertions after fixes in Netflix#951
  • Loading branch information
mattrjacobs committed Oct 21, 2015
2 parents 4dec35d + 202cf4f commit 43724f5
Showing 1 changed file with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void reset() {
*/
@Test
public void testCommandRequiresContextConcurrencyStrategyProvidesIt() {
HystrixPlugins.getInstance().registerConcurrencyStrategy(new CustomConcurrencyStrategy(true));
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is set up properly
HystrixRequestContext context = HystrixRequestContext.initializeContext();
Expand All @@ -69,22 +70,12 @@ public void testCommandRequiresContextConcurrencyStrategyProvidesIt() {

//context is not set up
HystrixRequestContext.setContextOnCurrentThread(null);
try {
HystrixCommand<Boolean> cmd2 = new TestCommand(true, true);
assertTrue(cmd2.execute()); //command execution throws with missing context
fail("command should fail and throw (no fallback)");
} catch (IllegalStateException ise) {
//expected
ise.printStackTrace();
}

try {
printRequestLog();
fail("static access to HystrixRequestLog should fail and throw");
} catch (IllegalStateException ise) {
//expected
ise.printStackTrace();
}
HystrixCommand<Boolean> cmd2 = new TestCommand(true, true);
assertTrue(cmd2.execute()); //command execution not affected by missing context
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd2.currentRequestLog);
}

/**
Expand Down Expand Up @@ -149,13 +140,10 @@ public void testCommandDoesNotRequireContextConcurrencyStrategyProvidesIt() {
HystrixRequestContext.setContextOnCurrentThread(null);
HystrixCommand<Boolean> cmd2 = new TestCommand(false, false);
assertTrue(cmd2.execute()); //command execution not affected by missing context
try {
printRequestLog();
fail("static access to HystrixRequestLog fails");
} catch (IllegalStateException ise) {
//expected
ise.printStackTrace();
}
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd1.currentRequestLog);
}

/**
Expand Down

0 comments on commit 43724f5

Please sign in to comment.