Search in sources :

Example 71 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project netty by netty.

the class AbstractSingleThreadEventLoopTest method testChannelsRegistered.

@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testChannelsRegistered() throws Exception {
    EventLoopGroup group = newEventLoopGroup();
    final SingleThreadEventLoop loop = (SingleThreadEventLoop) group.next();
    try {
        final Channel ch1 = newChannel();
        final Channel ch2 = newChannel();
        int rc = registeredChannels(loop);
        boolean channelCountSupported = rc != -1;
        if (channelCountSupported) {
            assertEquals(0, registeredChannels(loop));
        }
        assertTrue(loop.register(ch1).syncUninterruptibly().isSuccess());
        assertTrue(loop.register(ch2).syncUninterruptibly().isSuccess());
        if (channelCountSupported) {
            checkNumRegisteredChannels(loop, 2);
        }
        assertTrue(ch1.deregister().syncUninterruptibly().isSuccess());
        if (channelCountSupported) {
            checkNumRegisteredChannels(loop, 1);
        }
    } finally {
        group.shutdownGracefully();
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) LocalServerChannel(io.netty.channel.local.LocalServerChannel) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) SingleThreadEventLoop(io.netty.channel.SingleThreadEventLoop) Timeout(org.junit.jupiter.api.Timeout)

Example 72 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project netty by netty.

the class AbstractSingleThreadEventLoopTest method shutdownBeforeStart.

@Test
@SuppressWarnings("deprecation")
public void shutdownBeforeStart() throws Exception {
    EventLoopGroup group = newEventLoopGroup();
    assertFalse(group.awaitTermination(2, TimeUnit.MILLISECONDS));
    group.shutdown();
    assertTrue(group.awaitTermination(200, TimeUnit.MILLISECONDS));
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) Test(org.junit.jupiter.api.Test)

Example 73 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project netty by netty.

the class AbstractSingleThreadEventLoopTest method shutdownGracefullyBeforeStart.

@Test
public void shutdownGracefullyBeforeStart() throws Exception {
    EventLoopGroup group = newEventLoopGroup();
    assertTrue(group.shutdownGracefully(200L, 1000L, TimeUnit.MILLISECONDS).await(500L));
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) Test(org.junit.jupiter.api.Test)

Example 74 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project netty by netty.

the class DefaultAuthoritativeDnsServerCacheTest method testExpireWithTTL0.

private static void testExpireWithTTL0(int days) {
    EventLoopGroup group = new NioEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultAuthoritativeDnsServerCache cache = new DefaultAuthoritativeDnsServerCache();
        cache.cache("netty.io", new InetSocketAddress(NetUtil.LOCALHOST, 53), days, loop);
    } finally {
        group.shutdownGracefully();
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EventLoop(io.netty.channel.EventLoop) InetSocketAddress(java.net.InetSocketAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 75 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project netty by netty.

the class DefaultAuthoritativeDnsServerCacheTest method testUnresolvedReplacedByResolved.

@Test
public void testUnresolvedReplacedByResolved() throws Exception {
    InetSocketAddress unresolved = InetSocketAddress.createUnresolved("ns1", 53);
    InetSocketAddress resolved1 = new InetSocketAddress(InetAddress.getByAddress("ns2", new byte[] { 10, 0, 0, 2 }), 53);
    InetSocketAddress resolved2 = new InetSocketAddress(InetAddress.getByAddress("ns1", new byte[] { 10, 0, 0, 1 }), 53);
    EventLoopGroup group = new DefaultEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultAuthoritativeDnsServerCache cache = new DefaultAuthoritativeDnsServerCache();
        cache.cache("netty.io", unresolved, 100, loop);
        cache.cache("netty.io", resolved1, 10000, loop);
        DnsServerAddressStream entries = cache.get("netty.io");
        assertEquals(2, entries.size());
        assertEquals(unresolved, entries.next());
        assertEquals(resolved1, entries.next());
        cache.cache("netty.io", resolved2, 100, loop);
        DnsServerAddressStream entries2 = cache.get("netty.io");
        assertEquals(2, entries2.size());
        assertEquals(resolved2, entries2.next());
        assertEquals(resolved1, entries2.next());
    } finally {
        group.shutdownGracefully();
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EventLoop(io.netty.channel.EventLoop) InetSocketAddress(java.net.InetSocketAddress) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) Test(org.junit.jupiter.api.Test)

Aggregations

EventLoopGroup (io.netty.channel.EventLoopGroup)367 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)271 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)162 Bootstrap (io.netty.bootstrap.Bootstrap)137 Channel (io.netty.channel.Channel)131 ChannelFuture (io.netty.channel.ChannelFuture)129 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)109 SocketChannel (io.netty.channel.socket.SocketChannel)94 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)92 InetSocketAddress (java.net.InetSocketAddress)69 Test (org.junit.jupiter.api.Test)67 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)60 LoggingHandler (io.netty.handler.logging.LoggingHandler)55 ChannelPipeline (io.netty.channel.ChannelPipeline)51 SslContext (io.netty.handler.ssl.SslContext)51 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)50 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)49 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)46 LocalServerChannel (io.netty.channel.local.LocalServerChannel)42 LocalChannel (io.netty.channel.local.LocalChannel)40