15
15
16
16
public class HystrixTimeoutTest {
17
17
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
-
33
18
@ Test
34
19
public void givenInputBobAndDefaultSettings_whenExecuted_thenReturnHelloBob (){
35
20
assertThat (new CommandHelloWorld ("Bob" ).execute (), equalTo ("Hello Bob!" ));
@@ -38,35 +23,43 @@ public void givenInputBobAndDefaultSettings_whenExecuted_thenReturnHelloBob(){
38
23
@ Test
39
24
public void givenSvcTimeoutOf100AndDefaultSettings_whenExecuted_thenReturnSuccess ()
40
25
throws InterruptedException {
41
-
42
26
HystrixCommand .Setter config = HystrixCommand
43
27
.Setter
44
- .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroup1" ));
45
-
28
+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroup2" ));
46
29
assertThat (new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (100 )).execute (),
47
30
equalTo ("Success" ));
48
31
}
49
32
50
- @ Test
33
+ @ Test ( expected = HystrixRuntimeException . class )
51
34
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" ));
53
38
new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (10_000 )).execute ();
54
39
}
55
40
56
41
@ Test
57
42
public void givenSvcTimeoutOf5000AndExecTimeoutOf10000__whenExecuted_thenReturnSuccess ()
58
43
throws InterruptedException {
44
+
45
+ HystrixCommand .Setter config = HystrixCommand
46
+ .Setter
47
+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupTest4" ));
48
+ HystrixCommandProperties .Setter commandProperties = HystrixCommandProperties .Setter ();
59
49
commandProperties .withExecutionTimeoutInMilliseconds (10_000 );
60
50
config .andCommandPropertiesDefaults (commandProperties );
61
51
62
52
assertThat (new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (500 )).execute (),
63
53
equalTo ("Success" ));
64
54
}
65
55
66
- @ Test
56
+ @ Test ( expected = HystrixRuntimeException . class )
67
57
public void givenSvcTimeoutOf15000AndExecTimeoutOf5000__whenExecuted_thenExpectHRE ()
68
58
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 ();
70
63
commandProperties .withExecutionTimeoutInMilliseconds (5_000 );
71
64
config .andCommandPropertiesDefaults (commandProperties );
72
65
new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (15_000 )).execute ();
@@ -75,6 +68,11 @@ public void givenSvcTimeoutOf15000AndExecTimeoutOf5000__whenExecuted_thenExpectH
75
68
@ Test
76
69
public void givenSvcTimeoutOf500AndExecTimeoutOf10000AndThreadPool__whenExecuted_thenReturnSuccess ()
77
70
throws InterruptedException {
71
+
72
+ HystrixCommand .Setter config = HystrixCommand
73
+ .Setter
74
+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupThreadPool" ));
75
+ HystrixCommandProperties .Setter commandProperties = HystrixCommandProperties .Setter ();
78
76
commandProperties .withExecutionTimeoutInMilliseconds (10_000 );
79
77
config .andCommandPropertiesDefaults (commandProperties );
80
78
config .andThreadPoolPropertiesDefaults (HystrixThreadPoolProperties .Setter ()
@@ -90,6 +88,10 @@ public void givenSvcTimeoutOf500AndExecTimeoutOf10000AndThreadPool__whenExecuted
90
88
public void givenCircuitBreakerSetup__whenRemoteSvcCmdExecuted_thenReturnSuccess ()
91
89
throws InterruptedException {
92
90
91
+ HystrixCommand .Setter config = HystrixCommand
92
+ .Setter
93
+ .withGroupKey (HystrixCommandGroupKey .Factory .asKey ("RemoteServiceGroupCircuitBreakerTest" ));
94
+ HystrixCommandProperties .Setter commandProperties = HystrixCommandProperties .Setter ();
93
95
commandProperties .withExecutionTimeoutInMilliseconds (1000 );
94
96
95
97
commandProperties .withCircuitBreakerSleepWindowInMilliseconds (4000 );
@@ -105,8 +107,9 @@ public void givenCircuitBreakerSetup__whenRemoteSvcCmdExecuted_thenReturnSuccess
105
107
.withCoreSize (1 )
106
108
.withQueueSizeRejectionThreshold (1 ));
107
109
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 ));
110
113
Thread .sleep (5000 );
111
114
112
115
assertThat (new RemoteServiceTestCommand (config , new RemoteServiceTestSimulator (500 )).execute (),
@@ -117,7 +120,7 @@ public void givenCircuitBreakerSetup__whenRemoteSvcCmdExecuted_thenReturnSuccess
117
120
equalTo ("Success" ));
118
121
}
119
122
120
- public String invokeRemoteService (long timeout ) throws InterruptedException {
123
+ public String invokeRemoteService (HystrixCommand . Setter config , int timeout ) throws InterruptedException {
121
124
String response = null ;
122
125
try {
123
126
response = new RemoteServiceTestCommand (config ,
0 commit comments