diff --git a/hystrix/pom.xml b/hystrix/pom.xml
index 7867bbb955..42828e1c97 100644
--- a/hystrix/pom.xml
+++ b/hystrix/pom.xml
@@ -62,11 +62,11 @@
hystrix-metrics-event-stream
${hystrix-metrics-event-stream.version}
-
+
com.netflix.rxjava
rxjava-core
diff --git a/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java b/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java
index e85f3d7199..bea89248e4 100644
--- a/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java
+++ b/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java
@@ -15,21 +15,6 @@ import static org.hamcrest.Matchers.equalTo;
public class HystrixTimeoutTest {
- private HystrixCommand.Setter config;
- private HystrixCommandProperties.Setter commandProperties;
-
-
- @Rule
- public final ExpectedException exception = ExpectedException.none();
-
- @Before
- public void setup() {
- commandProperties = HystrixCommandProperties.Setter();
- config = HystrixCommand
- .Setter
- .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
- }
-
@Test
public void givenInputBobAndDefaultSettings_whenExecuted_thenReturnHelloBob(){
assertThat(new CommandHelloWorld("Bob").execute(), equalTo("Hello Bob!"));
@@ -38,24 +23,29 @@ public class HystrixTimeoutTest {
@Test
public void givenSvcTimeoutOf100AndDefaultSettings_whenExecuted_thenReturnSuccess()
throws InterruptedException {
-
HystrixCommand.Setter config = HystrixCommand
.Setter
- .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
-
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup2"));
assertThat(new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(100)).execute(),
equalTo("Success"));
}
- @Test
+ @Test(expected = HystrixRuntimeException.class)
public void givenSvcTimeoutOf10000AndDefaultSettings__whenExecuted_thenExpectHRE() throws InterruptedException {
- exception.expect(HystrixRuntimeException.class);
+ HystrixCommand.Setter config = HystrixCommand
+ .Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroupTest3"));
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(10_000)).execute();
}
@Test
public void givenSvcTimeoutOf5000AndExecTimeoutOf10000__whenExecuted_thenReturnSuccess()
throws InterruptedException {
+
+ HystrixCommand.Setter config = HystrixCommand
+ .Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroupTest4"));
+ HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties.Setter();
commandProperties.withExecutionTimeoutInMilliseconds(10_000);
config.andCommandPropertiesDefaults(commandProperties);
@@ -63,10 +53,13 @@ public class HystrixTimeoutTest {
equalTo("Success"));
}
- @Test
+ @Test(expected = HystrixRuntimeException.class)
public void givenSvcTimeoutOf15000AndExecTimeoutOf5000__whenExecuted_thenExpectHRE()
throws InterruptedException {
- exception.expect(HystrixRuntimeException.class);
+ HystrixCommand.Setter config = HystrixCommand
+ .Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroupTest5"));
+ HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties.Setter();
commandProperties.withExecutionTimeoutInMilliseconds(5_000);
config.andCommandPropertiesDefaults(commandProperties);
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(15_000)).execute();
@@ -75,6 +68,11 @@ public class HystrixTimeoutTest {
@Test
public void givenSvcTimeoutOf500AndExecTimeoutOf10000AndThreadPool__whenExecuted_thenReturnSuccess()
throws InterruptedException {
+
+ HystrixCommand.Setter config = HystrixCommand
+ .Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroupThreadPool"));
+ HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties.Setter();
commandProperties.withExecutionTimeoutInMilliseconds(10_000);
config.andCommandPropertiesDefaults(commandProperties);
config.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter()
@@ -90,6 +88,10 @@ public class HystrixTimeoutTest {
public void givenCircuitBreakerSetup__whenRemoteSvcCmdExecuted_thenReturnSuccess()
throws InterruptedException {
+ HystrixCommand.Setter config = HystrixCommand
+ .Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroupCircuitBreakerTest"));
+ HystrixCommandProperties.Setter commandProperties = HystrixCommandProperties.Setter();
commandProperties.withExecutionTimeoutInMilliseconds(1000);
commandProperties.withCircuitBreakerSleepWindowInMilliseconds(4000);
@@ -105,8 +107,9 @@ public class HystrixTimeoutTest {
.withCoreSize(1)
.withQueueSizeRejectionThreshold(1));
- assertThat(this.invokeRemoteService(10000), equalTo(null));
- assertThat(this.invokeRemoteService(10000), equalTo(null));
+ assertThat(this.invokeRemoteService(config, 10_000), equalTo(null));
+ assertThat(this.invokeRemoteService(config, 10_000), equalTo(null));
+ assertThat(this.invokeRemoteService(config, 10_000), equalTo(null));
Thread.sleep(5000);
assertThat(new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(500)).execute(),
@@ -117,7 +120,7 @@ public class HystrixTimeoutTest {
equalTo("Success"));
}
- public String invokeRemoteService(long timeout) throws InterruptedException {
+ public String invokeRemoteService(HystrixCommand.Setter config, int timeout) throws InterruptedException {
String response = null;
try {
response = new RemoteServiceTestCommand(config,