Search in sources :

Example 1 with Netty4HttpServerTransport

use of org.elasticsearch.http.netty4.Netty4HttpServerTransport in project elasticsearch by elastic.

the class Netty4HttpChannelTests method testReleaseOnSendToClosedChannel.

public void testReleaseOnSendToClosedChannel() {
    final Settings settings = Settings.builder().build();
    final NamedXContentRegistry registry = xContentRegistry();
    try (Netty4HttpServerTransport httpServerTransport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, registry, new NullDispatcher())) {
        final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
        final Netty4HttpRequest request = new Netty4HttpRequest(registry, httpRequest, embeddedChannel);
        final HttpPipelinedRequest pipelinedRequest = randomBoolean() ? new HttpPipelinedRequest(request.request(), 1) : null;
        final Netty4HttpChannel channel = new Netty4HttpChannel(httpServerTransport, request, pipelinedRequest, randomBoolean(), threadPool.getThreadContext());
        final TestResponse response = new TestResponse(bigArrays);
        assertThat(response.content(), instanceOf(Releasable.class));
        embeddedChannel.close();
        channel.sendResponse(response);
    // ESTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
    }
}
Also used : NullDispatcher(org.elasticsearch.http.NullDispatcher) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpPipelinedRequest(org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest) Releasable(org.elasticsearch.common.lease.Releasable) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings) HttpTransportSettings(org.elasticsearch.http.HttpTransportSettings)

Example 2 with Netty4HttpServerTransport

use of org.elasticsearch.http.netty4.Netty4HttpServerTransport in project crate by crate.

the class CrateHttpsTransportTest method testPipelineConfiguration.

@Test
public void testPipelineConfiguration() throws Exception {
    Settings settings = Settings.builder().put(PATH_HOME_SETTING.getKey(), "/tmp").put(SslSettings.SSL_HTTP_ENABLED.getKey(), true).put(SslSettings.SSL_TRUSTSTORE_FILEPATH.getKey(), trustStoreFile.getAbsolutePath()).put(SslSettings.SSL_TRUSTSTORE_PASSWORD.getKey(), "keystorePassword").put(SslSettings.SSL_KEYSTORE_FILEPATH.getKey(), keyStoreFile.getAbsolutePath()).put(SslSettings.SSL_KEYSTORE_PASSWORD.getKey(), "keystorePassword").put(SslSettings.SSL_KEYSTORE_KEY_PASSWORD.getKey(), "keystorePassword").build();
    NetworkService networkService = new NetworkService(Collections.singletonList(new NetworkService.CustomNameResolver() {

        @Override
        public InetAddress[] resolveDefault() {
            return new InetAddress[] { InetAddresses.forString("127.0.0.1") };
        }

        @Override
        public InetAddress[] resolveIfPossible(String value) throws IOException {
            return new InetAddress[] { InetAddresses.forString("127.0.0.1") };
        }
    }));
    PipelineRegistry pipelineRegistry = new PipelineRegistry(settings);
    pipelineRegistry.setSslContextProvider(new SslContextProvider(settings));
    Netty4HttpServerTransport transport = new Netty4HttpServerTransport(settings, networkService, BigArrays.NON_RECYCLING_INSTANCE, mock(ThreadPool.class), NamedXContentRegistry.EMPTY, pipelineRegistry, new NettyBootstrap(), mock(NodeClient.class));
    EmbeddedChannel channel = new EmbeddedChannel();
    try {
        transport.start();
        Netty4HttpServerTransport.HttpChannelHandler httpChannelHandler = (Netty4HttpServerTransport.HttpChannelHandler) transport.configureServerChannelHandler();
        httpChannelHandler.initChannel(channel);
        assertThat(channel.pipeline().first(), instanceOf(SslHandler.class));
    } finally {
        transport.stop();
        transport.close();
        channel.releaseInbound();
        channel.close().awaitUninterruptibly();
    }
}
Also used : NodeClient(org.elasticsearch.client.node.NodeClient) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Netty4HttpServerTransport(org.elasticsearch.http.netty4.Netty4HttpServerTransport) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) PipelineRegistry(io.crate.netty.channel.PipelineRegistry) SslHandler(io.netty.handler.ssl.SslHandler) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) InetAddress(java.net.InetAddress) Settings(org.elasticsearch.common.settings.Settings) SslSettings(io.crate.protocols.ssl.SslSettings) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 Settings (org.elasticsearch.common.settings.Settings)2 NettyBootstrap (io.crate.netty.NettyBootstrap)1 PipelineRegistry (io.crate.netty.channel.PipelineRegistry)1 SslContextProvider (io.crate.protocols.ssl.SslContextProvider)1 SslSettings (io.crate.protocols.ssl.SslSettings)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 SslHandler (io.netty.handler.ssl.SslHandler)1 InetAddress (java.net.InetAddress)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Releasable (org.elasticsearch.common.lease.Releasable)1 NetworkService (org.elasticsearch.common.network.NetworkService)1 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)1 HttpTransportSettings (org.elasticsearch.http.HttpTransportSettings)1 NullDispatcher (org.elasticsearch.http.NullDispatcher)1 Netty4HttpServerTransport (org.elasticsearch.http.netty4.Netty4HttpServerTransport)1 HttpPipelinedRequest (org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest)1 ThreadPool (org.elasticsearch.threadpool.ThreadPool)1 Test (org.junit.Test)1