From 5a172a792a4134e21145fca5c0ce4d5814ac41ed Mon Sep 17 00:00:00 2001 From: Alex Theedom Date: Mon, 25 Jul 2016 20:30:05 +0100 Subject: [PATCH] Add simplest hello world examples --- .../baeldung/hystrix/CommandHelloWorld.java | 19 +++++++++++++++++++ .../baeldung/hystrix/HystrixTimeoutTest.java | 12 ++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 hystrix/src/test/java/com/baeldung/hystrix/CommandHelloWorld.java diff --git a/hystrix/src/test/java/com/baeldung/hystrix/CommandHelloWorld.java b/hystrix/src/test/java/com/baeldung/hystrix/CommandHelloWorld.java new file mode 100644 index 0000000000..4f2b0c38c3 --- /dev/null +++ b/hystrix/src/test/java/com/baeldung/hystrix/CommandHelloWorld.java @@ -0,0 +1,19 @@ +package com.baeldung.hystrix; + +import com.netflix.hystrix.HystrixCommand; +import com.netflix.hystrix.HystrixCommandGroupKey; + +class CommandHelloWorld extends HystrixCommand { + + private final String name; + + CommandHelloWorld(String name) { + super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")); + this.name = name; + } + + @Override + protected String run() { + return "Hello " + name + "!"; + } +} diff --git a/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java b/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java index a49cc31a02..773c76536f 100644 --- a/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java +++ b/hystrix/src/test/java/com/baeldung/hystrix/HystrixTimeoutTest.java @@ -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(); } - }