Search in sources :

Example 16 with OK

use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.

the class StandardHttpPipelineTest method interceptorReceivesNewContext.

@Test
public void interceptorReceivesNewContext() {
    HttpInterceptor expectNewContext = (request, chain) -> {
        Object seen = chain.context().get("seen", Object.class);
        assertThat("Old context reused" + seen, seen, is(nullValue()));
        chain.context().add("seen", true);
        return chain.proceed(request);
    };
    StandardHttpPipeline pipeline = pipeline(expectNewContext);
    assertThat(sendRequestTo(pipeline).status(), is(OK));
    // make the same request again to ensure a new context is used
    assertThat(sendRequestTo(pipeline).status(), is(OK));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RequestTracker(com.hotels.styx.server.track.RequestTracker) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HttpInterceptorContext(com.hotels.styx.server.HttpInterceptorContext) Support.requestContext(com.hotels.styx.support.Support.requestContext) Arrays.asList(java.util.Arrays.asList) Matchers.nullValue(org.hamcrest.Matchers.nullValue) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MethodSource(org.junit.jupiter.params.provider.MethodSource) Eventual(com.hotels.styx.api.Eventual) HttpHandler(com.hotels.styx.api.HttpHandler) Mono(reactor.core.publisher.Mono) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Matchers.contains(org.hamcrest.Matchers.contains) OK(com.hotels.styx.api.HttpResponseStatus.OK) Matchers.is(org.hamcrest.Matchers.is) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with OK

use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.

the class InstrumentedPluginTest method errorsMetricIsNotRecordedWhenResponseIsMappedToNon5005xxStatus.

@Test
public void errorsMetricIsNotRecordedWhenResponseIsMappedToNon5005xxStatus() {
    Chain chain = request -> aResponse(OK);
    String pluginName = "replaceStatusCodeY";
    InstrumentedPlugin plugin = instrumentedPlugin("replaceStatusCodeY", (request, aChain) -> aChain.proceed(request).map(response -> responseWithNewStatusCode(response, BAD_GATEWAY)));
    LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
    assertThat(response.status(), is(BAD_GATEWAY));
    assertThat(getStatusCount(pluginName, "502"), is(1.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)

Aggregations

OK (com.hotels.styx.api.HttpResponseStatus.OK)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)17 Test (org.junit.jupiter.api.Test)17 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)16 Eventual (com.hotels.styx.api.Eventual)15 Matchers.is (org.hamcrest.Matchers.is)15 Mono (reactor.core.publisher.Mono)12 HttpHandler (com.hotels.styx.api.HttpHandler)11 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)11 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)10 Support.requestContext (com.hotels.styx.support.Support.requestContext)9 List (java.util.List)9 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 InetSocketAddress (java.net.InetSocketAddress)7 ArrayList (java.util.ArrayList)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)7 HttpInterceptorContext (com.hotels.styx.server.HttpInterceptorContext)6 RequestTracker (com.hotels.styx.server.track.RequestTracker)6