Search in sources :

Example 71 with HttpResponse

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

the class StyxProxyTest method startsServerWithHttpConnector.

@Test
public void startsServerWithHttpConnector() {
    HttpInterceptor echoInterceptor = (request, chain) -> textResponse("Response from http connector");
    StandardHttpRouter handler = new StandardHttpRouter();
    InetServer styxServer = newBuilder().setProtocolConnector(connector(0)).bossExecutor(NettyExecutor.create("Test-Server-Boss", 1)).workerExecutor(NettyExecutor.create("Test-Server-Worker", 0)).handler(new HttpInterceptorPipeline(List.of(echoInterceptor), (request, context) -> new HttpAggregator(new StandardHttpRouter()).handle(request, context), false)).build();
    Service server = StyxServers.toGuavaService(styxServer);
    server.startAsync().awaitRunning();
    assertThat("Server should be running", server.isRunning());
    HttpResponse secureResponse = get("http://localhost:" + styxServer.inetAddress().getPort());
    assertThat(secureResponse.bodyAs(UTF_8), containsString("Response from http connector"));
    server.stopAsync().awaitTerminated();
    assertThat("Server should not be running", !server.isRunning());
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LoggerFactory(org.slf4j.LoggerFactory) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) StyxHttpClient(com.hotels.styx.client.StyxHttpClient) HttpClient(com.hotels.styx.client.HttpClient) Disabled(org.junit.jupiter.api.Disabled) HttpConnectorConfig(com.hotels.styx.server.HttpConnectorConfig) StyxServers(com.hotels.styx.StyxServers) WebServerConnectorFactory(com.hotels.styx.server.netty.WebServerConnectorFactory) NettyServerBuilder(com.hotels.styx.server.netty.NettyServerBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StandardHttpRouter(com.hotels.styx.server.StandardHttpRouter) Eventual(com.hotels.styx.api.Eventual) Logger(org.slf4j.Logger) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpAggregator(com.hotels.styx.common.http.handler.HttpAggregator) NettyServerBuilder.newBuilder(com.hotels.styx.server.netty.NettyServerBuilder.newBuilder) NettyExecutor(com.hotels.styx.NettyExecutor) IOException(java.io.IOException) HttpRequest(com.hotels.styx.api.HttpRequest) HttpInterceptorPipeline(com.hotels.styx.routing.handlers.HttpInterceptorPipeline) Service(com.google.common.util.concurrent.Service) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) List(java.util.List) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) OK(com.hotels.styx.api.HttpResponseStatus.OK) InetServer(com.hotels.styx.InetServer) ServerConnector(com.hotels.styx.server.netty.ServerConnector) StandardHttpRouter(com.hotels.styx.server.StandardHttpRouter) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) HttpInterceptorPipeline(com.hotels.styx.routing.handlers.HttpInterceptorPipeline) Service(com.google.common.util.concurrent.Service) HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) HttpAggregator(com.hotels.styx.common.http.handler.HttpAggregator) InetServer(com.hotels.styx.InetServer) Test(org.junit.jupiter.api.Test)

Example 72 with HttpResponse

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

the class CurrentRequestsHandlerTest method testStackTraceForSentRequest.

@Test
public void testStackTraceForSentRequest() {
    Thread.currentThread().setName("Test-Thread-1");
    tracker.trackRequest(req1);
    tracker.markRequestAsSent(req1);
    HttpResponse response = Mono.from(handler.handle(adminRequest, requestContext())).block();
    assertThat(response.bodyAs(UTF_8).contains("Request state: Waiting response from origin."), is(true));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 73 with HttpResponse

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

the class CurrentRequestsHandlerTest method testWithStackTrace.

@Test
public void testWithStackTrace() {
    Thread.currentThread().setName("Test-Thread");
    tracker.trackRequest(req1);
    HttpResponse response = Mono.from(handler.handle(HttpRequest.get("/req?withStackTrace=true").build(), requestContext())).block();
    assertTrue(response.bodyAs(UTF_8).contains("Thread Info:"));
    assertTrue(response.bodyAs(UTF_8).contains("id=" + Thread.currentThread().getId() + " state"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 74 with HttpResponse

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

the class IndexHandlerTest method printsTheRegisteredPaths.

@Test
public void printsTheRegisteredPaths() {
    HttpResponse response = Mono.from(handler.handle(get("/admin").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(response.contentType().map(String::toLowerCase).get(), is("text/html; charset=utf-8"));
    assertThat(response.bodyAs(UTF_8), is("<html><body><ol style='list-style-type: none; padding-left: 0px; margin-left: 0px;'>" + "<li><a href='/admin/foo'>Abc</a></li>" + "<li><a href='/admin/bar'>Xyz</a></li>" + "</ol></body></html>"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 75 with HttpResponse

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

the class JVMMetricsHandlerTest method exposesAllMetricsStartingWithJvm.

@Test
public void exposesAllMetricsStartingWithJvm() {
    HttpResponse response = call(get("/jvm").build());
    assertThat(response.bodyAs(UTF_8), containsStrings("jvm.foo.gauge", "jvm.bar.counter", "jvm.baz.meter", "jvm.hello.timer", "jvm.world.histogram"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpResponse (com.hotels.styx.api.HttpResponse)107 Test (org.junit.jupiter.api.Test)99 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)30 HttpRequest (com.hotels.styx.api.HttpRequest)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Eventual (com.hotels.styx.api.Eventual)10 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)9 StyxHttpClient (com.hotels.styx.client.StyxHttpClient)8 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)8 TlsSettings (com.hotels.styx.api.extension.service.TlsSettings)7 StyxObjectRecord (com.hotels.styx.StyxObjectRecord)6 HttpHandler (com.hotels.styx.api.HttpHandler)6 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)6 OK (com.hotels.styx.api.HttpResponseStatus.OK)5 HttpClient (com.hotels.styx.client.HttpClient)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)4 Plugin (com.hotels.styx.api.plugins.spi.Plugin)4 PluginFactory (com.hotels.styx.api.plugins.spi.PluginFactory)4 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)3