1515
1616public class HystrixTimeoutTest {
1717
18- private HystrixCommand .Setter config ;
19- private HystrixCommandProperties .Setter commandProperties ;
20-
21-
22- @ Rule
23- public final ExpectedException exception = ExpectedException .none ();
24-
25- @ Before
26- public void setup () {
27- commandProperties = HystrixCommandProperties .Setter ();
28- config = HystrixCommand
29- .Setter
30- .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroup1" ));
31- }
32-
3318 @ Test
3419 public void givenInputBobAndDefaultSettings_whenExecuted_thenReturnHelloBob (){
3520 assertThat (new CommandHelloWorld ("Bob" ).execute (), equalTo ("Hello Bob!" ));
@@ -38,35 +23,43 @@ public void givenInputBobAndDefaultSettings_whenExecuted_thenReturnHelloBob(){
3823 @ Test
3924 public void givenSvcTimeoutOf100AndDefaultSettings_whenExecuted_thenReturnSuccess ()
4025 throws InterruptedException {
41-
4226 HystrixCommand .Setter config = HystrixCommand
4327 .Setter
44- .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroup1" ));
45-
28+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroup2" ));
4629 assertThat (new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (100 )).execute (),
4730 equalTo ("Success" ));
4831 }
4932
50- @ Test
33+ @ Test ( expected = HystrixRuntimeException . class )
5134 public void givenSvcTimeoutOf10000AndDefaultSettings__whenExecuted_thenExpectHRE () throws InterruptedException {
52- exception .expect (HystrixRuntimeException .class );
35+ HystrixCommand .Setter config = HystrixCommand
36+ .Setter
37+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupTest3" ));
5338 new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (10_000 )).execute ();
5439 }
5540
5641 @ Test
5742 public void givenSvcTimeoutOf5000AndExecTimeoutOf10000__whenExecuted_thenReturnSuccess ()
5843 throws InterruptedException {
44+
45+ HystrixCommand .Setter config = HystrixCommand
46+ .Setter
47+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupTest4" ));
48+ HystrixCommandProperties .Setter commandProperties = HystrixCommandProperties .Setter ();
5949 commandProperties .withExecutionTimeoutInMilliseconds (10_000 );
6050 config .andCommandPropertiesDefaults (commandProperties );
6151
6252 assertThat (new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (500 )).execute (),
6353 equalTo ("Success" ));
6454 }
6555
66- @ Test
56+ @ Test ( expected = HystrixRuntimeException . class )
6757 public void givenSvcTimeoutOf15000AndExecTimeoutOf5000__whenExecuted_thenExpectHRE ()
6858 throws InterruptedException {
69- exception .expect (HystrixRuntimeException .class );
59+ HystrixCommand .Setter config = HystrixCommand
60+ .Setter
61+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupTest5" ));
62+ HystrixCommandProperties .Setter commandProperties = HystrixCommandProperties .Setter ();
7063 commandProperties .withExecutionTimeoutInMilliseconds (5_000 );
7164 config .andCommandPropertiesDefaults (commandProperties );
7265 new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (15_000 )).execute ();
@@ -75,6 +68,11 @@ public void givenSvcTimeoutOf15000AndExecTimeoutOf5000__whenExecuted_thenExpectH
7568 @ Test
7669 public void givenSvcTimeoutOf500AndExecTimeoutOf10000AndThreadPool__whenExecuted_thenReturnSuccess ()
7770 throws InterruptedException {
71+
72+ HystrixCommand .Setter config = HystrixCommand
73+ .Setter
74+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupThreadPool" ));
75+ HystrixCommandProperties .Setter commandProperties = HystrixCommandProperties .Setter ();
7876 commandProperties .withExecutionTimeoutInMilliseconds (10_000 );
7977 config .andCommandPropertiesDefaults (commandProperties );
8078 config .andThreadPoolPropertiesDefaults (HystrixThreadPoolProperties .Setter ()
@@ -90,6 +88,10 @@ public void givenSvcTimeoutOf500AndExecTimeoutOf10000AndThreadPool__whenExecuted
9088 public void givenCircuitBreakerSetup__whenRemoteSvcCmdExecuted_thenReturnSuccess ()
9189 throws InterruptedException {
9290
91+ HystrixCommand .Setter config = HystrixCommand
92+ .Setter
93+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupCircuitBreakerTest" ));
94+ HystrixCommandProperties .Setter commandProperties = HystrixCommandProperties .Setter ();
9395 commandProperties .withExecutionTimeoutInMilliseconds (1000 );
9496
9597 commandProperties .withCircuitBreakerSleepWindowInMilliseconds (4000 );
@@ -105,8 +107,9 @@ public void givenCircuitBreakerSetup__whenRemoteSvcCmdExecuted_thenReturnSuccess
105107 .withCoreSize (1 )
106108 .withQueueSizeRejectionThreshold (1 ));
107109
108- assertThat (this .invokeRemoteService (10000 ), equalTo (null ));
109- assertThat (this .invokeRemoteService (10000 ), equalTo (null ));
110+ assertThat (this .invokeRemoteService (config , 10_000 ), equalTo (null ));
111+ assertThat (this .invokeRemoteService (config , 10_000 ), equalTo (null ));
112+ assertThat (this .invokeRemoteService (config , 10_000 ), equalTo (null ));
110113 Thread .sleep (5000 );
111114
112115 assertThat (new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (500 )).execute (),
@@ -117,7 +120,7 @@ public void givenCircuitBreakerSetup__whenRemoteSvcCmdExecuted_thenReturnSuccess
117120 equalTo ("Success" ));
118121 }
119122
120- public String invokeRemoteService (long timeout ) throws InterruptedException {
123+ public String invokeRemoteService (HystrixCommand . Setter config , int timeout ) throws InterruptedException {
121124 String response = null ;
122125 try {
123126 response = new RemoteServiceTestCommand (config ,
0 commit comments