added spring-boot-starter-actuator so /hystrix.stream works and added test
fixes gh-2
This commit is contained in:
@@ -28,6 +28,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix</artifactId>
|
||||
|
||||
@@ -2,6 +2,7 @@ package demo;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -15,6 +16,9 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = HystrixApplication.class)
|
||||
@IntegrationTest("server.port=0")
|
||||
@@ -40,4 +44,20 @@ public class HystrixApplicationTests {
|
||||
assertEquals("Bad status code", HttpStatus.OK, response.getStatusCode());
|
||||
assertEquals("Wrong response text", "from the fallback", response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hystrixStreamWorks() throws Exception {
|
||||
String url = "http://localhost:" + port;
|
||||
//you have to hit a Hystrix circuit breaker before the stream sends anything
|
||||
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url, String.class);
|
||||
assertEquals("bad response code", HttpStatus.OK, response.getStatusCode());
|
||||
|
||||
URL hystrixUrl = new URL(url + "/hystrix.stream");
|
||||
InputStream in = hystrixUrl.openStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
in.read(buffer);
|
||||
String contents = new String(buffer);
|
||||
assertTrue(contents.contains("ping"));
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user