Add simplest hello world examples
This commit is contained in:
parent
8881fdcaf4
commit
5a172a792a
@ -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 + "!";
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.baeldung.hystrix;
|
package com.baeldung.hystrix;
|
||||||
|
|
||||||
import com.netflix.hystrix.*;
|
import com.netflix.hystrix.*;
|
||||||
|
import com.netflix.hystrix.collapser.RequestCollapserFactory;
|
||||||
import com.netflix.hystrix.exception.HystrixRuntimeException;
|
import com.netflix.hystrix.exception.HystrixRuntimeException;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -27,6 +28,11 @@ public class HystrixTimeoutTest {
|
|||||||
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
|
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceGroup1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInputBob_andDefaultSettings_thenReturnHelloBob(){
|
||||||
|
assertThat(new CommandHelloWorld("Bob").execute(), equalTo("Hello Bob!"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTimeoutEqualTo100_andDefaultSettings_thenReturnSuccess() throws InterruptedException {
|
public void givenTimeoutEqualTo100_andDefaultSettings_thenReturnSuccess() throws InterruptedException {
|
||||||
assertThat(new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(100)).execute(), equalTo("Success"));
|
assertThat(new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(100)).execute(), equalTo("Success"));
|
||||||
@ -36,7 +42,6 @@ public class HystrixTimeoutTest {
|
|||||||
public void givenTimeoutEqualTo10000_andDefaultSettings_thenExpectHystrixRuntimeException() throws InterruptedException {
|
public void givenTimeoutEqualTo10000_andDefaultSettings_thenExpectHystrixRuntimeException() throws InterruptedException {
|
||||||
exception.expect(HystrixRuntimeException.class);
|
exception.expect(HystrixRuntimeException.class);
|
||||||
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(10_000)).execute();
|
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(10_000)).execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -54,5 +59,4 @@ public class HystrixTimeoutTest {
|
|||||||
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(15_000)).execute();
|
new RemoteServiceTestCommand(config, new RemoteServiceTestSimulator(15_000)).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user