Search in sources :

Example 1 with PASS_THROUGH

use of com.hotels.styx.api.plugins.spi.Plugin.PASS_THROUGH in project styx by ExpediaGroup.

the class InstrumentedPluginTest method metricIsNotRecordedWhenErrorStatusIsReturnedByChain.

@Test
public void metricIsNotRecordedWhenErrorStatusIsReturnedByChain() {
    Chain chain = request -> aResponse(INTERNAL_SERVER_ERROR);
    String pluginName = "doNotRecordMe";
    InstrumentedPlugin plugin = instrumentedPlugin(pluginName, PASS_THROUGH);
    LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
    assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
    assertThat(getStatusCount(pluginName, "500"), is(0.0));
    assertThat(getErrorCount(pluginName), is(0.0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StepVerifier(reactor.test.StepVerifier) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) Eventual.error(com.hotels.styx.api.Eventual.error) Matchers.not(org.hamcrest.Matchers.not) PluginException(com.hotels.styx.api.plugins.spi.PluginException) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) PASS_THROUGH(com.hotels.styx.api.plugins.spi.Plugin.PASS_THROUGH) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Counter(io.micrometer.core.instrument.Counter) Eventual(com.hotels.styx.api.Eventual) INTERNAL_SERVER_ERROR(com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Plugin(com.hotels.styx.api.plugins.spi.Plugin) Mono(reactor.core.publisher.Mono) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Metrics.formattedExceptionName(com.hotels.styx.api.Metrics.formattedExceptionName) Chain(com.hotels.styx.api.HttpInterceptor.Chain) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) MeterRegistry(com.hotels.styx.api.MeterRegistry) Environment(com.hotels.styx.Environment) OK(com.hotels.styx.api.HttpResponseStatus.OK) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) BAD_GATEWAY(com.hotels.styx.api.HttpResponseStatus.BAD_GATEWAY) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Mockito.mock(org.mockito.Mockito.mock) Chain(com.hotels.styx.api.HttpInterceptor.Chain) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with PASS_THROUGH

use of com.hotels.styx.api.plugins.spi.Plugin.PASS_THROUGH in project styx by ExpediaGroup.

the class InstrumentedPluginTest method metricsAreNotRecordedWhenExceptionIsReturnedByChain.

@Test
public void metricsAreNotRecordedWhenExceptionIsReturnedByChain() {
    String pluginName = "passThrough";
    Chain chain = request -> error(new SomeException());
    InstrumentedPlugin plugin = instrumentedPlugin(pluginName, PASS_THROUGH);
    assertThatEventualHasErrorOnly(SomeException.class, plugin.intercept(someRequest, chain));
    assertThat(getExceptionCount(pluginName, SOME_EXCEPTION), is(0.0));
    assertThat(getErrorCount(pluginName), is(0.0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StepVerifier(reactor.test.StepVerifier) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) Eventual.error(com.hotels.styx.api.Eventual.error) Matchers.not(org.hamcrest.Matchers.not) PluginException(com.hotels.styx.api.plugins.spi.PluginException) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) PASS_THROUGH(com.hotels.styx.api.plugins.spi.Plugin.PASS_THROUGH) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Counter(io.micrometer.core.instrument.Counter) Eventual(com.hotels.styx.api.Eventual) INTERNAL_SERVER_ERROR(com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Plugin(com.hotels.styx.api.plugins.spi.Plugin) Mono(reactor.core.publisher.Mono) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Metrics.formattedExceptionName(com.hotels.styx.api.Metrics.formattedExceptionName) Chain(com.hotels.styx.api.HttpInterceptor.Chain) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) MeterRegistry(com.hotels.styx.api.MeterRegistry) Environment(com.hotels.styx.Environment) OK(com.hotels.styx.api.HttpResponseStatus.OK) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) BAD_GATEWAY(com.hotels.styx.api.HttpResponseStatus.BAD_GATEWAY) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Mockito.mock(org.mockito.Mockito.mock) Chain(com.hotels.styx.api.HttpInterceptor.Chain) Test(org.junit.jupiter.api.Test)

Aggregations

Environment (com.hotels.styx.Environment)2 Eventual (com.hotels.styx.api.Eventual)2 Eventual.error (com.hotels.styx.api.Eventual.error)2 Chain (com.hotels.styx.api.HttpInterceptor.Chain)2 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)2 BAD_GATEWAY (com.hotels.styx.api.HttpResponseStatus.BAD_GATEWAY)2 INTERNAL_SERVER_ERROR (com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR)2 OK (com.hotels.styx.api.HttpResponseStatus.OK)2 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)2 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)2 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)2 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)2 MeterRegistry (com.hotels.styx.api.MeterRegistry)2 Metrics.formattedExceptionName (com.hotels.styx.api.Metrics.formattedExceptionName)2 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)2 Plugin (com.hotels.styx.api.plugins.spi.Plugin)2 PASS_THROUGH (com.hotels.styx.api.plugins.spi.Plugin.PASS_THROUGH)2 PluginException (com.hotels.styx.api.plugins.spi.PluginException)2 NamedPlugin.namedPlugin (com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin)2 Counter (io.micrometer.core.instrument.Counter)2