Search in sources :

Example 1 with AbortedException

use of reactor.ipc.netty.channel.AbortedException 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 2 with AbortedException

use of reactor.ipc.netty.channel.AbortedException in project reactor-netty by reactor.

the class TcpClientTests method connectionWillAttemptToReconnectWhenItIsDropped.

@Test
public void connectionWillAttemptToReconnectWhenItIsDropped() throws InterruptedException, IOException {
    final CountDownLatch connectionLatch = new CountDownLatch(1);
    final CountDownLatch reconnectionLatch = new CountDownLatch(1);
    try {
        TcpClient tcpClient = TcpClient.create(opts -> opts.host("localhost").port(abortServerPort).disablePool());
        Mono<? extends NettyContext> handler = tcpClient.newHandler((in, out) -> {
            System.out.println("Start");
            connectionLatch.countDown();
            in.receive().subscribe();
            return Flux.never();
        });
        handler.log().block(Duration.ofSeconds(30)).onClose().then(handler.doOnSuccess(s -> reconnectionLatch.countDown())).block(Duration.ofSeconds(30));
        assertTrue("Initial connection is made", connectionLatch.await(5, TimeUnit.SECONDS));
        assertTrue("A reconnect attempt was made", reconnectionLatch.await(5, TimeUnit.SECONDS));
    } catch (AbortedException ise) {
        return;
    }
}
Also used : AbortedException(reactor.ipc.netty.channel.AbortedException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 AbortedException (reactor.ipc.netty.channel.AbortedException)2 Unpooled (io.netty.buffer.Unpooled)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)1 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)1 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 HttpVersion (io.netty.handler.codec.http.HttpVersion)1 SslContext (io.netty.handler.ssl.SslContext)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1 CharsetUtil (io.netty.util.CharsetUtil)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 URISyntaxException (java.net.URISyntaxException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1