Search in sources :

Example 1 with UNHEALTHY

use of com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY 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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginState(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState) Predicate(java.util.function.Predicate) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) NOT_FOUND(com.hotels.styx.api.HttpResponseStatus.NOT_FOUND) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Meter(io.micrometer.core.instrument.Meter) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClient(com.hotels.styx.client.HttpClient) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Collectors(java.util.stream.Collectors) UNHEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY) Test(org.junit.jupiter.api.Test) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Origin(com.hotels.styx.api.extension.Origin) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Matchers.is(org.hamcrest.Matchers.is) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY) HttpClient(com.hotels.styx.client.HttpClient) Test(org.junit.jupiter.api.Test)

Example 2 with UNHEALTHY

use of com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY 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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) OriginState(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState) Predicate(java.util.function.Predicate) HttpResponse.response(com.hotels.styx.api.HttpResponse.response) NOT_FOUND(com.hotels.styx.api.HttpResponseStatus.NOT_FOUND) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) Meter(io.micrometer.core.instrument.Meter) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClient(com.hotels.styx.client.HttpClient) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Collectors(java.util.stream.Collectors) UNHEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY) Test(org.junit.jupiter.api.Test) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Origin(com.hotels.styx.api.extension.Origin) OK(com.hotels.styx.api.HttpResponseStatus.OK) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) Matchers.is(org.hamcrest.Matchers.is) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HEALTHY(com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY) HttpClient(com.hotels.styx.client.HttpClient) Test(org.junit.jupiter.api.Test)

Aggregations

HttpResponse (com.hotels.styx.api.HttpResponse)2 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)2 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)2 NOT_FOUND (com.hotels.styx.api.HttpResponseStatus.NOT_FOUND)2 OK (com.hotels.styx.api.HttpResponseStatus.OK)2 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)2 Origin (com.hotels.styx.api.extension.Origin)2 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)2 HttpClient (com.hotels.styx.client.HttpClient)2 OriginState (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState)2 HEALTHY (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY)2 UNHEALTHY (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY)2 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)2 Meter (io.micrometer.core.instrument.Meter)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2