use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.
the class MetricsSnapshot method downloadFrom.
public static MetricsSnapshot downloadFrom(String host, int port) throws IOException {
HttpClient client = new StyxHttpClient.Builder().build();
HttpResponse response = await(client.sendRequest(get(format("http://%s:%d/admin/metrics", host, port)).build()));
return new MetricsSnapshot(decodeToMap(response.bodyAs(UTF_8)));
}
use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.
the class UrlRequestHealthCheckTest method declaredOriginUnhealthyOnTransportException.
@Test
public void declaredOriginUnhealthyOnTransportException() {
HttpClient client = request -> respondWith(new RuntimeException("health check failure, as expected"));
new UrlRequestHealthCheck("/version.txt", metrics).check(client, someOrigin, state -> this.originState = state);
assertThat(originState, is(UNHEALTHY));
assertThat(metrics.getRegistry().find("proxy.client.originHealthCheckFailures").tags("originId", someOrigin.id().toString(), "appId", someOrigin.applicationId().toString()).counter().count(), is(1.0));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(1));
}
use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.
the class UrlRequestHealthCheckTest method declaresOriginUnhealthyOnNon200Ok.
@Test
public void declaresOriginUnhealthyOnNon200Ok() {
HttpClient client = request -> respondWith(NOT_FOUND);
new UrlRequestHealthCheck("/version.txt", metrics).check(client, someOrigin, state -> this.originState = state);
assertThat(originState, is(UNHEALTHY));
assertThat(metrics.getRegistry().find("proxy.client.originHealthCheckFailures").tags("originId", someOrigin.id().toString(), "appId", someOrigin.applicationId().toString()).counter().count(), is(1.0));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(1));
}
use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.
the class UrlRequestHealthCheckTest method sendsTheHealthCheckRequestToTheGivenUrl.
@Test
public void sendsTheHealthCheckRequestToTheGivenUrl() {
HttpClient client = request -> {
requestedUrl = request.url().path();
return respondWith(NOT_FOUND);
};
new UrlRequestHealthCheck("/version-foo.txt", metrics).check(client, someOrigin, state -> {
});
assertThat(requestedUrl, is("/version-foo.txt"));
}
use of com.hotels.styx.client.HttpClient in project styx by ExpediaGroup.
the class UrlRequestHealthCheckTest method declaresOriginHealthyOnOkResponseCode.
@Test
public void declaresOriginHealthyOnOkResponseCode() {
HttpClient client = request -> respondWith(OK);
new UrlRequestHealthCheck("/version.txt", metrics).check(client, someOrigin, state -> this.originState = state);
assertThat(originState, is(HEALTHY));
assertThat(meters(id -> id.getName().equals("proxy.client.originHealthCheckFailures")).size(), is(0));
}
Aggregations