Search in sources :

Example 1 with OriginState

use of com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState 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 OriginState

use of com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState 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)

Example 3 with OriginState

use of com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState 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));
}
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)3 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)3 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)3 NOT_FOUND (com.hotels.styx.api.HttpResponseStatus.NOT_FOUND)3 OK (com.hotels.styx.api.HttpResponseStatus.OK)3 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)3 Origin (com.hotels.styx.api.extension.Origin)3 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)3 HttpClient (com.hotels.styx.client.HttpClient)3 OriginState (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState)3 HEALTHY (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.HEALTHY)3 UNHEALTHY (com.hotels.styx.client.healthcheck.OriginHealthCheckFunction.OriginState.UNHEALTHY)3 CentralisedMetrics (com.hotels.styx.metrics.CentralisedMetrics)3 Meter (io.micrometer.core.instrument.Meter)3 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Predicate (java.util.function.Predicate)3 Collectors (java.util.stream.Collectors)3 Collectors.toList (java.util.stream.Collectors.toList)3