Search in sources :

Example 6 with OK

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

the class StandardHttpPipelineTest method sendsExceptionUponExtraSubscriptionInsideInterceptor.

@ParameterizedTest
@MethodSource("multipleSubscriptionInterceptors")
public void sendsExceptionUponExtraSubscriptionInsideInterceptor(HttpInterceptor interceptor) throws Exception {
    HttpHandler handler = (request, context) -> Eventual.of(response(OK).build());
    List<HttpInterceptor> interceptors = singletonList(interceptor);
    StandardHttpPipeline pipeline = new StandardHttpPipeline(interceptors, handler, RequestTracker.NO_OP);
    Eventual<LiveHttpResponse> responseObservable = pipeline.handle(get("/").build(), requestContext());
    assertThrows(IllegalStateException.class, () -> Mono.from(responseObservable).block());
}
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) HttpHandler(com.hotels.styx.api.HttpHandler) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with OK

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

the class StandardHttpPipelineTest method sendsExceptionUponMultipleSubscription.

@Test
public void sendsExceptionUponMultipleSubscription() {
    HttpHandler handler = (request, context) -> Eventual.of(response(OK).build());
    StandardHttpPipeline pipeline = new StandardHttpPipeline(handler);
    Eventual<LiveHttpResponse> responseObservable = pipeline.handle(get("/").build(), requestContext());
    LiveHttpResponse response = Mono.from(responseObservable).block();
    assertThat(response.status(), is(OK));
    assertThrows(IllegalStateException.class, () -> Mono.from(responseObservable).block());
}
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) HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with OK

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

the class InstrumentedPluginTest method metricIsRecordedWhenResponseIsMappedToErrorStatus.

@Test
public void metricIsRecordedWhenResponseIsMappedToErrorStatus() {
    Chain chain = request -> aResponse(OK);
    String pluginName = "replaceStatus1";
    InstrumentedPlugin plugin = instrumentedPlugin(pluginName, (request, aChain) -> aChain.proceed(request).map(response -> responseWithNewStatusCode(response, INTERNAL_SERVER_ERROR)));
    LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
    assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
    assertThat(getStatusCount(pluginName, "500"), is(1.0));
    assertThat(getErrorCount(pluginName), is(1.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 9 with OK

use of com.hotels.styx.api.HttpResponseStatus.OK 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)

Example 10 with OK

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

the class StyxServerTest method addsEndpointLinksToPluginPage.

@Test
public void addsEndpointLinksToPluginPage() {
    setUpStyxAndPluginWithAdminPages(Map.of("adminPage1", (request, ctx) -> Eventual.of(LiveHttpResponse.response().build()), "adminPage2", (request, ctx) -> Eventual.of(LiveHttpResponse.response().build())));
    HttpResponse response = doAdminRequest("/admin/plugins/plugin-with-admin-pages");
    assertThat(response.status(), is(OK));
    assertThat(response.bodyAs(UTF_8), allOf(containsString("/admin/plugins/plugin-with-admin-pages/adminPage1"), containsString("/admin/plugins/plugin-with-admin-pages/adminPage2")));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) Matchers.not(org.hamcrest.Matchers.not) StyxHttpClient(com.hotels.styx.client.StyxHttpClient) HttpClient(com.hotels.styx.client.HttpClient) WireMock(com.github.tomakehurst.wiremock.client.WireMock) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) HttpRequest.get(com.hotels.styx.api.HttpRequest.get) Map(java.util.Map) Origins.origin(com.hotels.styx.testapi.Origins.origin) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) WireMock.configureFor(com.github.tomakehurst.wiremock.client.WireMock.configureFor) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) Collections.emptyMap(java.util.Collections.emptyMap) Eventual(com.hotels.styx.api.Eventual) HttpHandler(com.hotels.styx.api.HttpHandler) Plugin(com.hotels.styx.api.plugins.spi.Plugin) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Matchers.allOf(org.hamcrest.Matchers.allOf) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) Mockito.verify(org.mockito.Mockito.verify) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) IsOptional.isValue(com.hotels.styx.support.matchers.IsOptional.isValue) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) OK(com.hotels.styx.api.HttpResponseStatus.OK) Optional(java.util.Optional) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) HttpResponse(com.hotels.styx.api.HttpResponse) 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