Search in sources :

Example 31 with EventLoop

use of io.netty.channel.EventLoop in project netty by netty.

the class AbstractChannelPoolMapTest method testCloseClosesPoolsImmediately.

@Test
public void testCloseClosesPoolsImmediately() {
    EventLoopGroup group = new LocalEventLoopGroup();
    LocalAddress addr = new LocalAddress(getLocalAddrId());
    final Bootstrap cb = new Bootstrap();
    cb.remoteAddress(addr);
    cb.group(group).channel(LocalChannel.class);
    AbstractChannelPoolMap<EventLoop, TestPool> poolMap = new AbstractChannelPoolMap<EventLoop, TestPool>() {

        @Override
        protected TestPool newPool(EventLoop key) {
            return new TestPool(cb.clone(key), new TestChannelPoolHandler());
        }
    };
    EventLoop loop = group.next();
    TestPool pool = poolMap.get(loop);
    assertFalse(pool.closeFuture.isDone());
    // the pool should be closed immediately after remove
    poolMap.close();
    assertTrue(pool.closeFuture.isDone());
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) LocalEventLoopGroup(io.netty.channel.local.LocalEventLoopGroup) LocalEventLoopGroup(io.netty.channel.local.LocalEventLoopGroup) LocalAddress(io.netty.channel.local.LocalAddress) EventLoop(io.netty.channel.EventLoop) Bootstrap(io.netty.bootstrap.Bootstrap) Test(org.junit.jupiter.api.Test)

Example 32 with EventLoop

use of io.netty.channel.EventLoop in project netty by netty.

the class DefaultDnsCacheTest method testExpireWithTTL0.

private static void testExpireWithTTL0(int days) {
    EventLoopGroup group = new NioEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultDnsCache cache = new DefaultDnsCache();
        assertNotNull(cache.cache("netty.io", null, NetUtil.LOCALHOST, 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) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 33 with EventLoop

use of io.netty.channel.EventLoop in project netty by netty.

the class DefaultDnsCacheTest method testAddSameAddressForSameHostname.

@Test
public void testAddSameAddressForSameHostname() throws Exception {
    InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 });
    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, addr1, 10000, loop);
        List<? extends DnsCacheEntry> entries = cache.get("netty.io", null);
        assertEquals(1, entries.size());
        assertEntry(entries.get(0), addr1);
    } 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) Test(org.junit.jupiter.api.Test)

Example 34 with EventLoop

use of io.netty.channel.EventLoop in project netty by netty.

the class DefaultDnsCacheTest method testExpireWithToBigMinTTL.

@Test
public void testExpireWithToBigMinTTL() {
    EventLoopGroup group = new NioEventLoopGroup(1);
    try {
        EventLoop loop = group.next();
        final DefaultDnsCache cache = new DefaultDnsCache(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
        assertNotNull(cache.cache("netty.io", null, NetUtil.LOCALHOST, 100, 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) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.jupiter.api.Test)

Example 35 with EventLoop

use of io.netty.channel.EventLoop in project netty by netty.

the class DefaultDnsCacheTest method testCacheFailed.

@Test
public void testCacheFailed() throws Exception {
    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(1, 100, 100);
        cache.cache("netty.io", null, addr1, 10000, loop);
        cache.cache("netty.io", null, addr2, 10000, loop);
        List<? extends DnsCacheEntry> entries = cache.get("netty.io", null);
        assertEquals(2, entries.size());
        assertEntry(entries.get(0), addr1);
        assertEntry(entries.get(1), addr2);
        Exception exception = new Exception();
        cache.cache("netty.io", null, exception, loop);
        entries = cache.get("netty.io", null);
        DnsCacheEntry entry = entries.get(0);
        assertEquals(1, entries.size());
        assertSame(exception, entry.cause());
        assertNull(entry.address());
    } 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) Test(org.junit.jupiter.api.Test)

Aggregations

EventLoop (io.netty.channel.EventLoop)79 EventLoopGroup (io.netty.channel.EventLoopGroup)27 Test (org.junit.jupiter.api.Test)27 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)18 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)17 Bootstrap (io.netty.bootstrap.Bootstrap)11 Channel (io.netty.channel.Channel)11 InetSocketAddress (java.net.InetSocketAddress)11 InetAddress (java.net.InetAddress)9 ChannelFuture (io.netty.channel.ChannelFuture)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 ChannelPromise (io.netty.channel.ChannelPromise)6 ChannelFutureListener (io.netty.channel.ChannelFutureListener)5 LocalAddress (io.netty.channel.local.LocalAddress)5 ClosedChannelException (java.nio.channels.ClosedChannelException)5 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 List (java.util.List)4 SingleThreadEventLoop (io.netty.channel.SingleThreadEventLoop)3 IOException (java.io.IOException)3