1818import org .junit .Before ;
1919
2020import com .netflix .hystrix .HystrixCommand .Setter ;
21+ import org .junit .Test ;
22+
23+ import static org .junit .Assert .assertEquals ;
24+ import static org .junit .Assert .assertNull ;
25+ import static org .junit .Assert .assertTrue ;
2126
2227public class HystrixTest {
2328 @ Before
2429 public void reset () {
2530 Hystrix .reset ();
2631 }
2732
28- /* @Test
33+ @ Test
2934 public void testNotInThread () {
3035 assertNull (Hystrix .getCurrentThreadExecutingCommand ());
3136 }
@@ -100,7 +105,7 @@ public void testInsideHystrixSemaphoreExecute() {
100105
101106 HystrixCommand <Boolean > command = new HystrixCommand <Boolean >(Setter .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("TestUtil" ))
102107 .andCommandKey (HystrixCommandKey .Factory .asKey ("SemaphoreIsolatedCommandName" ))
103- .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) {
108+ .andCommandPropertiesDefaults (HystrixCommandProperties .Setter ().withExecutionIsolationStrategy (HystrixCommandProperties . ExecutionIsolationStrategy .SEMAPHORE ))) {
104109
105110 @ Override
106111 protected Boolean run () {
@@ -122,7 +127,7 @@ public void testInsideHystrixSemaphoreQueue() throws Exception {
122127
123128 HystrixCommand <Boolean > command = new HystrixCommand <Boolean >(Setter .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("TestUtil" ))
124129 .andCommandKey (HystrixCommandKey .Factory .asKey ("SemaphoreIsolatedCommandName" ))
125- .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) {
130+ .andCommandPropertiesDefaults (HystrixCommandProperties .Setter ().withExecutionIsolationStrategy (HystrixCommandProperties . ExecutionIsolationStrategy .SEMAPHORE ))) {
126131
127132 @ Override
128133 protected Boolean run () {
@@ -145,7 +150,7 @@ public void testThreadNestedInsideHystrixSemaphore() {
145150 HystrixCommand <Boolean > command = new HystrixCommand <Boolean >(Setter
146151 .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("TestUtil" ))
147152 .andCommandKey (HystrixCommandKey .Factory .asKey ("OuterSemaphoreCommand" ))
148- .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE))) {
153+ .andCommandPropertiesDefaults (HystrixCommandProperties .Setter ().withExecutionIsolationStrategy (HystrixCommandProperties . ExecutionIsolationStrategy .SEMAPHORE ))) {
149154
150155 @ Override
151156 protected Boolean run () {
@@ -186,22 +191,25 @@ protected Boolean run() {
186191 //see https://github.com/Netflix/Hystrix/issues/280
187192 @ Test
188193 public void testResetCommandProperties () {
189- HystrixCommand<Boolean> cmd1 = new ResettableCommand(100, 10);
190- assertEquals(100L, (long) cmd1.getProperties().executionIsolationThreadTimeoutInMilliseconds().get());
194+ HystrixCommand <Boolean > cmd1 = new ResettableCommand (100 , 1 , 10 );
195+ assertEquals (100L , (long ) cmd1 .getProperties ().executionTimeoutInMilliseconds ().get ());
196+ assertEquals (1L , (long ) cmd1 .getProperties ().executionIsolationSemaphoreMaxConcurrentRequests ().get ());
191197 assertEquals (10L , (long ) cmd1 .threadPool .getExecutor ().getCorePoolSize ());
192198
193199 Hystrix .reset ();
194200
195- HystrixCommand<Boolean> cmd2 = new ResettableCommand(700, 40);
196- assertEquals(700L, (long) cmd2.getProperties().executionIsolationThreadTimeoutInMilliseconds().get());
201+ HystrixCommand <Boolean > cmd2 = new ResettableCommand (700 , 2 , 40 );
202+ assertEquals (700L , (long ) cmd2 .getProperties ().executionTimeoutInMilliseconds ().get ());
203+ assertEquals (2L , (long ) cmd2 .getProperties ().executionIsolationSemaphoreMaxConcurrentRequests ().get ());
197204 assertEquals (40L , (long ) cmd2 .threadPool .getExecutor ().getCorePoolSize ());
198-
199- }*/
205+ }
200206
201207 private static class ResettableCommand extends HystrixCommand <Boolean > {
202- ResettableCommand (int timeout , int poolCoreSize ) {
208+ ResettableCommand (int timeout , int semaphoreCount , int poolCoreSize ) {
203209 super (Setter .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("GROUP" ))
204- .andCommandPropertiesDefaults (HystrixCommandProperties .Setter ().withExecutionTimeoutInMilliseconds (timeout ))
210+ .andCommandPropertiesDefaults (HystrixCommandProperties .Setter ()
211+ .withExecutionTimeoutInMilliseconds (timeout )
212+ .withExecutionIsolationSemaphoreMaxConcurrentRequests (semaphoreCount ))
205213 .andThreadPoolPropertiesDefaults (HystrixThreadPoolProperties .Setter ().withCoreSize (poolCoreSize )));
206214 }
207215
0 commit comments