use of feign.Target in project feign-reactive by kptfh.
the class HystrixReactiveHttpClientTest method getSetterFactory.
static CloudReactiveFeign.SetterFactory getSetterFactory(int testNo) {
return new CloudReactiveFeign.SetterFactory() {
@Override
public HystrixObservableCommand.Setter create(Target<?> target, MethodMetadata methodMetadata) {
String groupKey = target.name();
String commandKey = methodMetadata.configKey();
return HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)).andCommandKey(HystrixCommandKey.Factory.asKey(commandKey + testNo)).andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(1));
}
};
}
use of feign.Target in project feign by OpenFeign.
the class Http2ClientAsyncTest method decodingExceptionGetWrappedInDecode404Mode.
@Test
public void decodingExceptionGetWrappedInDecode404Mode() throws Throwable {
server.enqueue(new MockResponse().setResponseCode(404));
thrown.expect(DecodeException.class);
thrown.expectCause(isA(NoSuchElementException.class));
final TestInterfaceAsync api = newAsyncBuilder().decode404().decoder((response, type) -> {
assertEquals(404, response.status());
throw new NoSuchElementException();
}).target("http://localhost:" + server.getPort());
unwrap(api.post());
}
use of feign.Target in project feign by OpenFeign.
the class Http2ClientAsyncTest method throwsFeignExceptionWithoutBody.
@Test
public void throwsFeignExceptionWithoutBody() {
server.enqueue(new MockResponse().setBody("success!"));
final TestInterfaceAsync api = newAsyncBuilder().decoder((response, type) -> {
throw new IOException("timeout");
}).target("http://localhost:" + server.getPort());
try {
api.noContent();
} catch (final FeignException e) {
Assertions.assertThat(e.getMessage()).isEqualTo("timeout reading POST http://localhost:" + server.getPort() + "/");
Assertions.assertThat(e.contentUTF8()).isEqualTo("");
}
}
use of feign.Target in project feign-reactive by kptfh.
the class HystrixReactiveHttpClientTest method getSetterFactory.
CloudReactiveFeign.SetterFactory getSetterFactory(int testNo) {
return new CloudReactiveFeign.SetterFactory() {
@Override
public HystrixObservableCommand.Setter create(Target<?> target, MethodMetadata methodMetadata) {
String groupKey = target.name();
HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(methodMetadata.configKey() + testNo);
lastCommandKey.set(commandKey);
return HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)).andCommandKey(commandKey).andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(VOLUME_THRESHOLD).withExecutionTimeoutEnabled(false).withCircuitBreakerSleepWindowInMilliseconds(SLEEP_WINDOW).withMetricsHealthSnapshotIntervalInMilliseconds(10));
}
};
}
use of feign.Target 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.");
}
Aggregations