Skip to content

Commit

Permalink
Merge pull request #1380 from mattrjacobs/add-jmh-test-when-circuit-o…
Browse files Browse the repository at this point in the history
…pened

Add jmh test when circuit opened
  • Loading branch information
mattrjacobs committed Oct 12, 2016
2 parents ad5e3f4 + da29bfd commit 7c42aa3
Showing 1 changed file with 39 additions and 9 deletions.
Expand Up @@ -51,29 +51,53 @@
*/
public class CommandExecutionPerfTest {

static HystrixCommandProperties.Setter threadIsolatedCommandDefaults = HystrixCommandProperties.Setter()
private static HystrixCommandProperties.Setter threadIsolatedCommandDefaults = HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)
.withRequestCacheEnabled(true)
.withRequestLogEnabled(true)
.withCircuitBreakerEnabled(true)
.withCircuitBreakerForceOpen(false);

static HystrixCommandProperties.Setter semaphoreIsolatedCommandDefaults = HystrixCommandProperties.Setter()
private static HystrixCommandProperties.Setter threadIsolatedFailFastCommandDefaults = HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)
.withRequestCacheEnabled(true)
.withRequestLogEnabled(true)
.withCircuitBreakerEnabled(true)
.withCircuitBreakerForceOpen(true);

private static HystrixCommandProperties.Setter semaphoreIsolatedCommandDefaults = HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
.withRequestCacheEnabled(true)
.withRequestLogEnabled(true)
.withCircuitBreakerEnabled(true)
.withCircuitBreakerForceOpen(false);

static HystrixThreadPoolProperties.Setter threadPoolDefaults = HystrixThreadPoolProperties.Setter()
private static HystrixCommandProperties.Setter semaphoreIsolatedFailFastCommandDefaults = HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
.withRequestCacheEnabled(true)
.withRequestLogEnabled(true)
.withCircuitBreakerEnabled(true)
.withCircuitBreakerForceOpen(true);

private static HystrixThreadPoolProperties.Setter threadPoolDefaults = HystrixThreadPoolProperties.Setter()
.withCoreSize(100);

static HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("PERF");
private static HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey("PERF");

private static HystrixCommandProperties.Setter getCommandSetter(HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy) {
private static HystrixCommandProperties.Setter getCommandSetter(HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy, boolean forceOpen) {
switch (isolationStrategy) {
case THREAD: return threadIsolatedCommandDefaults;
default: return semaphoreIsolatedCommandDefaults;
case THREAD:
if (forceOpen) {
return threadIsolatedFailFastCommandDefaults;
} else {
return threadIsolatedCommandDefaults;
}
default:
if (forceOpen) {
return semaphoreIsolatedFailFastCommandDefaults;
} else {
return semaphoreIsolatedCommandDefaults;
}
}
}

Expand All @@ -89,6 +113,9 @@ public static class CommandState {
HystrixCommand<Integer> command;
HystrixRequestContext requestContext;

@Param({"true", "false"})
public boolean forceOpen;

@Param({"true", "false"})
public boolean setUpRequestContext;

Expand All @@ -107,7 +134,7 @@ public void setUp() {

command = new HystrixCommand<Integer>(
HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("PERF"))
.andCommandPropertiesDefaults(getCommandSetter(isolationStrategy))
.andCommandPropertiesDefaults(getCommandSetter(isolationStrategy, forceOpen))
.andThreadPoolPropertiesDefaults(threadPoolDefaults)
) {
@Override
Expand Down Expand Up @@ -136,6 +163,9 @@ public static class ObservableCommandState {
HystrixObservableCommand<Integer> command;
HystrixRequestContext requestContext;

@Param({"true", "false"})
public boolean forceOpen;

@Param({"true", "false"})
public boolean setUpRequestContext;

Expand All @@ -151,7 +181,7 @@ public void setUp() {

command = new HystrixObservableCommand<Integer>(
HystrixObservableCommand.Setter.withGroupKey(groupKey)
.andCommandPropertiesDefaults(getCommandSetter(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE))
.andCommandPropertiesDefaults(getCommandSetter(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE, forceOpen))
) {
@Override
protected Observable<Integer> construct() {
Expand Down

0 comments on commit 7c42aa3

Please sign in to comment.