Search in sources :

Example 11 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.

the class HttpServerTests method contextShouldBeTransferredFromDownStreamToUpsream.

@Test
public void contextShouldBeTransferredFromDownStreamToUpsream() {
    AtomicReference<Context> context = new AtomicReference<>();
    NettyContext server = HttpServer.create(0).newHandler((req, res) -> res.status(200).send()).block(Duration.ofSeconds(300));
    HttpClient client = HttpClient.create(ops -> ops.connectAddress(() -> server.address()).poolResources(PoolResources.fixed("test", 1)));
    try {
        Mono<String> content = client.post("/", req -> req.failOnClientError(false).sendString(Mono.just("bodysample").subscriberContext(c -> {
            context.set(c);
            return c;
        }))).flatMap(res -> res.receive().aggregate().asString()).subscriberContext(c -> c.put("Hello", "World"));
        StepVerifier.create(content).expectComplete().verify(Duration.ofSeconds(300));
        assertThat(context.get().get("Hello").equals("World")).isTrue();
    } finally {
        server.dispose();
    }
}
Also used : BlockingNettyContext(reactor.ipc.netty.tcp.BlockingNettyContext) Context(reactor.util.context.Context) SslContext(io.netty.handler.ssl.SslContext) NettyContext(reactor.ipc.netty.NettyContext) HttpResources(reactor.ipc.netty.http.HttpResources) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) StepVerifier(reactor.test.StepVerifier) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) NettyOutbound(reactor.ipc.netty.NettyOutbound) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) BlockingNettyContext(reactor.ipc.netty.tcp.BlockingNettyContext) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Path(java.nio.file.Path) Context(reactor.util.context.Context) StandardOpenOption(java.nio.file.StandardOpenOption) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) FileSystem(java.nio.file.FileSystem) InetSocketAddress(java.net.InetSocketAddress) HttpClientResponse(reactor.ipc.netty.http.client.HttpClientResponse) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) SSLException(javax.net.ssl.SSLException) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) ByteBufFlux(reactor.ipc.netty.ByteBufFlux) HttpVersion(io.netty.handler.codec.http.HttpVersion) FluxSink(reactor.core.publisher.FluxSink) Tuple3(reactor.util.function.Tuple3) Tuple2(reactor.util.function.Tuple2) AsynchronousFileChannel(java.nio.channels.AsynchronousFileChannel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ByteBuf(io.netty.buffer.ByteBuf) Assert(org.testng.Assert) HttpClient(reactor.ipc.netty.http.client.HttpClient) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ExecutorService(java.util.concurrent.ExecutorService) TcpClient(reactor.ipc.netty.tcp.TcpClient) SslContext(io.netty.handler.ssl.SslContext) Files(java.nio.file.Files) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) FutureMono(reactor.ipc.netty.FutureMono) CompletionHandler(java.nio.channels.CompletionHandler) HttpMethod(io.netty.handler.codec.http.HttpMethod) IOException(java.io.IOException) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) PoolResources(reactor.ipc.netty.resources.PoolResources) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flux(reactor.core.publisher.Flux) Paths(java.nio.file.Paths) NettyContext(reactor.ipc.netty.NettyContext) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) FileSystems(java.nio.file.FileSystems) HttpClient(reactor.ipc.netty.http.client.HttpClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlockingNettyContext(reactor.ipc.netty.tcp.BlockingNettyContext) NettyContext(reactor.ipc.netty.NettyContext) Test(org.junit.Test)

Example 12 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.

the class TcpClientTests method tcpClientHandlesLineFeedDataFixedPool.

@Test
public void tcpClientHandlesLineFeedDataFixedPool() throws InterruptedException {
    Consumer<Channel> channelInit = c -> c.pipeline().addBefore(NettyPipeline.ReactiveBridge, "codec", new LineBasedFrameDecoder(8 * 1024));
    tcpClientHandlesLineFeedData(opts -> opts.host("localhost").port(echoServerPort).poolResources(PoolResources.fixed("tcpClientHandlesLineFeedDataFixedPool", 1)).afterChannelInit(channelInit));
}
Also used : Arrays(java.util.Arrays) ChannelOption(io.netty.channel.ChannelOption) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) SocketChannel(java.nio.channels.SocketChannel) NettyPipeline(reactor.ipc.netty.NettyPipeline) Duration(java.time.Duration) After(org.junit.After) HttpClient(reactor.ipc.netty.http.client.HttpClient) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) SocketUtils(reactor.ipc.netty.SocketUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Publisher(org.reactivestreams.Publisher) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) PoolResources(reactor.ipc.netty.resources.PoolResources) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) ServerSocketChannel(java.nio.channels.ServerSocketChannel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Channel(io.netty.channel.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flux(reactor.core.publisher.Flux) List(java.util.List) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) NettyContext(reactor.ipc.netty.NettyContext) ClientOptions(reactor.ipc.netty.options.ClientOptions) Matchers.is(org.hamcrest.Matchers.is) AbortedException(reactor.ipc.netty.channel.AbortedException) Assert.assertEquals(org.junit.Assert.assertEquals) SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Channel(io.netty.channel.Channel) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) Test(org.junit.Test)

Example 13 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.

the class HttpClientTest method closePool.

@Test
public void closePool() {
    PoolResources pr = PoolResources.fixed("wstest", 1);
    NettyContext httpServer = HttpServer.create(0).newHandler((in, out) -> out.options(opt -> opt.flushOnEach()).sendString(Mono.just("test").delayElement(Duration.ofMillis(100)).repeat())).block(Duration.ofSeconds(30));
    Flux<String> ws = HttpClient.create(opts -> opts.port(httpServer.address().getPort()).poolResources(pr)).get("/").flatMapMany(in -> in.receive().asString());
    StepVerifier.create(Flux.range(1, 10).concatMap(i -> ws.take(2).log())).expectNextSequence(Flux.range(1, 20).map(v -> "test").toIterable()).expectComplete().verify();
    httpServer.dispose();
    pr.dispose();
}
Also used : HttpResources(reactor.ipc.netty.http.HttpResources) HttpVersion(io.netty.handler.codec.http.HttpVersion) StepVerifier(reactor.test.StepVerifier) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Unpooled(io.netty.buffer.Unpooled) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) Duration(java.time.Duration) CharsetUtil(io.netty.util.CharsetUtil) Path(java.nio.file.Path) HttpServer(reactor.ipc.netty.http.server.HttpServer) DirectProcessor(reactor.core.publisher.DirectProcessor) SslContext(io.netty.handler.ssl.SslContext) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) FutureMono(reactor.ipc.netty.FutureMono) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) PoolResources(reactor.ipc.netty.resources.PoolResources) InetSocketAddress(java.net.InetSocketAddress) StandardCharsets(java.nio.charset.StandardCharsets) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) SSLException(javax.net.ssl.SSLException) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) TcpServer(reactor.ipc.netty.tcp.TcpServer) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) NettyContext(reactor.ipc.netty.NettyContext) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) AbortedException(reactor.ipc.netty.channel.AbortedException) Assert(org.junit.Assert) InputStream(java.io.InputStream) Proxy(reactor.ipc.netty.options.ClientProxyOptions.Proxy) PoolResources(reactor.ipc.netty.resources.PoolResources) NettyContext(reactor.ipc.netty.NettyContext) Test(org.junit.Test)

Example 14 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.

the class HttpClientTest method contentHeader.

@Test
public void contentHeader() throws Exception {
    PoolResources fixed = PoolResources.fixed("test", 1);
    HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(fixed)).get("http://google.com", c -> c.header("content-length", "1").failOnClientError(false).sendString(Mono.just(" "))).block(Duration.ofSeconds(30));
    HttpClientResponse r1 = HttpClient.create(opts -> opts.poolResources(fixed)).get("http://google.com", c -> c.header("content-length", "1").failOnClientError(false).sendString(Mono.just(" "))).block(Duration.ofSeconds(30));
    Assert.assertTrue(r.status() == HttpResponseStatus.BAD_REQUEST);
    r.dispose();
    r1.dispose();
    fixed.dispose();
}
Also used : HttpResources(reactor.ipc.netty.http.HttpResources) HttpVersion(io.netty.handler.codec.http.HttpVersion) StepVerifier(reactor.test.StepVerifier) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Unpooled(io.netty.buffer.Unpooled) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) Duration(java.time.Duration) CharsetUtil(io.netty.util.CharsetUtil) Path(java.nio.file.Path) HttpServer(reactor.ipc.netty.http.server.HttpServer) DirectProcessor(reactor.core.publisher.DirectProcessor) SslContext(io.netty.handler.ssl.SslContext) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) FutureMono(reactor.ipc.netty.FutureMono) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) PoolResources(reactor.ipc.netty.resources.PoolResources) InetSocketAddress(java.net.InetSocketAddress) StandardCharsets(java.nio.charset.StandardCharsets) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) SSLException(javax.net.ssl.SSLException) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) TcpServer(reactor.ipc.netty.tcp.TcpServer) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) NettyContext(reactor.ipc.netty.NettyContext) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) AbortedException(reactor.ipc.netty.channel.AbortedException) Assert(org.junit.Assert) InputStream(java.io.InputStream) Proxy(reactor.ipc.netty.options.ClientProxyOptions.Proxy) PoolResources(reactor.ipc.netty.resources.PoolResources) Test(org.junit.Test)

Example 15 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.

the class HttpClientTest method disableChunkImplicitDefault.

@Test
public void disableChunkImplicitDefault() throws Exception {
    PoolResources p = PoolResources.fixed("test", 1);
    HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.chunkedTransfer(false).failOnClientError(false)).block(Duration.ofSeconds(30));
    HttpClientResponse r2 = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.chunkedTransfer(false).failOnClientError(false)).block(Duration.ofSeconds(30));
    Assert.assertTrue(r.context().channel() == r2.context().channel());
    Assert.assertTrue(r.status() == HttpResponseStatus.NOT_FOUND);
    r.dispose();
    r2.dispose();
    p.dispose();
}
Also used : HttpResources(reactor.ipc.netty.http.HttpResources) HttpVersion(io.netty.handler.codec.http.HttpVersion) StepVerifier(reactor.test.StepVerifier) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Unpooled(io.netty.buffer.Unpooled) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) Duration(java.time.Duration) CharsetUtil(io.netty.util.CharsetUtil) Path(java.nio.file.Path) HttpServer(reactor.ipc.netty.http.server.HttpServer) DirectProcessor(reactor.core.publisher.DirectProcessor) SslContext(io.netty.handler.ssl.SslContext) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) FutureMono(reactor.ipc.netty.FutureMono) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) PoolResources(reactor.ipc.netty.resources.PoolResources) InetSocketAddress(java.net.InetSocketAddress) StandardCharsets(java.nio.charset.StandardCharsets) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) SSLException(javax.net.ssl.SSLException) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) TcpServer(reactor.ipc.netty.tcp.TcpServer) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) NettyContext(reactor.ipc.netty.NettyContext) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) AbortedException(reactor.ipc.netty.channel.AbortedException) Assert(org.junit.Assert) InputStream(java.io.InputStream) Proxy(reactor.ipc.netty.options.ClientProxyOptions.Proxy) PoolResources(reactor.ipc.netty.resources.PoolResources) Test(org.junit.Test)

Aggregations

PoolResources (reactor.ipc.netty.resources.PoolResources)21 Test (org.junit.Test)18 Mono (reactor.core.publisher.Mono)17 Duration (java.time.Duration)16 Flux (reactor.core.publisher.Flux)15 NettyContext (reactor.ipc.netty.NettyContext)15 InetSocketAddress (java.net.InetSocketAddress)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 StepVerifier (reactor.test.StepVerifier)12 SslContext (io.netty.handler.ssl.SslContext)11 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 FutureMono (reactor.ipc.netty.FutureMono)10 HttpServer (reactor.ipc.netty.http.server.HttpServer)10 Unpooled (io.netty.buffer.Unpooled)9 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)9 HttpVersion (io.netty.handler.codec.http.HttpVersion)9 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)9 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)9