Skip to content

Commit 5a172a7

Browse files
committed
Add simplest hello world examples
1 parent 8881fdc commit 5a172a7

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.hystrix;
2+
3+
import com.netflix.hystrix.HystrixCommand;
4+
import com.netflix.hystrix.HystrixCommandGroupKey;
5+
6+
class CommandHelloWorld extends HystrixCommand<String> {
7+
8+
private final String name;
9+
10+
CommandHelloWorld(String name) {
11+
super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
12+
this.name = name;
13+
}
14+
15+
@Override
16+
protected String run() {
17+
return "Hello " + name + "!";
18+
}
19+
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.hystrix;
22

33
import com.netflix.hystrix.*;
4+
import com.netflix.hystrix.collapser.RequestCollapserFactory;
45
import com.netflix.hystrix.exception.HystrixRuntimeException;
56
import org.junit.After;
67
import org.junit.Before;
@@ -23,8 +24,13 @@ public class HystrixTimeoutTest {
2324
@Before
2425
public void setup() {
2526
config = HystrixCommand
26-
.Setter
27-
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
27+
.Setter
28+
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
29+
}
30+
31+
@Test
32+
public void givenInputBob_andDefaultSettings_thenReturnHelloBob(){
33+
assertThat(new CommandHelloWorld("Bob").execute(), equalTo("Hello Bob!"));
2834
}
2935

3036
@Test
@@ -36,7 +42,6 @@ public void givenTimeoutEqualTo100_andDefaultSettings_thenReturnSuccess() throws
3642
public void givenTimeoutEqualTo10000_andDefaultSettings_thenExpectHystrixRuntimeException() throws InterruptedException {
3743
exception.expect(HystrixRuntimeException.class);
3844
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(10_000)).execute();
39-
4045
}
4146

4247
@Test
@@ -54,5 +59,4 @@ public void givenTimeoutEqualTo15000_andExecutionTimeoutEqualTo10000_thenExpectH
5459
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(15_000)).execute();
5560
}
5661

57-
5862
}

0 commit comments

Comments
 (0)