Search in sources :

Example 76 with EventLoopGroup

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

the class DefaultAuthoritativeDnsServerCacheTest method testExpire.

@Test
public void testExpire() throws Throwable {
    InetSocketAddress resolved1 = new InetSocketAddress(InetAddress.getByAddress("ns1", new byte[] { 10, 0, 0, 1 }), 53);
    InetSocketAddress resolved2 = new InetSocketAddress(InetAddress.getByAddress("ns2", new byte[] { 10, 0, 0, 2 }), 53);
    EventLoopGroup group = new DefaultEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultAuthoritativeDnsServerCache cache = new DefaultAuthoritativeDnsServerCache();
        cache.cache("netty.io", resolved1, 1, loop);
        cache.cache("netty.io", resolved2, 10000, loop);
        Throwable error = loop.schedule(new Callable<Throwable>() {

            @Override
            public Throwable call() {
                try {
                    assertNull(cache.get("netty.io"));
                    return null;
                } catch (Throwable cause) {
                    return cause;
                }
            }
        }, 1, TimeUnit.SECONDS).get();
        if (error != null) {
            throw error;
        }
    } 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) Callable(java.util.concurrent.Callable) Test(org.junit.jupiter.api.Test)

Example 77 with EventLoopGroup

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

the class DefaultDnsCnameCacheTest method testExpire.

@Test
public void testExpire() throws Throwable {
    EventLoopGroup group = new DefaultEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultDnsCnameCache cache = new DefaultDnsCnameCache();
        cache.cache("netty.io", "mapping.netty.io", 1, loop);
        Throwable error = loop.schedule(new Callable<Throwable>() {

            @Override
            public Throwable call() {
                try {
                    assertNull(cache.get("netty.io"));
                    return null;
                } catch (Throwable cause) {
                    return cause;
                }
            }
        }, 1, TimeUnit.SECONDS).get();
        if (error != null) {
            throw error;
        }
    } finally {
        group.shutdownGracefully();
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) EventLoop(io.netty.channel.EventLoop) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) Callable(java.util.concurrent.Callable) Test(org.junit.jupiter.api.Test)

Example 78 with EventLoopGroup

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

the class DefaultDnsCnameCacheTest method testExpireWithTTL0.

private static void testExpireWithTTL0(int days) {
    EventLoopGroup group = new DefaultEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultDnsCnameCache cache = new DefaultDnsCnameCache();
        cache.cache("netty.io", "mapping.netty.io", TimeUnit.DAYS.toSeconds(days), loop);
        assertEquals("mapping.netty.io", cache.get("netty.io"));
    } finally {
        group.shutdownGracefully();
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) EventLoop(io.netty.channel.EventLoop) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup)

Example 79 with EventLoopGroup

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

the class DnsNameResolverClientSubnetTest method testSubnetQuery.

// See https://www.gsic.uva.es/~jnisigl/dig-edns-client-subnet.html
// Ignore as this needs to query real DNS servers.
@Disabled
@Test
public void testSubnetQuery() throws Exception {
    EventLoopGroup group = new NioEventLoopGroup(1);
    DnsNameResolver resolver = newResolver(group).build();
    try {
        // Same as:
        // # /.bind-9.9.3-edns/bin/dig @ns1.google.com www.google.es +client=157.88.0.0/24
        Future<List<InetAddress>> future = resolver.resolveAll("www.google.es", Collections.<DnsRecord>singleton(// 157.88.0.0 / 24
        new DefaultDnsOptEcsRecord(1024, 24, SocketUtils.addressByName("157.88.0.0").getAddress())));
        for (InetAddress address : future.syncUninterruptibly().getNow()) {
            System.out.println(address);
        }
    } finally {
        resolver.close();
        group.shutdownGracefully(0, 0, TimeUnit.SECONDS);
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) DefaultDnsOptEcsRecord(io.netty.handler.codec.dns.DefaultDnsOptEcsRecord) List(java.util.List) InetAddress(java.net.InetAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 80 with EventLoopGroup

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

the class DefaultDnsCacheTest method testExpire.

@Test
public void testExpire() throws Throwable {
    InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 });
    InetAddress addr2 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 2 });
    EventLoopGroup group = new DefaultEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultDnsCache cache = new DefaultDnsCache();
        cache.cache("netty.io", null, addr1, 1, loop);
        cache.cache("netty.io", null, addr2, 10000, loop);
        Throwable error = loop.schedule(new Callable<Throwable>() {

            @Override
            public Throwable call() {
                try {
                    assertNull(cache.get("netty.io", null));
                    return null;
                } catch (Throwable cause) {
                    return cause;
                }
            }
        }, 1, TimeUnit.SECONDS).get();
        if (error != null) {
            throw error;
        }
    } 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) InetAddress(java.net.InetAddress) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) Callable(java.util.concurrent.Callable) 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