Search in sources :

Example 71 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project dropwizard by dropwizard.

the class HttpConnectorFactoryTest method testBuildConnector.

@Test
public void testBuildConnector() throws Exception {
    HttpConnectorFactory http = new HttpConnectorFactory();
    http.setBindHost("127.0.0.1");
    http.setAcceptorThreads(Optional.of(1));
    http.setSelectorThreads(Optional.of(2));
    http.setAcceptQueueSize(1024);
    http.setSoLingerTime(Duration.seconds(30));
    http.setBlockingTimeout(Duration.minutes(1));
    Server server = new Server();
    MetricRegistry metrics = new MetricRegistry();
    ThreadPool threadPool = new QueuedThreadPool();
    ServerConnector connector = (ServerConnector) http.build(server, metrics, "test-http-connector", threadPool);
    assertThat(connector.getPort()).isEqualTo(8080);
    assertThat(connector.getHost()).isEqualTo("127.0.0.1");
    assertThat(connector.getAcceptQueueSize()).isEqualTo(1024);
    assertThat(connector.getReuseAddress()).isTrue();
    assertThat(connector.getSoLingerTime()).isEqualTo(30);
    assertThat(connector.getIdleTimeout()).isEqualTo(30000);
    assertThat(connector.getName()).isEqualTo("test-http-connector");
    assertThat(connector.getServer()).isSameAs(server);
    assertThat(connector.getScheduler()).isInstanceOf(ScheduledExecutorScheduler.class);
    assertThat(connector.getExecutor()).isSameAs(threadPool);
    // That's gross, but unfortunately ArrayByteBufferPool doesn't have public API for configuration
    ByteBufferPool byteBufferPool = connector.getByteBufferPool();
    assertThat(byteBufferPool).isInstanceOf(ArrayByteBufferPool.class);
    assertThat(getField(ArrayByteBufferPool.class, "_min", true).get(byteBufferPool)).isEqualTo(64);
    assertThat(getField(ArrayByteBufferPool.class, "_inc", true).get(byteBufferPool)).isEqualTo(1024);
    assertThat(((Object[]) getField(ArrayByteBufferPool.class, "_direct", true).get(byteBufferPool)).length).isEqualTo(64);
    assertThat(connector.getAcceptors()).isEqualTo(1);
    assertThat(connector.getSelectorManager().getSelectorCount()).isEqualTo(2);
    Jetty93InstrumentedConnectionFactory connectionFactory = (Jetty93InstrumentedConnectionFactory) connector.getConnectionFactory("http/1.1");
    assertThat(connectionFactory).isInstanceOf(Jetty93InstrumentedConnectionFactory.class);
    assertThat(connectionFactory.getTimer()).isSameAs(metrics.timer("org.eclipse.jetty.server.HttpConnectionFactory.127.0.0.1.8080.connections"));
    HttpConnectionFactory httpConnectionFactory = (HttpConnectionFactory) connectionFactory.getConnectionFactory();
    assertThat(httpConnectionFactory.getInputBufferSize()).isEqualTo(8192);
    assertThat(httpConnectionFactory.getHttpCompliance()).isEqualByComparingTo(HttpCompliance.RFC7230);
    HttpConfiguration httpConfiguration = httpConnectionFactory.getHttpConfiguration();
    assertThat(httpConfiguration.getHeaderCacheSize()).isEqualTo(512);
    assertThat(httpConfiguration.getOutputBufferSize()).isEqualTo(32768);
    assertThat(httpConfiguration.getRequestHeaderSize()).isEqualTo(8192);
    assertThat(httpConfiguration.getResponseHeaderSize()).isEqualTo(8192);
    assertThat(httpConfiguration.getSendDateHeader()).isTrue();
    assertThat(httpConfiguration.getSendServerVersion()).isFalse();
    assertThat(httpConfiguration.getCustomizers()).hasAtLeastOneElementOfType(ForwardedRequestCustomizer.class);
    assertThat(httpConfiguration.getBlockingTimeout()).isEqualTo(60000L);
    connector.stop();
    server.stop();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) MetricRegistry(com.codahale.metrics.MetricRegistry) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Test(org.junit.Test)

Example 72 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class RawHTTP2ProxyTest method startClient.

private HTTP2Client startClient(String name) throws Exception {
    HTTP2Client client = new HTTP2Client();
    QueuedThreadPool clientExecutor = new QueuedThreadPool();
    clientExecutor.setName(name);
    client.setExecutor(clientExecutor);
    clients.add(client);
    client.start();
    return client;
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool)

Example 73 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class RawHTTP2ProxyTest method startServer.

private Server startServer(String name, ServerSessionListener listener) throws Exception {
    QueuedThreadPool serverExecutor = new QueuedThreadPool();
    serverExecutor.setName(name);
    Server server = new Server(serverExecutor);
    RawHTTP2ServerConnectionFactory connectionFactory = new RawHTTP2ServerConnectionFactory(new HttpConfiguration(), listener);
    ServerConnector connector = new ServerConnector(server, 1, 1, connectionFactory);
    server.addConnector(connector);
    server.setAttribute("connector", connector);
    servers.add(server);
    server.start();
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) RawHTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.RawHTTP2ServerConnectionFactory) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 74 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class ProxyTest method startClient.

private void startClient() throws Exception {
    QueuedThreadPool clientExecutor = new QueuedThreadPool();
    clientExecutor.setName("client");
    client = new HTTP2Client();
    client.setExecutor(clientExecutor);
    client.start();
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool)

Example 75 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class ProxyTest method startServer.

private void startServer(HttpServlet servlet) throws Exception {
    QueuedThreadPool serverPool = new QueuedThreadPool();
    serverPool.setName("server");
    server = new Server(serverPool);
    serverConnector = new ServerConnector(server);
    server.addConnector(serverConnector);
    ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
    ServletHolder appServletHolder = new ServletHolder(servlet);
    appCtx.addServlet(appServletHolder, "/*");
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)126 Server (org.eclipse.jetty.server.Server)65 ServerConnector (org.eclipse.jetty.server.ServerConnector)51 Test (org.junit.Test)30 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)26 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)23 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)22 HttpClient (org.eclipse.jetty.client.HttpClient)18 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)18 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)18 IOException (java.io.IOException)17 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)11 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)11 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)10 File (java.io.File)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 InputStream (java.io.InputStream)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)8