Skip to content

Commit

Permalink
Merge pull request #963 from mattrjacobs/deflake-custom-concurrency-test
Browse files Browse the repository at this point in the history
Splitting up some tests for (hopefully) repeatable CI success
  • Loading branch information
mattrjacobs committed Nov 10, 2015
2 parents 4a0d280 + 6ce4a56 commit 696aada
Showing 1 changed file with 91 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void init() {
public void reset() {
HystrixRequestContext.setContextOnCurrentThread(null);
HystrixPropertiesFactory.reset();
HystrixPlugins.reset();
}

/**
Expand All @@ -51,31 +50,45 @@ public void reset() {
** useRequestCache : true
** useRequestLog : true
*
* OUTCOME: RequestLog set up properly in command if context initialized, static access depends on context initialization
* and will throw if not initialized
* OUTCOME: RequestLog set up properly in command
*/
@Test
public void testCommandRequiresContextConcurrencyStrategyProvidesIt() {
public void testCommandRequiresContextConcurrencyStrategyProvidesItContextSetUpCorrectly() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is set up properly
HystrixRequestContext context = HystrixRequestContext.initializeContext();
HystrixCommand<Boolean> cmd1 = new TestCommand(true, true);
assertTrue(cmd1.execute());
HystrixCommand<Boolean> cmd = new TestCommand(true, true);
assertTrue(cmd.execute());
printRequestLog();
assertNotNull(HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
assertNotNull(cmd1.currentRequestLog);
assertNotNull(cmd.currentRequestLog);
context.shutdown();
}

/**
* HystrixConcurrencyStrategy
** useDefaultRequestContext : true
* HystrixCommand
** useRequestCache : true
** useRequestLog : true
*
* OUTCOME: RequestLog not set up properly in command, static access is null
*/
@Test
public void testCommandRequiresContextConcurrencyStrategyProvidesItContextLeftUninitialized() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is not set up
HystrixRequestContext.setContextOnCurrentThread(null);
HystrixCommand<Boolean> cmd2 = new TestCommand(true, true);
assertTrue(cmd2.execute()); //command execution not affected by missing context
HystrixCommand<Boolean> cmd = new TestCommand(true, true);
assertTrue(cmd.execute()); //command execution not affected by missing context
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd2.currentRequestLog);
assertNull(cmd.currentRequestLog);
}

/**
Expand All @@ -88,28 +101,43 @@ public void testCommandRequiresContextConcurrencyStrategyProvidesIt() {
* OUTCOME: RequestLog not set up in command, not available statically
*/
@Test
public void testCommandRequiresContextConcurrencyStrategyDoesNotProvideIt() {
public void testCommandRequiresContextConcurrencyStrategyDoesNotProvideItContextSetUpCorrectly() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is set up properly
HystrixRequestContext context = HystrixRequestContext.initializeContext();
HystrixCommand<Boolean> cmd1 = new TestCommand(true, true);
assertTrue(cmd1.execute());
HystrixCommand<Boolean> cmd = new TestCommand(true, true);
assertTrue(cmd.execute());
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd1.currentRequestLog);
assertNull(cmd.currentRequestLog);
context.shutdown();
}

/**
* HystrixConcurrencyStrategy
** useDefaultRequestContext : false
* HystrixCommand
** useRequestCache : true
** useRequestLog : true
*
* OUTCOME: RequestLog not set up in command, not available statically
*/
@Test
public void testCommandRequiresContextConcurrencyStrategyDoesNotProvideItContextLeftUninitialized() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is not set up
HystrixRequestContext.setContextOnCurrentThread(null);
HystrixCommand<Boolean> cmd2 = new TestCommand(true, true);
assertTrue(cmd2.execute()); //command execution not affected by missing context
HystrixCommand<Boolean> cmd = new TestCommand(true, true);
assertTrue(cmd.execute()); //command execution not affected by missing context
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd2.currentRequestLog);
assertNull(cmd.currentRequestLog);
}

/**
Expand All @@ -119,33 +147,49 @@ public void testCommandRequiresContextConcurrencyStrategyDoesNotProvideIt() {
** useRequestCache : false
** useRequestLog : false
*
* OUTCOME: RequestLog not set up in command, static access depends on context initialization and will throw if not initialized
* OUTCOME: RequestLog not set up in command, static access works properly
*/
@Test
public void testCommandDoesNotRequireContextConcurrencyStrategyProvidesIt() {
public void testCommandDoesNotRequireContextConcurrencyStrategyProvidesItContextSetUpCorrectly() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is set up properly
HystrixRequestContext context = HystrixRequestContext.initializeContext();
HystrixCommand<Boolean> cmd1 = new TestCommand(false, false);
assertTrue(cmd1.execute());
HystrixCommand<Boolean> cmd = new TestCommand(false, false);
assertTrue(cmd.execute());
printRequestLog();
assertNotNull(HystrixRequestLog.getCurrentRequest());
assertNotNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd1.currentRequestLog);
assertNull(cmd.currentRequestLog);
context.shutdown();
}

/**
* HystrixConcurrencyStrategy
** useDefaultRequestContext : true
* HystrixCommand
** useRequestCache : false
** useRequestLog : false
*
* OUTCOME: RequestLog not set up in command, static access is null
*/
@Test
public void testCommandDoesNotRequireContextConcurrencyStrategyProvidesItContextLeftUninitialized() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(true);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is not set up
HystrixRequestContext.setContextOnCurrentThread(null);
HystrixCommand<Boolean> cmd2 = new TestCommand(false, false);
assertTrue(cmd2.execute()); //command execution not affected by missing context
HystrixCommand<Boolean> cmd = new TestCommand(false, false);
assertTrue(cmd.execute()); //command execution not affected by missing context
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd1.currentRequestLog);
assertNull(cmd.currentRequestLog);
}


/**
* HystrixConcurrencyStrategy
** useDefaultRequestContext : false
Expand All @@ -156,28 +200,43 @@ public void testCommandDoesNotRequireContextConcurrencyStrategyProvidesIt() {
* OUTCOME: RequestLog not set up in command, not available statically
*/
@Test
public void testCommandDoesNotRequireContextConcurrencyStrategyDoesNotProvideIt() {
public void testCommandDoesNotRequireContextConcurrencyStrategyDoesNotProvideItContextSetUpCorrectly() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is set up properly
HystrixRequestContext context = HystrixRequestContext.initializeContext();
HystrixCommand<Boolean> cmd1 = new TestCommand(true, true);
assertTrue(cmd1.execute());
HystrixCommand<Boolean> cmd = new TestCommand(true, true);
assertTrue(cmd.execute());
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd1.currentRequestLog);
assertNull(cmd.currentRequestLog);
context.shutdown();
}

/**
* HystrixConcurrencyStrategy
** useDefaultRequestContext : false
* HystrixCommand
** useRequestCache : false
** useRequestLog : false
*
* OUTCOME: RequestLog not set up in command, not available statically
*/
@Test
public void testCommandDoesNotRequireContextConcurrencyStrategyDoesNotProvideItContextLeftUninitialized() {
HystrixConcurrencyStrategy strategy = new CustomConcurrencyStrategy(false);
HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);

//context is not set up
HystrixRequestContext.setContextOnCurrentThread(null);
HystrixCommand<Boolean> cmd2 = new TestCommand(true, true);
assertTrue(cmd2.execute()); //command execution unaffected by missing context
HystrixCommand<Boolean> cmd = new TestCommand(true, true);
assertTrue(cmd.execute()); //command execution unaffected by missing context
printRequestLog();
assertNull(HystrixRequestLog.getCurrentRequest());
assertNull(HystrixRequestLog.getCurrentRequest(strategy));
assertNull(cmd2.currentRequestLog);
assertNull(cmd.currentRequestLog);
}


Expand Down

0 comments on commit 696aada

Please sign in to comment.