Search in sources :

Example 96 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class BlockingConnectionTest method testTimeoutOnStop.

@Test
void testTimeoutOnStop() {
    Connection c = new TestClientTransport(Mono.just(NEVER_STOP_CONTEXT)).connectNow();
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> c.disposeNow(Duration.ofMillis(100))).withMessage("Socket couldn't be stopped within 100ms");
}
Also used : Connection(reactor.netty.Connection) Test(org.junit.jupiter.api.Test)

Example 97 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class ReactorNettyLoggingHandler method channelString.

private String channelString(Channel channel) {
    String channelStr;
    StringBuilder result;
    Connection connection = Connection.from(channel);
    if (connection instanceof ChannelOperationsId) {
        channelStr = ((ChannelOperationsId) connection).asLongText();
        if (channelStr.charAt(0) != TRACE_ID_PREFIX) {
            result = new StringBuilder(1 + channelStr.length() + 1).append(CHANNEL_ID_PREFIX).append(channelStr).append(CHANNEL_ID_SUFFIX);
        } else {
            result = new StringBuilder(channelStr);
        }
    } else {
        channelStr = channel.toString();
        if (channelStr.charAt(0) == CHANNEL_ID_PREFIX) {
            channelStr = channelStr.substring(ORIGINAL_CHANNEL_ID_PREFIX_LENGTH);
            result = new StringBuilder(1 + channelStr.length()).append(CHANNEL_ID_PREFIX).append(channelStr);
        } else {
            int ind = channelStr.indexOf(ORIGINAL_CHANNEL_ID_PREFIX);
            result = new StringBuilder(1 + (channelStr.length() - ORIGINAL_CHANNEL_ID_PREFIX_LENGTH)).append(channelStr.substring(0, ind)).append(CHANNEL_ID_PREFIX).append(channelStr.substring(ind + ORIGINAL_CHANNEL_ID_PREFIX_LENGTH));
        }
    }
    return result.toString();
}
Also used : ChannelOperationsId(reactor.netty.ChannelOperationsId) Connection(reactor.netty.Connection)

Example 98 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class TcpClientTests method tcpClientHandlesLineFeedDataElasticPool.

@Test
void tcpClientHandlesLineFeedDataElasticPool() throws InterruptedException {
    Consumer<? super Connection> channelInit = c -> c.addHandler("codec", new LineBasedFrameDecoder(8 * 1024));
    tcpClientHandlesLineFeedData(TcpClient.create(ConnectionProvider.create("tcpClientHandlesLineFeedDataElasticPool", Integer.MAX_VALUE)).host("localhost").port(echoServerPort).doOnConnected(channelInit));
}
Also used : AttributeKey(io.netty.util.AttributeKey) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) AbortedException(reactor.netty.channel.AbortedException) Retry(reactor.util.retry.Retry) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) Future(java.util.concurrent.Future) Loggers(reactor.util.Loggers) SocketChannel(java.nio.channels.SocketChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Duration(java.time.Duration) Logger(reactor.util.Logger) NameResolverProvider(reactor.netty.transport.NameResolverProvider) LoopResources(reactor.netty.resources.LoopResources) ChannelOperations(reactor.netty.channel.ChannelOperations) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) NettyOutbound(reactor.netty.NettyOutbound) DisposableServer(reactor.netty.DisposableServer) ChannelOption(io.netty.channel.ChannelOption) SocketUtils(reactor.netty.SocketUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Schedulers(reactor.core.scheduler.Schedulers) WeakReference(java.lang.ref.WeakReference) Connection(reactor.netty.Connection) ExecutorService(java.util.concurrent.ExecutorService) Properties(java.util.Properties) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Publisher(org.reactivestreams.Publisher) NetUtil(io.netty.util.NetUtil) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) ServerSocketChannel(java.nio.channels.ServerSocketChannel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Bootstrap(io.netty.bootstrap.Bootstrap) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DefaultAddressResolverGroup(io.netty.resolver.DefaultAddressResolverGroup) ConnectionProvider(reactor.netty.resources.ConnectionProvider) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) Test(org.junit.jupiter.api.Test)

Example 99 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class TcpClientTests method tcpClientHandlesLineFeedDataFixedPool.

@Test
void tcpClientHandlesLineFeedDataFixedPool() throws InterruptedException {
    Consumer<? super Connection> channelInit = c -> c.addHandler("codec", new LineBasedFrameDecoder(8 * 1024));
    ConnectionProvider p = ConnectionProvider.newConnection();
    tcpClientHandlesLineFeedData(TcpClient.create(p).host("localhost").port(echoServerPort).doOnConnected(channelInit));
}
Also used : AttributeKey(io.netty.util.AttributeKey) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) AbortedException(reactor.netty.channel.AbortedException) Retry(reactor.util.retry.Retry) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) Future(java.util.concurrent.Future) Loggers(reactor.util.Loggers) SocketChannel(java.nio.channels.SocketChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Duration(java.time.Duration) Logger(reactor.util.Logger) NameResolverProvider(reactor.netty.transport.NameResolverProvider) LoopResources(reactor.netty.resources.LoopResources) ChannelOperations(reactor.netty.channel.ChannelOperations) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) NettyOutbound(reactor.netty.NettyOutbound) DisposableServer(reactor.netty.DisposableServer) ChannelOption(io.netty.channel.ChannelOption) SocketUtils(reactor.netty.SocketUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Schedulers(reactor.core.scheduler.Schedulers) WeakReference(java.lang.ref.WeakReference) Connection(reactor.netty.Connection) ExecutorService(java.util.concurrent.ExecutorService) Properties(java.util.Properties) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Publisher(org.reactivestreams.Publisher) NetUtil(io.netty.util.NetUtil) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) ServerSocketChannel(java.nio.channels.ServerSocketChannel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Bootstrap(io.netty.bootstrap.Bootstrap) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DefaultAddressResolverGroup(io.netty.resolver.DefaultAddressResolverGroup) ConnectionProvider(reactor.netty.resources.ConnectionProvider) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) ConnectionProvider(reactor.netty.resources.ConnectionProvider) Test(org.junit.jupiter.api.Test)

Example 100 with Connection

use of reactor.netty.Connection in project reactor-netty by reactor.

the class TcpClientTests method testReconnectWhenDisconnected.

@Test
void testReconnectWhenDisconnected() throws Exception {
    DisposableServer server = TcpServer.create().port(0).wiretap(true).handle((req, res) -> res.sendString(Mono.just("test"))).bindNow();
    final CountDownLatch latch = new CountDownLatch(1);
    TcpClient client = TcpClient.create().port(echoServerPort).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100).handle((in, out) -> out.withConnection(Connection::dispose)).wiretap(true);
    connect(client, true, latch);
    assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    server.disposeNow();
}
Also used : AttributeKey(io.netty.util.AttributeKey) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) SocketAddress(java.net.SocketAddress) AbortedException(reactor.netty.channel.AbortedException) Retry(reactor.util.retry.Retry) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) Future(java.util.concurrent.Future) Loggers(reactor.util.Loggers) SocketChannel(java.nio.channels.SocketChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Duration(java.time.Duration) Logger(reactor.util.Logger) NameResolverProvider(reactor.netty.transport.NameResolverProvider) LoopResources(reactor.netty.resources.LoopResources) ChannelOperations(reactor.netty.channel.ChannelOperations) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) NettyOutbound(reactor.netty.NettyOutbound) DisposableServer(reactor.netty.DisposableServer) ChannelOption(io.netty.channel.ChannelOption) SocketUtils(reactor.netty.SocketUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Schedulers(reactor.core.scheduler.Schedulers) WeakReference(java.lang.ref.WeakReference) Connection(reactor.netty.Connection) ExecutorService(java.util.concurrent.ExecutorService) Properties(java.util.Properties) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Publisher(org.reactivestreams.Publisher) NetUtil(io.netty.util.NetUtil) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) ServerSocketChannel(java.nio.channels.ServerSocketChannel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Bootstrap(io.netty.bootstrap.Bootstrap) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DefaultAddressResolverGroup(io.netty.resolver.DefaultAddressResolverGroup) ConnectionProvider(reactor.netty.resources.ConnectionProvider) DisposableServer(reactor.netty.DisposableServer) Connection(reactor.netty.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (reactor.netty.Connection)137 Test (org.junit.jupiter.api.Test)69 CountDownLatch (java.util.concurrent.CountDownLatch)52 Duration (java.time.Duration)49 Mono (reactor.core.publisher.Mono)47 InetSocketAddress (java.net.InetSocketAddress)41 TimeUnit (java.util.concurrent.TimeUnit)39 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)38 LoopResources (reactor.netty.resources.LoopResources)38 ByteBuf (io.netty.buffer.ByteBuf)35 Flux (reactor.core.publisher.Flux)35 DisposableServer (reactor.netty.DisposableServer)35 DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)33 AtomicReference (java.util.concurrent.atomic.AtomicReference)32 List (java.util.List)31 IOException (java.io.IOException)30 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)30 ChannelOption (io.netty.channel.ChannelOption)29 Unpooled (io.netty.buffer.Unpooled)28 Charset (java.nio.charset.Charset)28