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());
}
Aggregations