Search in sources :

Example 1 with PoolResources

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

the class TcpClientTests method tcpClientHandlesLineFeedDataElasticPool.

@Test
public void tcpClientHandlesLineFeedDataElasticPool() 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.elastic("tcpClientHandlesLineFeedDataElasticPool")).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 2 with PoolResources

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

the class TcpResourcesTest method before.

@Before
public void before() {
    loopDisposed = new AtomicBoolean();
    poolDisposed = new AtomicBoolean();
    loopResources = new LoopResources() {

        @Override
        public EventLoopGroup onServer(boolean useNative) {
            return null;
        }

        @Override
        public Mono<Void> disposeLater() {
            return Mono.<Void>empty().doOnSuccess(c -> loopDisposed.set(true));
        }

        @Override
        public boolean isDisposed() {
            return loopDisposed.get();
        }
    };
    poolResources = new PoolResources() {

        @Override
        public ChannelPool selectOrCreate(SocketAddress address, Supplier<? extends Bootstrap> bootstrap, Consumer<? super Channel> onChannelCreate, EventLoopGroup group) {
            return null;
        }

        public Mono<Void> disposeLater() {
            return Mono.<Void>empty().doOnSuccess(c -> poolDisposed.set(true));
        }

        @Override
        public boolean isDisposed() {
            return poolDisposed.get();
        }
    };
    tcpResources = new TcpResources(loopResources, poolResources);
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) SocketAddress(java.net.SocketAddress) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) PoolResources(reactor.ipc.netty.resources.PoolResources) InetSocketAddress(java.net.InetSocketAddress) Supplier(java.util.function.Supplier) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Channel(io.netty.channel.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) Bootstrap(io.netty.bootstrap.Bootstrap) Flux(reactor.core.publisher.Flux) Duration(java.time.Duration) NettyContext(reactor.ipc.netty.NettyContext) ChannelPool(io.netty.channel.pool.ChannelPool) SocketUtils(reactor.ipc.netty.SocketUtils) LoopResources(reactor.ipc.netty.resources.LoopResources) Before(org.junit.Before) ChannelPool(io.netty.channel.pool.ChannelPool) Mono(reactor.core.publisher.Mono) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EventLoopGroup(io.netty.channel.EventLoopGroup) PoolResources(reactor.ipc.netty.resources.PoolResources) LoopResources(reactor.ipc.netty.resources.LoopResources) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Before(org.junit.Before)

Example 3 with PoolResources

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

the class HttpClientTest method pipelined.

@Test
@Ignore
public void pipelined() throws Exception {
    NettyContext x = TcpServer.create("localhost", 0).newHandler((in, out) -> out.context(c -> c.addHandlerFirst(new HttpResponseEncoder())).sendObject(Flux.just(response(), response())).neverComplete()).block(Duration.ofSeconds(30));
    PoolResources pool = PoolResources.fixed("test", 1);
    HttpClient.create(opts -> opts.host("localhost").port(x.address().getPort()).poolResources(pool)).get("/").flatMap(r -> {
        r.dispose();
        return Mono.just(r.status().code());
    }).log().block(Duration.ofSeconds(30));
    try {
        HttpClient.create(opts -> opts.host("localhost").port(x.address().getPort()).poolResources(pool)).get("/").log().block(Duration.ofSeconds(30));
    } catch (AbortedException ae) {
        return;
    }
    x.dispose();
    pool.dispose();
    Assert.fail("Not aborted");
}
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) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) PoolResources(reactor.ipc.netty.resources.PoolResources) AbortedException(reactor.ipc.netty.channel.AbortedException) NettyContext(reactor.ipc.netty.NettyContext) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with PoolResources

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

the class HttpClientTest method disableChunkImplicit.

@Test
public void disableChunkImplicit() throws Exception {
    PoolResources p = PoolResources.fixed("test", 1);
    HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.failOnClientError(false).sendHeaders()).block(Duration.ofSeconds(30));
    HttpClientResponse r2 = HttpClient.create(opts -> opts.poolResources(p)).get("http://google.com/unsupportedURI", c -> c.failOnClientError(false).sendHeaders()).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)

Example 5 with PoolResources

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

the class HttpClientTest method userIssue.

@Test
public void userIssue() throws Exception {
    final PoolResources pool = PoolResources.fixed("local", 1);
    CountDownLatch latch = new CountDownLatch(3);
    Set<String> localAddresses = ConcurrentHashMap.newKeySet();
    NettyContext serverContext = HttpServer.create(8080).newRouter(r -> r.post("/", (req, resp) -> req.receive().asString().flatMap(data -> {
        latch.countDown();
        return resp.status(200).send();
    }))).block();
    final HttpClient client = HttpClient.create(options -> {
        options.poolResources(pool);
        options.connectAddress(() -> new InetSocketAddress(8080));
    });
    Flux.just("1", "2", "3").concatMap(data -> client.post("/", req -> req.sendString(Flux.just(data))).doOnNext(r -> r.receive().subscribe())).subscribe(response -> {
        localAddresses.add(response.channel().localAddress().toString());
    });
    latch.await();
    pool.dispose();
    serverContext.dispose();
    System.out.println("Local Addresses used: " + localAddresses);
}
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) InetSocketAddress(java.net.InetSocketAddress) CountDownLatch(java.util.concurrent.CountDownLatch) NettyContext(reactor.ipc.netty.NettyContext) 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