Search in sources :

Example 1 with ArrayByteBufferPool

use of org.eclipse.jetty.io.ArrayByteBufferPool in project jetty.project by eclipse.

the class GZIPContentDecoderTest method beforeClass.

@Before
public void beforeClass() throws Exception {
    buffers.set(0);
    pool = new ArrayByteBufferPool() {

        @Override
        public ByteBuffer acquire(int size, boolean direct) {
            buffers.incrementAndGet();
            return super.acquire(size, direct);
        }

        @Override
        public void release(ByteBuffer buffer) {
            buffers.decrementAndGet();
            super.release(buffer);
        }
    };
}
Also used : ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Example 2 with ArrayByteBufferPool

use of org.eclipse.jetty.io.ArrayByteBufferPool 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 3 with ArrayByteBufferPool

use of org.eclipse.jetty.io.ArrayByteBufferPool in project jetty.project by eclipse.

the class AbstractHttpTest method setUp.

@Before
public void setUp() throws Exception {
    server = new Server();
    connector = new ServerConnector(server, null, null, new ArrayByteBufferPool(64, 2048, 64 * 1024), 1, 1, new HttpConnectionFactory());
    connector.setIdleTimeout(100000);
    server.addConnector(connector);
    stacklessChannelLogging = new StacklessLogging(HttpChannel.class);
}
Also used : ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Before(org.junit.Before)

Example 4 with ArrayByteBufferPool

use of org.eclipse.jetty.io.ArrayByteBufferPool in project jetty.project by eclipse.

the class HttpClientLoadTest method newServerConnector.

@Override
protected ServerConnector newServerConnector(Server server) {
    int cores = Runtime.getRuntime().availableProcessors();
    ByteBufferPool byteBufferPool = new ArrayByteBufferPool();
    byteBufferPool = new LeakTrackingByteBufferPool(byteBufferPool);
    return new ServerConnector(server, null, null, byteBufferPool, 1, Math.min(1, cores / 2), provideServerConnectionFactory(transport));
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ServerConnector(org.eclipse.jetty.server.ServerConnector) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool)

Example 5 with ArrayByteBufferPool

use of org.eclipse.jetty.io.ArrayByteBufferPool in project jetty.project by eclipse.

the class HttpWriterTest method init.

@Before
public void init() throws Exception {
    _bytes = BufferUtil.allocate(2048);
    final ByteBufferPool pool = new ArrayByteBufferPool();
    HttpChannel channel = new HttpChannel(null, new HttpConfiguration(), null, null) {

        @Override
        public ByteBufferPool getByteBufferPool() {
            return pool;
        }
    };
    _httpOut = new HttpOutput(channel) {

        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            BufferUtil.append(_bytes, b, off, len);
        }
    };
}
Also used : ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

ArrayByteBufferPool (org.eclipse.jetty.io.ArrayByteBufferPool)5 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)3 Before (org.junit.Before)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 LeakTrackingByteBufferPool (org.eclipse.jetty.io.LeakTrackingByteBufferPool)1 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 Server (org.eclipse.jetty.server.Server)1 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)1 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)1 ThreadPool (org.eclipse.jetty.util.thread.ThreadPool)1 Test (org.junit.Test)1