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());
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations