Search in sources :

Example 1 with SC_SERVICE_UNAVAILABLE

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.");
}
Also used : IntStream(java.util.stream.IntStream) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) Target(feign.Target) HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) HystrixRuntimeException(com.netflix.hystrix.exception.HystrixRuntimeException) MethodMetadata(feign.MethodMetadata) Collectors(java.util.stream.Collectors) List(java.util.List) Rule(org.junit.Rule) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) HystrixObservableCommand(com.netflix.hystrix.HystrixObservableCommand) SC_SERVICE_UNAVAILABLE(org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE) ClassRule(org.junit.ClassRule) ExpectedException(org.junit.rules.ExpectedException) Matchers.containsString(org.hamcrest.Matchers.containsString) Before(org.junit.Before) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMockConfiguration.wireMockConfig (com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig)1 WireMockClassRule (com.github.tomakehurst.wiremock.junit.WireMockClassRule)1 HystrixCommandGroupKey (com.netflix.hystrix.HystrixCommandGroupKey)1 HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)1 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)1 HystrixObservableCommand (com.netflix.hystrix.HystrixObservableCommand)1 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)1 MethodMetadata (feign.MethodMetadata)1 Target (feign.Target)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 SC_SERVICE_UNAVAILABLE (org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Before (org.junit.Before)1 ClassRule (org.junit.ClassRule)1 Rule (org.junit.Rule)1