3737import java .util .concurrent .TimeUnit ;
3838
3939public class MultiThreadedMetricsTest {
40+ private static HystrixCommand .Setter threadIsolatedSetter = HystrixCommand .Setter .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("PERF" ))
41+ .andCommandPropertiesDefaults (
42+ HystrixCommandProperties .Setter ()
43+ .withExecutionIsolationStrategy (HystrixCommandProperties .ExecutionIsolationStrategy .THREAD )
44+ .withRequestCacheEnabled (true )
45+ .withRequestLogEnabled (true )
46+ .withCircuitBreakerEnabled (true )
47+ .withCircuitBreakerForceOpen (false )
48+ )
49+ .andThreadPoolPropertiesDefaults (
50+ HystrixThreadPoolProperties .Setter ()
51+ .withCoreSize (100 )
52+ );
53+
54+ private static HystrixCommand .Setter semaphoreIsolatedSetter = HystrixCommand .Setter .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("PERF" ))
55+ .andCommandPropertiesDefaults (
56+ HystrixCommandProperties .Setter ()
57+ .withExecutionIsolationStrategy (HystrixCommandProperties .ExecutionIsolationStrategy .SEMAPHORE )
58+ .withRequestCacheEnabled (true )
59+ .withRequestLogEnabled (true )
60+ .withCircuitBreakerEnabled (true )
61+ .withCircuitBreakerForceOpen (false )
62+ )
63+ .andThreadPoolPropertiesDefaults (
64+ HystrixThreadPoolProperties .Setter ()
65+ .withCoreSize (100 )
66+ );
67+
4068 @ State (Scope .Thread )
4169 public static class CommandState {
4270 HystrixCommand <Integer > command ;
@@ -49,21 +77,14 @@ public static class CommandState {
4977 @ Setup (Level .Invocation )
5078 public void setUp () {
5179 reqContext = HystrixRequestContext .initializeContext ();
52- command = new HystrixCommand <Integer >(
53- HystrixCommand .Setter .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("PERF" ))
54- .andCommandPropertiesDefaults (
55- HystrixCommandProperties .Setter ()
56- .withExecutionIsolationStrategy (isolationStrategy )
57- .withRequestCacheEnabled (true )
58- .withRequestLogEnabled (true )
59- .withCircuitBreakerEnabled (true )
60- .withCircuitBreakerForceOpen (false )
61- )
62- .andThreadPoolPropertiesDefaults (
63- HystrixThreadPoolProperties .Setter ()
64- .withCoreSize (100 )
65- )
66- ) {
80+ HystrixCommand .Setter cachedSetter = null ;
81+ if (isolationStrategy .equals (HystrixCommandProperties .ExecutionIsolationStrategy .THREAD )) {
82+ cachedSetter = threadIsolatedSetter ;
83+ } else {
84+ cachedSetter = semaphoreIsolatedSetter ;
85+ }
86+
87+ command = new HystrixCommand <Integer >(cachedSetter ) {
6788 @ Override
6889 protected Integer run () throws Exception {
6990 return 1 ;
0 commit comments