use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestTestingHttpServer method testFilteredRequest.
@Test
public void testFilteredRequest() throws Exception {
DummyServlet servlet = new DummyServlet();
DummyFilter filter = new DummyFilter();
TestingHttpServer server = createTestingHttpServerWithFilter(servlet, ImmutableMap.of(), filter);
try {
server.start();
try (HttpClient client = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(1, SECONDS)))) {
StatusResponse response = client.execute(prepareGet().setUri(server.getBaseUrl()).build(), createStatusResponseHandler());
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(servlet.getCallCount(), 1);
assertEquals(filter.getCallCount(), 1);
}
} finally {
server.stop();
}
}
use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestTestingHttpServer method testRequest.
@Test
public void testRequest() throws Exception {
DummyServlet servlet = new DummyServlet();
TestingHttpServer server = createTestingHttpServer(servlet, ImmutableMap.of());
try {
server.start();
try (HttpClient client = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(1, SECONDS)))) {
StatusResponse response = client.execute(prepareGet().setUri(server.getBaseUrl()).build(), createStatusResponseHandler());
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(servlet.getCallCount(), 1);
}
} finally {
server.stop();
}
}
use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestServer method setup.
@BeforeMethod
public void setup() throws Exception {
Bootstrap app = new Bootstrap(new TestingNodeModule(), new TestingHttpServerModule(), new JsonModule(), new JaxrsModule(), new JmxHttpModule(), new JmxModule(), new MainModule());
Injector injector = app.doNotInitializeLogging().initialize();
lifeCycleManager = injector.getInstance(LifeCycleManager.class);
server = injector.getInstance(TestingHttpServer.class);
client = new JettyHttpClient();
}
use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestServiceInventory method testHttpServiceInventory.
@Test
public void testHttpServiceInventory() throws Exception {
String serviceInventoryJson = Resources.toString(Resources.getResource("service-inventory.json"), UTF_8);
Server server = null;
try (JettyHttpClient httpClient = new JettyHttpClient()) {
int port;
try (ServerSocket socket = new ServerSocket()) {
socket.bind(new InetSocketAddress(0));
port = socket.getLocalPort();
}
URI baseURI = new URI("http", null, "127.0.0.1", port, null, null, null);
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setSendServerVersion(false);
httpConfiguration.setSendXPoweredBy(false);
server = new Server();
ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
httpConnector.setPort(port);
httpConnector.setName("http");
server.addConnector(httpConnector);
ServletHolder servletHolder = new ServletHolder(new ServiceInventoryServlet(serviceInventoryJson));
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.addServlet(servletHolder, "/*");
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(context);
server.setHandler(handlers);
server.start();
// test
ServiceInventoryConfig serviceInventoryConfig = new ServiceInventoryConfig().setServiceInventoryUri(baseURI);
ServiceInventory serviceInventory = new ServiceInventory(serviceInventoryConfig, new NodeInfo("test"), JsonCodec.jsonCodec(ServiceDescriptorsRepresentation.class), httpClient);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors()), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery")), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery", "general")), 2);
serviceInventory.updateServiceInventory();
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors()), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery")), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery", "general")), 2);
} finally {
if (server != null) {
server.stop();
}
}
}
use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestServer method setup.
@BeforeMethod
public void setup() {
Bootstrap app = new Bootstrap(new TestingNodeModule(), new InMemoryEventModule(), new TestingHttpServerModule(), new JsonModule(), new JaxrsModule(), new MainModule());
Injector injector = app.doNotInitializeLogging().initialize();
lifeCycleManager = injector.getInstance(LifeCycleManager.class);
server = injector.getInstance(TestingHttpServer.class);
store = injector.getInstance(PersonStore.class);
eventClient = injector.getInstance(InMemoryEventClient.class);
client = new JettyHttpClient();
}
Aggregations