Skip to content

Commit c3fcdc3

Browse files
author
sbalachandran
committed
Fixed Failig unit tests
1 parent f7995e4 commit c3fcdc3

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

hystrix/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@
6262
<artifactId>hystrix-metrics-event-stream</artifactId>
6363
<version>${hystrix-metrics-event-stream.version}</version>
6464
</dependency>
65-
<dependency>
65+
<!--<dependency>
6666
<groupId>com.netflix.hystrix</groupId>
6767
<artifactId>hystrix-dashboard</artifactId>
6868
<version>${hystrix-dashboard.version}</version>
69-
</dependency>
69+
</dependency>-->
7070
<dependency>
7171
<groupId>com.netflix.rxjava</groupId>
7272
<artifactId>rxjava-core</artifactId>

hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java

+28-25
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@
1515

1616
public 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

Comments
 (0)