Search in sources :

Example 1 with ErrorDecoder

use of feign.codec.ErrorDecoder in project feign by OpenFeign.

the class FeignTest method ensureRetryerClonesItself.

@Test
public void ensureRetryerClonesItself() {
    server.enqueue(new MockResponse().setResponseCode(503).setBody("foo 1"));
    server.enqueue(new MockResponse().setResponseCode(200).setBody("foo 2"));
    server.enqueue(new MockResponse().setResponseCode(503).setBody("foo 3"));
    server.enqueue(new MockResponse().setResponseCode(200).setBody("foo 4"));
    MockRetryer retryer = new MockRetryer();
    TestInterface api = Feign.builder().retryer(retryer).errorDecoder(new ErrorDecoder() {

        @Override
        public Exception decode(String methodKey, Response response) {
            return new RetryableException("play it again sam!", null);
        }
    }).target(TestInterface.class, "http://localhost:" + server.getPort());
    api.post();
    // if retryer instance was reused, this statement will throw an exception
    api.post();
    assertEquals(4, server.getRequestCount());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) ErrorDecoder(feign.codec.ErrorDecoder) Test(org.junit.Test)

Aggregations

ErrorDecoder (feign.codec.ErrorDecoder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.junit.Test)1