Add simplest hello world examples

This commit is contained in:
Alex Theedom 2016-07-25 20:30:05 +01:00
parent 8881fdcaf4
commit 5a172a792a
2 changed files with 27 additions and 4 deletions

View File

@ -0,0 +1,19 @@
package com.baeldung.hystrix;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
class CommandHelloWorld extends HystrixCommand<String> {
private final String name;
CommandHelloWorld(String name) {
super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
this.name = name;
}
@Override
protected String run() {
return "Hello " + name + "!";
}
}

View File

@ -1,6 +1,7 @@
package com.baeldung.hystrix;
import com.netflix.hystrix.*;
import com.netflix.hystrix.collapser.RequestCollapserFactory;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import org.junit.After;
import org.junit.Before;
@ -23,8 +24,13 @@ public class HystrixTimeoutTest {
@Before
public void setup() {
config = HystrixCommand
.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
}
@Test
public void givenInputBob_andDefaultSettings_thenReturnHelloBob(){
assertThat(new CommandHelloWorld("Bob").execute(), equalTo("Hello Bob!"));
}
@Test
@ -36,7 +42,6 @@ public class HystrixTimeoutTest {
public void givenTimeoutEqualTo10000_andDefaultSettings_thenExpectHystrixRuntimeException() throws InterruptedException {
exception.expect(HystrixRuntimeException.class);
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(10_000)).execute();
}
@Test
@ -54,5 +59,4 @@ public class HystrixTimeoutTest {
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(15_000)).execute();
}
}