use of org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE in project feign-reactive by kptfh.
the class HystrixReactiveHttpClientTest method shouldOpenCircuitBreaker.
@Test
public void shouldOpenCircuitBreaker() throws IOException, InterruptedException {
String body = "success!";
int callsNo = 10;
LoadBalancingReactiveHttpClientTest.mockSuccessAfterSeveralAttempts(server, "/", callsNo, SC_SERVICE_UNAVAILABLE, aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(body));
LoadBalancingReactiveHttpClientTest.TestInterface client = CloudReactiveFeign.<LoadBalancingReactiveHttpClientTest.TestInterface>builder().webClient(WebClient.create()).setHystrixCommandSetterFactory(getSetterFactory(testNo)).target(LoadBalancingReactiveHttpClientTest.TestInterface.class, "http://localhost:" + server.port());
List<Object> results = IntStream.range(0, callsNo).mapToObj(i -> {
try {
return client.get().block();
} catch (Throwable t) {
return t;
}
}).collect(Collectors.toList());
assertThat(server.getAllServeEvents().size()).isLessThan(callsNo);
Throwable firstError = (Throwable) results.get(0);
assertThat(firstError).isInstanceOf(HystrixRuntimeException.class);
assertThat(firstError.getMessage()).contains("failed and no fallback available");
Throwable lastError = (Throwable) results.get(results.size() - 1);
assertThat(lastError).isInstanceOf(HystrixRuntimeException.class);
assertThat(lastError.getMessage()).contains("short-circuited and no fallback available.");
}
Aggregations