Search in sources :

Example 61 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class HopByHopHeadersRemovingInterceptorTest method removesAllFieldsWhenMultipleInstancesArePresent.

@Test
public void removesAllFieldsWhenMultipleInstancesArePresent() {
    LiveHttpRequest request = delete("/foo").header(PROXY_AUTHENTICATE, "foo").header(PROXY_AUTHENTICATE, "bar").header(PROXY_AUTHENTICATE, "baz").build();
    LiveHttpRequest interceptedRequest = interceptRequest(request);
    assertThat(interceptedRequest.header(PROXY_AUTHENTICATE), isAbsent());
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 62 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class BackendServicesRouterTest method selectsUsingSingleSlashPath.

@Test
public void selectsUsingSingleSlashPath() throws Exception {
    Registry.Changes<BackendService> changes = added(appA().newCopy().path("/").build(), appB().newCopy().path("/appB/hotel/details.html").build());
    BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
    router.onChange(changes);
    LiveHttpRequest request = get("/").build();
    Optional<HttpHandler> route = router.route(request, context);
    assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_A));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Registry(com.hotels.styx.api.extension.service.spi.Registry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 63 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class HttpErrorStatusCauseLoggerTest method logsOtherExceptionsWithoutRequest.

@Test
public void logsOtherExceptionsWithoutRequest() {
    LiveHttpRequest request = LiveHttpRequest.get("/foo").build();
    Exception exception = new Exception("This is just a test");
    httpErrorStatusCauseLogger.proxyErrorOccurred(request, InetSocketAddress.createUnresolved("127.0.0.1", 0), BAD_GATEWAY, exception);
    assertThat(loggingTestSupport.log(), hasItem(loggingEvent(ERROR, "Failure status=\"502 Bad Gateway\", exception=\"java.lang.Exception.*This is just a test.*\"")));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 64 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class HttpErrorStatusMetricsTest method updatesCountersForProxyErrorsWithResponse.

@Test
public void updatesCountersForProxyErrorsWithResponse() {
    LiveHttpRequest request = get("/foo").build();
    errorListener.proxyErrorOccurred(request, InetSocketAddress.createUnresolved("127.0.0.1", 0), INTERNAL_SERVER_ERROR, new CustomException());
    assertThat(count(ERROR), is(1));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class StyxServerTest method serverDoesNotStartUntilPluginsAreStarted.

@Test
public void serverDoesNotStartUntilPluginsAreStarted() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    StyxServer styxServer = styxServerWithPlugins(Map.of("slowlyStartingPlugin", new Plugin() {

        @Override
        public void styxStarting() {
            try {
                latch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        @Override
        public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request1, Chain chain) {
            return Eventual.of(response(OK).build());
        }
    }));
    try {
        styxServer.startAsync();
        Thread.sleep(10);
        assertThat(styxServer.proxyHttpAddress(), nullValue());
        latch.countDown();
        eventually(() -> assertThat(styxServer.proxyHttpAddress().getPort(), is(greaterThan(0))));
    } finally {
        stopIfRunning(styxServer);
    }
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) CountDownLatch(java.util.concurrent.CountDownLatch) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) NamedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin) Plugin(com.hotels.styx.api.plugins.spi.Plugin) Test(org.junit.jupiter.api.Test)

Aggregations

LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)82 Test (org.junit.jupiter.api.Test)76 Condition (com.hotels.styx.server.routing.Condition)19 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)14 HttpHandler (com.hotels.styx.api.HttpHandler)10 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)9 MeterRegistry (com.hotels.styx.api.MeterRegistry)8 BackendService (com.hotels.styx.api.extension.service.BackendService)7 Registry (com.hotels.styx.api.extension.service.spi.Registry)7 Eventual (com.hotels.styx.api.Eventual)6 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)6 HttpResponse (com.hotels.styx.api.HttpResponse)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Mono (reactor.core.publisher.Mono)5 HttpRequestMessageLogger (com.hotels.styx.common.logging.HttpRequestMessageLogger)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4