Search in sources :

Example 1 with RETRY_AFTER

use of org.apache.http.HttpHeaders.RETRY_AFTER in project feign-reactive by kptfh.

the class RetryingTest method shouldFailAsNoMoreRetries.

@Test
public void shouldFailAsNoMoreRetries() {
    String orderUrl = "/icecream/orders/1";
    wireMockRule.stubFor(get(urlEqualTo(orderUrl)).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(503).withHeader(RETRY_AFTER, "1")));
    IcecreamServiceApi client = builder().retryWhen(ReactiveRetryers.retry(3)).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findOrder(1)).expectErrorMatches(throwable -> throwable instanceof RetryPublisherHttpClient.OutOfRetriesException && hasProperty("cause", isA(RetryableException.class)).matches(throwable)).verify();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Matchers.isA(org.hamcrest.Matchers.isA) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) RETRY_AFTER(org.apache.http.HttpHeaders.RETRY_AFTER) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMock(com.github.tomakehurst.wiremock.client.WireMock) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) RetryableException(feign.RetryableException) SC_OK(org.apache.http.HttpStatus.SC_OK) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) TestUtils.equalsComparingFieldByFieldRecursively(reactivefeign.TestUtils.equalsComparingFieldByFieldRecursively) SC_SERVICE_UNAVAILABLE(org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE) Mixin(reactivefeign.testcase.domain.Mixin) ClassRule(org.junit.ClassRule) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Before(org.junit.Before) RetryableException(feign.RetryableException) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Test(org.junit.Test)

Example 2 with RETRY_AFTER

use of org.apache.http.HttpHeaders.RETRY_AFTER in project feign-reactive by kptfh.

the class RetryingTest method shouldFailAsNoMoreRetriesWithBackoff.

@Test
public void shouldFailAsNoMoreRetriesWithBackoff() {
    String orderUrl = "/icecream/orders/1";
    wireMockRule.stubFor(get(urlEqualTo(orderUrl)).withHeader("Accept", equalTo("application/json")).willReturn(aResponse().withStatus(503).withHeader(RETRY_AFTER, "1")));
    IcecreamServiceApi client = builder().retryWhen(ReactiveRetryers.retryWithBackoff(7, 5)).target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
    StepVerifier.create(client.findOrder(1)).expectErrorMatches(throwable -> throwable instanceof RetryPublisherHttpClient.OutOfRetriesException && hasProperty("cause", isA(RetryableException.class)).matches(throwable)).verify();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Matchers.isA(org.hamcrest.Matchers.isA) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) OrderGenerator(reactivefeign.testcase.domain.OrderGenerator) RETRY_AFTER(org.apache.http.HttpHeaders.RETRY_AFTER) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) IceCreamOrder(reactivefeign.testcase.domain.IceCreamOrder) WireMock(com.github.tomakehurst.wiremock.client.WireMock) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) RetryableException(feign.RetryableException) SC_OK(org.apache.http.HttpStatus.SC_OK) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) TestUtils.equalsComparingFieldByFieldRecursively(reactivefeign.TestUtils.equalsComparingFieldByFieldRecursively) SC_SERVICE_UNAVAILABLE(org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE) Mixin(reactivefeign.testcase.domain.Mixin) ClassRule(org.junit.ClassRule) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Before(org.junit.Before) RetryableException(feign.RetryableException) IcecreamServiceApi(reactivefeign.testcase.IcecreamServiceApi) RetryPublisherHttpClient(reactivefeign.publisher.RetryPublisherHttpClient) Test(org.junit.Test)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 WireMockConfiguration.wireMockConfig (com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig)2 WireMockClassRule (com.github.tomakehurst.wiremock.junit.WireMockClassRule)2 STARTED (com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED)2 RetryableException (feign.RetryableException)2 Arrays (java.util.Arrays)2 RETRY_AFTER (org.apache.http.HttpHeaders.RETRY_AFTER)2 SC_OK (org.apache.http.HttpStatus.SC_OK)2 SC_SERVICE_UNAVAILABLE (org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE)2 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)2 Matchers.isA (org.hamcrest.Matchers.isA)2 Before (org.junit.Before)2 ClassRule (org.junit.ClassRule)2 Test (org.junit.Test)2 TestUtils.equalsComparingFieldByFieldRecursively (reactivefeign.TestUtils.equalsComparingFieldByFieldRecursively)2 RetryPublisherHttpClient (reactivefeign.publisher.RetryPublisherHttpClient)2 IcecreamServiceApi (reactivefeign.testcase.IcecreamServiceApi)2 IceCreamOrder (reactivefeign.testcase.domain.IceCreamOrder)2