use of feign.Request in project spring-cloud-sleuth by spring-cloud.
the class FeignRetriesTests method testRetriedWhenExceededNumberOfRetries.
@Test
public void testRetriedWhenExceededNumberOfRetries() throws Exception {
Client client = (request, options) -> {
throw new IOException();
};
String url = "http://localhost:" + server.getPort();
TestInterface api = Feign.builder().client(new TracingFeignClient(this.httpTracing, client)).target(TestInterface.class, url);
try {
api.decodedPost();
failBecauseExceptionWasNotThrown(FeignException.class);
} catch (FeignException e) {
}
}
use of feign.Request in project spring-cloud-sleuth by spring-cloud.
the class FeignRetriesTests method testRetriedWhenRequestEventuallyIsSent.
@Test
public void testRetriedWhenRequestEventuallyIsSent() throws Exception {
String url = "http://localhost:" + server.getPort();
final AtomicInteger atomicInteger = new AtomicInteger();
// Client to simulate a retry scenario
final Client client = (request, options) -> {
// we simulate an exception only for the first request
if (atomicInteger.get() == 1) {
throw new IOException();
} else {
// with the second retry (first retry) we send back good result
return Response.builder().status(200).reason("OK").headers(new HashMap<>()).body("OK", Charset.defaultCharset()).build();
}
};
TestInterface api = Feign.builder().client(new TracingFeignClient(this.httpTracing, new Client() {
@Override
public Response execute(Request request, Request.Options options) throws IOException {
atomicInteger.incrementAndGet();
return client.execute(request, options);
}
})).target(TestInterface.class, url);
then(api.decodedPost()).isEqualTo("OK");
// request interception should take place only twice (1st request & 2nd retry)
then(atomicInteger.get()).isEqualTo(2);
then(this.reporter.getSpans().get(0).tags()).containsEntry("error", "IOException");
then(this.reporter.getSpans().get(1).kind().ordinal()).isEqualTo(Span.Kind.CLIENT.ordinal());
}
use of feign.Request in project feign by OpenFeign.
the class ReactiveFeignIntegrationTest method testErrorDecoder.
@SuppressWarnings({ "ThrowableNotThrown" })
@Test
public void testErrorDecoder() {
this.webServer.enqueue(new MockResponse().setBody("Bad Request").setResponseCode(400));
ErrorDecoder errorDecoder = mock(ErrorDecoder.class);
given(errorDecoder.decode(anyString(), any(Response.class))).willReturn(new IllegalStateException("bad request"));
TestReactiveXService service = RxJavaFeign.builder().errorDecoder(errorDecoder).target(TestReactiveXService.class, this.getServerUrl());
StepVerifier.create(service.search(new SearchQuery())).expectErrorSatisfies(ex -> assertThat(ex).isInstanceOf(IllegalStateException.class).hasMessage("bad request")).verify();
verify(errorDecoder, times(1)).decode(anyString(), any(Response.class));
}
use of feign.Request in project feign by OpenFeign.
the class ReactiveFeignIntegrationTest method testClient.
@Test
public void testClient() throws Exception {
Client client = mock(Client.class);
given(client.execute(any(Request.class), any(Options.class))).willAnswer((Answer<Response>) invocation -> Response.builder().status(200).headers(Collections.emptyMap()).body("1.0", Charset.defaultCharset()).request((Request) invocation.getArguments()[0]).build());
TestReactorService service = ReactorFeign.builder().client(client).target(TestReactorService.class, this.getServerUrl());
StepVerifier.create(service.version()).expectNext("1.0").expectComplete().verify();
verify(client, times(1)).execute(any(Request.class), any(Options.class));
}
use of feign.Request in project feign by OpenFeign.
the class RequestKeyTest method create.
@SuppressWarnings("deprecation")
@Test
public void create() throws Exception {
Map<String, Collection<String>> map = new HashMap<String, Collection<String>>();
map.put("my-header", Arrays.asList("val"));
Request request = Request.create(Request.HttpMethod.GET, "a", map, "content".getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_16);
requestKey = RequestKey.create(request);
assertThat(requestKey.getMethod(), equalTo(HttpMethod.GET));
assertThat(requestKey.getUrl(), equalTo("a"));
assertThat(requestKey.getHeaders().size(), is(1));
assertThat(requestKey.getHeaders().fetch("my-header"), equalTo((Collection<String>) Arrays.asList("val")));
assertThat(requestKey.getCharset(), equalTo(StandardCharsets.UTF_16));
assertThat(requestKey.getBody(), equalTo("content".getBytes(StandardCharsets.UTF_8)));
}
Aggregations