Migrate transport tests to JUnit 5 (#11315)

Motivation:

JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel.

Modifications:

Use JUnit5 in tests

Result:

Related to https://github.com/netty/netty/issues/10757
This commit is contained in:
Riley Park 2021-05-26 01:47:15 -07:00 committed by GitHub
parent aedccda965
commit c80d55bd7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 413 additions and 289 deletions

View File

@ -42,8 +42,9 @@ import io.netty.util.AttributeKey;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.net.ConnectException;
import java.net.SocketAddress;
@ -58,6 +59,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
@ -65,10 +67,11 @@ import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BootstrapTest {
@ -76,7 +79,7 @@ public class BootstrapTest {
private static final EventLoopGroup groupB = new MultithreadEventLoopGroup(1, LocalHandler.newFactory());
private static final ChannelHandler dummyHandler = new DummyHandler();
@AfterClass
@AfterAll
public static void destroy() {
groupA.shutdownGracefully();
groupB.shutdownGracefully();
@ -125,7 +128,8 @@ public class BootstrapTest {
.bind(LocalAddress.ANY).sync();
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testBindDeadLock() throws Exception {
final Bootstrap bootstrapA = new Bootstrap();
bootstrapA.group(groupA);
@ -155,7 +159,8 @@ public class BootstrapTest {
}
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testConnectDeadLock() throws Exception {
final Bootstrap bootstrapA = new Bootstrap();
bootstrapA.group(groupA);
@ -256,7 +261,8 @@ public class BootstrapTest {
}
}
@Test(expected = ConnectException.class, timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testLateRegistrationConnect() throws Throwable {
EventLoopGroup group = new MultithreadEventLoopGroup(1, LocalHandler.newFactory());
LateRegisterHandler registerHandler = new LateRegisterHandler();
@ -268,9 +274,8 @@ public class BootstrapTest {
ChannelFuture future = bootstrapA.connect(LocalAddress.ANY);
assertFalse(future.isDone());
registerHandler.registerPromise().setSuccess();
future.syncUninterruptibly();
} catch (CompletionException e) {
throw e.getCause();
assertTrue(assertThrows(CompletionException.class, future::syncUninterruptibly)
.getCause() instanceof ConnectException);
} finally {
group.shutdownGracefully();
}

View File

@ -29,20 +29,23 @@ import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalHandler;
import io.netty.channel.local.LocalServerChannel;
import io.netty.util.AttributeKey;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ServerBootstrapTest {
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testHandlerRegister() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> error = new AtomicReference<>();
@ -72,12 +75,14 @@ public class ServerBootstrapTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testParentHandler() throws Exception {
testParentHandler(false);
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testParentHandlerViaChannelInitializer() throws Exception {
testParentHandler(true);
}

View File

@ -21,9 +21,10 @@ import java.net.SocketAddress;
import java.nio.channels.ClosedChannelException;
import io.netty.util.NetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;
public class AbstractChannelTest {

View File

@ -20,13 +20,13 @@ import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.ReferenceCountUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.nio.channels.ClosedChannelException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class AbstractCoalescingBufferQueueTest {

View File

@ -18,15 +18,17 @@ package io.netty.channel;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.util.concurrent.Future;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
public abstract class AbstractEventLoopTest {
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testShutdownGracefullyNoQuietPeriod() throws Exception {
EventLoopGroup loop = newEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();

View File

@ -18,11 +18,11 @@ package io.netty.channel;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -32,7 +32,7 @@ public class AdaptiveRecvByteBufAllocatorTest {
private ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT;
private RecvByteBufAllocator.ExtendedHandle handle;
@Before
@BeforeEach
public void setup() {
config = mock(ChannelConfig.class);
when(config.isAutoRead()).thenReturn(true);

View File

@ -15,7 +15,6 @@
*/
package io.netty.channel;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
@ -24,7 +23,7 @@ import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalHandler;
import io.netty.channel.local.LocalServerChannel;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
class BaseChannelTest {

View File

@ -15,9 +15,10 @@
*/
package io.netty.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import io.netty.channel.ChannelHandler.Sharable;
@ -30,18 +31,18 @@ public class ChannelHandlerAdapterTest {
@Test
public void testSharable() {
ChannelHandlerAdapter handler = new SharableChannelHandlerAdapter();
assertEquals(true, handler.isSharable());
assertTrue(handler.isSharable());
}
@Test
public void testInnerClassSharable() {
ChannelHandlerAdapter handler = new @Sharable ChannelHandlerAdapter() { };
assertEquals(true, handler.isSharable());
assertTrue(handler.isSharable());
}
@Test
public void testWithoutSharable() {
ChannelHandlerAdapter handler = new ChannelHandlerAdapter() { };
assertEquals(false, handler.isSharable());
assertFalse(handler.isSharable());
}
}

View File

@ -22,9 +22,10 @@ import io.netty.channel.local.LocalAddress;
import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalHandler;
import io.netty.channel.local.LocalServerChannel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.nio.channels.ClosedChannelException;
import java.util.Iterator;
@ -34,10 +35,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
public class ChannelInitializerTest {
private static final int TIMEOUT_MILLIS = 1000;
@ -47,7 +48,7 @@ public class ChannelInitializerTest {
private Bootstrap client;
private InspectableHandler testHandler;
@Before
@BeforeEach
public void setUp() {
group = new MultithreadEventLoopGroup(1, LocalHandler.newFactory());
server = new ServerBootstrap()
@ -61,7 +62,7 @@ public class ChannelInitializerTest {
testHandler = new InspectableHandler();
}
@After
@AfterEach
public void tearDown() {
group.shutdownGracefully(0, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).syncUninterruptibly();
}
@ -180,7 +181,8 @@ public class ChannelInitializerTest {
}
}
@Test(timeout = TIMEOUT_MILLIS)
@Test
@Timeout(value = TIMEOUT_MILLIS, unit = TimeUnit.MILLISECONDS)
public void firstHandlerInPipelineShouldReceiveChannelRegisteredEvent() {
testChannelRegisteredEventPropagation(new ChannelInitializer<LocalChannel>() {
@Override
@ -190,7 +192,8 @@ public class ChannelInitializerTest {
});
}
@Test(timeout = TIMEOUT_MILLIS)
@Test
@Timeout(value = TIMEOUT_MILLIS, unit = TimeUnit.MILLISECONDS)
public void lastHandlerInPipelineShouldReceiveChannelRegisteredEvent() {
testChannelRegisteredEventPropagation(new ChannelInitializer<LocalChannel>() {
@Override

View File

@ -15,14 +15,13 @@
*/
package io.netty.channel;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class ChannelOptionTest {

View File

@ -19,8 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
@ -29,7 +28,10 @@ import java.util.concurrent.Executors;
import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ChannelOutboundBufferTest {
@ -57,11 +59,11 @@ public class ChannelOutboundBufferTest {
ByteBuf buf = copiedBuffer("buf1", CharsetUtil.US_ASCII);
ByteBuffer nioBuf = buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes());
buffer.addMessage(buf, buf.readableBytes(), channel.voidPromise());
assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount());
assertEquals(0, buffer.nioBufferCount(), "Should still be 0 as not flushed yet");
buffer.addFlush();
ByteBuffer[] buffers = buffer.nioBuffers();
assertNotNull(buffers);
assertEquals("Should still be 0 as not flushed yet", 1, buffer.nioBufferCount());
assertEquals(1, buffer.nioBufferCount(), "Should still be 0 as not flushed yet");
for (int i = 0; i < buffer.nioBufferCount(); i++) {
if (i == 0) {
assertEquals(buffers[i], nioBuf);
@ -82,7 +84,7 @@ public class ChannelOutboundBufferTest {
for (int i = 0; i < 64; i++) {
buffer.addMessage(buf.copy(), buf.readableBytes(), channel.voidPromise());
}
assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount());
assertEquals(0, buffer.nioBufferCount(), "Should still be 0 as not flushed yet");
buffer.addFlush();
ByteBuffer[] buffers = buffer.nioBuffers();
assertEquals(64, buffer.nioBufferCount());
@ -106,7 +108,7 @@ public class ChannelOutboundBufferTest {
}
buffer.addMessage(comp, comp.readableBytes(), channel.voidPromise());
assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount());
assertEquals(0, buffer.nioBufferCount(), "Should still be 0 as not flushed yet");
buffer.addFlush();
ByteBuffer[] buffers = buffer.nioBuffers();
assertEquals(65, buffer.nioBufferCount());
@ -134,11 +136,11 @@ public class ChannelOutboundBufferTest {
}
assertEquals(65, comp.nioBufferCount());
buffer.addMessage(comp, comp.readableBytes(), channel.voidPromise());
assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount());
assertEquals(0, buffer.nioBufferCount(), "Should still be 0 as not flushed yet");
buffer.addFlush();
final int maxCount = 10; // less than comp.nioBufferCount()
ByteBuffer[] buffers = buffer.nioBuffers(maxCount, Integer.MAX_VALUE);
assertTrue("Should not be greater than maxCount", buffer.nioBufferCount() <= maxCount);
assertTrue(buffer.nioBufferCount() <= maxCount, "Should not be greater than maxCount");
for (int i = 0; i < buffer.nioBufferCount(); i++) {
assertEquals(buffers[i], buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()));
}

View File

@ -19,14 +19,14 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for {@link CoalescingBufferQueue}.
@ -46,7 +46,7 @@ public class CoalescingBufferQueueTest {
private EmbeddedChannel channel;
private CoalescingBufferQueue writeQueue;
@Before
@BeforeEach
public void setup() {
mouseDone = false;
mouseSuccess = false;
@ -64,7 +64,7 @@ public class CoalescingBufferQueueTest {
mouse = Unpooled.wrappedBuffer("mouse".getBytes(CharsetUtil.US_ASCII));
}
@After
@AfterEach
public void finish() {
assertFalse(channel.finish());
}

View File

@ -16,14 +16,20 @@
package io.netty.channel;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CombinedChannelDuplexHandlerTest {
@ -53,49 +59,51 @@ public class CombinedChannelDuplexHandlerTest {
DISCONNECT
}
@Test(expected = IllegalStateException.class)
@Test
public void testInboundRemoveBeforeAdded() {
CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler> handler =
new CombinedChannelDuplexHandler<>(
new ChannelHandler() { }, new ChannelHandler() { });
handler.removeInboundHandler();
assertThrows(IllegalStateException.class, handler::removeInboundHandler);
}
@Test(expected = IllegalStateException.class)
@Test
public void testOutboundRemoveBeforeAdded() {
CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler> handler =
new CombinedChannelDuplexHandler<>(
new ChannelHandler() { }, new ChannelHandler() { });
handler.removeOutboundHandler();
assertThrows(IllegalStateException.class, handler::removeOutboundHandler);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testInboundHandlerImplementsOutboundHandler() {
new CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler>(
new ChannelHandler() {
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) {
promise.setFailure(new UnsupportedOperationException());
}
}, new ChannelHandler() { });
assertThrows(IllegalArgumentException.class,
() -> new CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler>(
new ChannelHandler() {
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) {
promise.setFailure(new UnsupportedOperationException());
}
}, new ChannelHandler() { }));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testOutboundHandlerImplementsInboundHandler() {
new CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler>(
new ChannelHandler() { }, new ChannelHandler() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
// NOOP
}
});
assertThrows(IllegalArgumentException.class,
() -> new CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler>(
new ChannelHandler() { }, new ChannelHandler() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
// NOOP
}
}));
}
@Test(expected = IllegalStateException.class)
@Test
public void testInitNotCalledBeforeAdded() throws Exception {
CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler> handler =
new CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler>() { };
handler.handlerAdded(null);
assertThrows(IllegalStateException.class, () -> handler.handlerAdded(null));
}
@Test
@ -323,7 +331,8 @@ public class CombinedChannelDuplexHandlerTest {
channel.pipeline().deregister();
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testPromisesPassed() {
ChannelHandler outboundHandler = new ChannelHandler() {
@Override
@ -390,13 +399,14 @@ public class CombinedChannelDuplexHandlerTest {
ch.finish();
}
@Test(expected = IllegalStateException.class)
@Test
public void testNotSharable() {
new CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler>() {
@Override
public boolean isSharable() {
return true;
}
};
assertThrows(IllegalStateException.class,
() -> new CombinedChannelDuplexHandler<ChannelHandler, ChannelHandler>() {
@Override
public boolean isSharable() {
return true;
}
});
}
}

View File

@ -15,18 +15,20 @@
*/
package io.netty.channel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CompleteChannelFutureTest {
@Test(expected = NullPointerException.class)
@Test
public void shouldDisallowNullChannel() {
new CompleteChannelFutureImpl(null);
assertThrows(NullPointerException.class, () -> new CompleteChannelFutureImpl(null));
}
@Test

View File

@ -20,7 +20,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@ -29,7 +29,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SuppressWarnings("DynamicRegexReplaceableByCompiledPattern")
public class DefaultChannelIdTest {

View File

@ -15,8 +15,8 @@
*/
package io.netty.channel;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.net.SocketAddress;
@ -25,20 +25,20 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import io.netty.channel.local.LocalHandler;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class DefaultChannelPipelineTailTest {
private static EventLoopGroup GROUP;
@BeforeClass
@BeforeAll
public static void init() {
GROUP = new MultithreadEventLoopGroup(1, LocalHandler.newFactory());
}
@AfterClass
@AfterAll
public static void destroy() {
GROUP.shutdownGracefully();
}

View File

@ -39,9 +39,10 @@ import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
import io.netty.util.concurrent.ScheduledFuture;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.net.SocketAddress;
import java.util.ArrayDeque;
@ -60,14 +61,15 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class DefaultChannelPipelineTest {
@ -76,7 +78,7 @@ public class DefaultChannelPipelineTest {
private Channel self;
private Channel peer;
@AfterClass
@AfterAll
public static void afterClass() throws Exception {
group.shutdownGracefully().sync();
}
@ -114,7 +116,7 @@ public class DefaultChannelPipelineTest {
bindFuture.channel().close().sync();
}
@After
@AfterEach
public void tearDown() throws Exception {
if (peer != null) {
peer.close();
@ -264,14 +266,14 @@ public class DefaultChannelPipelineTest {
assertNotNull(pipeline.get("handler1"));
}
@Test(expected = NoSuchElementException.class)
@Test
public void testRemoveThrowNoSuchElementException() {
DefaultChannelPipeline pipeline = new DefaultChannelPipeline(newLocalChannel());
ChannelHandler handler1 = newHandler();
pipeline.addLast("handler1", handler1);
pipeline.remove("handlerXXX");
assertThrows(NoSuchElementException.class, () -> pipeline.remove("handlerXXX"));
}
@Test
@ -299,7 +301,7 @@ public class DefaultChannelPipelineTest {
assertSame(pipeline.get("handler2"), newHandler2);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testReplaceHandlerChecksDuplicateNames() {
ChannelPipeline pipeline = newLocalChannel().pipeline();
@ -309,7 +311,7 @@ public class DefaultChannelPipelineTest {
pipeline.addLast("handler2", handler2);
ChannelHandler newHandler1 = newHandler();
pipeline.replace("handler1", "handler2", newHandler1);
assertThrows(IllegalArgumentException.class, () -> pipeline.replace("handler1", "handler2", newHandler1));
}
@Test
@ -368,7 +370,8 @@ public class DefaultChannelPipelineTest {
verifyContextNumber(pipeline, HANDLER_ARRAY_LEN * 2);
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testThrowInExceptionCaught() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger counter = new AtomicInteger();
@ -406,7 +409,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testThrowInOtherHandlerAfterInvokedFromExceptionCaught() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger counter = new AtomicInteger();
@ -527,7 +531,8 @@ public class DefaultChannelPipelineTest {
verifyContextNumber(pipeline, 8);
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testLifeCycleAwareness() throws Exception {
setUp();
@ -570,7 +575,8 @@ public class DefaultChannelPipelineTest {
removeLatch.await();
}
@Test(timeout = 100000)
@Test
@Timeout(value = 100000, unit = TimeUnit.MILLISECONDS)
public void testRemoveAndForwardInbound() throws Exception {
final BufferedTestHandler handler1 = new BufferedTestHandler();
final BufferedTestHandler handler2 = new BufferedTestHandler();
@ -588,7 +594,8 @@ public class DefaultChannelPipelineTest {
}).sync();
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testRemoveAndForwardOutbound() throws Exception {
final BufferedTestHandler handler1 = new BufferedTestHandler();
final BufferedTestHandler handler2 = new BufferedTestHandler();
@ -606,7 +613,8 @@ public class DefaultChannelPipelineTest {
}).sync();
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testReplaceAndForwardOutbound() throws Exception {
final BufferedTestHandler handler1 = new BufferedTestHandler();
final BufferedTestHandler handler2 = new BufferedTestHandler();
@ -623,7 +631,8 @@ public class DefaultChannelPipelineTest {
}).sync();
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testReplaceAndForwardInboundAndOutbound() throws Exception {
final BufferedTestHandler handler1 = new BufferedTestHandler();
final BufferedTestHandler handler2 = new BufferedTestHandler();
@ -646,7 +655,8 @@ public class DefaultChannelPipelineTest {
}).sync();
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testRemoveAndForwardInboundOutbound() throws Exception {
final BufferedTestHandler handler1 = new BufferedTestHandler();
final BufferedTestHandler handler2 = new BufferedTestHandler();
@ -716,7 +726,7 @@ public class DefaultChannelPipelineTest {
assertTrue(future.isCancelled());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testWrongPromiseChannel() throws Exception {
ChannelPipeline pipeline = newLocalChannel().pipeline();
pipeline.channel().register().sync();
@ -726,34 +736,34 @@ public class DefaultChannelPipelineTest {
try {
ChannelPromise promise2 = pipeline2.channel().newPromise();
pipeline.close(promise2);
assertThrows(IllegalArgumentException.class, () -> pipeline.close(promise2));
} finally {
pipeline.close();
pipeline2.close();
}
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testUnexpectedVoidChannelPromise() throws Exception {
ChannelPipeline pipeline = newLocalChannel().pipeline();
pipeline.channel().register().sync();
try {
ChannelPromise promise = new VoidChannelPromise(pipeline.channel(), false);
pipeline.close(promise);
assertThrows(IllegalArgumentException.class, () -> pipeline.close(promise));
} finally {
pipeline.close();
}
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testUnexpectedVoidChannelPromiseCloseFuture() throws Exception {
ChannelPipeline pipeline = newLocalChannel().pipeline();
pipeline.channel().register().sync();
try {
ChannelPromise promise = (ChannelPromise) pipeline.channel().closeFuture();
pipeline.close(promise);
assertThrows(IllegalArgumentException.class, () -> pipeline.close(promise));
} finally {
pipeline.close();
}
@ -822,7 +832,8 @@ public class DefaultChannelPipelineTest {
assertNull(pipeline.last());
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testChannelInitializerException() throws Exception {
final IllegalStateException exception = new IllegalStateException();
final AtomicReference<Throwable> error = new AtomicReference<>();
@ -845,7 +856,8 @@ public class DefaultChannelPipelineTest {
assertSame(exception, error.get());
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddHandlerBeforeRegisteredThenRemove() {
final EventLoop loop = group.next();
@ -860,7 +872,8 @@ public class DefaultChannelPipelineTest {
pipeline.channel().close().syncUninterruptibly();
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddHandlerBeforeRegisteredThenReplace() throws Exception {
final EventLoop loop = group.next();
final CountDownLatch latch = new CountDownLatch(1);
@ -882,7 +895,8 @@ public class DefaultChannelPipelineTest {
pipeline.channel().close().syncUninterruptibly();
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testAddRemoveHandlerCalled() throws Throwable {
ChannelPipeline pipeline = newLocalChannel().pipeline();
@ -936,7 +950,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testOperationsFailWhenRemoved() {
ChannelPipeline pipeline = newLocalChannel().pipeline();
try {
@ -953,7 +968,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testOperationsFailWhenReplaced() {
ChannelPipeline pipeline = newLocalChannel().pipeline();
try {
@ -1040,7 +1056,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddReplaceHandlerCalled() throws Throwable {
ChannelPipeline pipeline = newLocalChannel().pipeline();
CallbackCheckHandler handler = new CallbackCheckHandler();
@ -1071,7 +1088,8 @@ public class DefaultChannelPipelineTest {
pipeline.channel().close().syncUninterruptibly();
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddBefore() throws Throwable {
EventLoopGroup defaultGroup = new MultithreadEventLoopGroup(2, LocalHandler.newFactory());
try {
@ -1097,7 +1115,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddInListenerNio() throws Throwable {
EventLoopGroup nioEventLoopGroup = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
try {
@ -1107,7 +1126,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddInListenerLocal() throws Throwable {
testAddInListener(newLocalChannel());
}
@ -1163,7 +1183,8 @@ public class DefaultChannelPipelineTest {
pipeline.addBefore("test", null, newHandler());
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testVoidPromiseNotify() throws Throwable {
EventLoopGroup defaultGroup = new MultithreadEventLoopGroup(1, LocalHandler.newFactory());
EventLoop eventLoop1 = defaultGroup.next();
@ -1507,7 +1528,7 @@ public class DefaultChannelPipelineTest {
}
private void assertCalled(String methodName, int mask) {
assertTrue(methodName + " was not called", (executionMask & mask) != 0);
assertTrue((executionMask & mask) != 0, methodName + " was not called");
}
}
@ -1597,7 +1618,7 @@ public class DefaultChannelPipelineTest {
}
private void assertCalled(String methodName, int mask) {
assertTrue(methodName + " was not called", (executionMask & mask) != 0);
assertTrue((executionMask & mask) != 0, methodName + " was not called");
}
}
@ -1684,12 +1705,14 @@ public class DefaultChannelPipelineTest {
channel2.close().syncUninterruptibly();
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void handlerAddedStateUpdatedBeforeHandlerAddedDoneForceEventLoop() throws InterruptedException {
handlerAddedStateUpdatedBeforeHandlerAddedDone(true);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void handlerAddedStateUpdatedBeforeHandlerAddedDoneOnCallingThread() throws InterruptedException {
handlerAddedStateUpdatedBeforeHandlerAddedDone(false);
}
@ -2004,8 +2027,8 @@ public class DefaultChannelPipelineTest {
}
public void validate(boolean afterAdd, boolean afterRemove) {
assertEquals(name, afterAdd, this.afterAdd);
assertEquals(name, afterRemove, this.afterRemove);
assertEquals(afterAdd, this.afterAdd, name);
assertEquals(afterRemove, this.afterRemove, name);
}
@Override

View File

@ -17,22 +17,25 @@ package io.netty.channel;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.concurrent.ImmediateEventExecutor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class DefaultChannelPromiseTest {
@Test(expected = NullPointerException.class)
@Test
public void testNullChannel() {
new DefaultChannelPromise(null);
assertThrows(NullPointerException.class, () -> new DefaultChannelPromise(null));
}
@Test(expected = NullPointerException.class)
@Test
public void testChannelWithNullExecutor() {
new DefaultChannelPromise(new EmbeddedChannel(), null);
assertThrows(NullPointerException.class, () -> new DefaultChannelPromise(new EmbeddedChannel(), null));
}
@Test(expected = NullPointerException.class)
@Test
public void testNullChannelWithExecutor() {
new DefaultChannelPromise(null, ImmediateEventExecutor.INSTANCE);
assertThrows(NullPointerException.class,
() -> new DefaultChannelPromise(null, ImmediateEventExecutor.INSTANCE));
}
}

View File

@ -16,7 +16,7 @@
package io.netty.channel;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -27,9 +27,9 @@ import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class DefaultFileRegionTest {

View File

@ -17,7 +17,7 @@ package io.netty.channel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class DelegatingChannelPromiseNotifierTest {

View File

@ -15,10 +15,12 @@
*/
package io.netty.channel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class FailedChannelFutureTest {
@Test
@ -31,8 +33,9 @@ public class FailedChannelFutureTest {
assertSame(e, future.cause());
}
@Test(expected = NullPointerException.class)
@Test
public void shouldDisallowNullException() {
new FailedChannelFuture(Mockito.mock(Channel.class), null, null);
assertThrows(NullPointerException.class,
() -> new FailedChannelFuture(Mockito.mock(Channel.class), null, null));
}
}

View File

@ -20,8 +20,8 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
@ -30,7 +30,13 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class PendingWriteQueueTest {
@ -39,7 +45,7 @@ public class PendingWriteQueueTest {
assertWrite(new TestHandler() {
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
assertFalse("Should not be writable anymore", ctx.channel().isWritable());
assertFalse(ctx.channel().isWritable(), "Should not be writable anymore");
ChannelFuture future = queue.removeAndWrite();
future.addListener((ChannelFutureListener) future1 -> assertQueueEmpty(queue));
@ -53,7 +59,7 @@ public class PendingWriteQueueTest {
assertWrite(new TestHandler() {
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
assertFalse("Should not be writable anymore", ctx.channel().isWritable());
assertFalse(ctx.channel().isWritable(), "Should not be writable anymore");
ChannelFuture future = queue.removeAndWriteAll();
future.addListener((ChannelFutureListener) future1 -> assertQueueEmpty(queue));
@ -287,7 +293,7 @@ public class PendingWriteQueueTest {
assertEquals(2L, (long) channel.readOutbound());
}
@Ignore("Need to verify and think about if the assumptions made by this test are valid at all.")
@Disabled("Need to verify and think about if the assumptions made by this test are valid at all.")
@Test
public void testRemoveAndFailAllReentrantWrite() {
final List<Integer> failOrder = Collections.synchronizedList(new ArrayList<>());
@ -374,7 +380,7 @@ public class PendingWriteQueueTest {
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelActive();
assertQueueEmpty(queue);
assertTrue("Should be writable", ctx.channel().isWritable());
assertTrue(ctx.channel().isWritable(), "Should be writable");
}
@Override

View File

@ -21,12 +21,13 @@ import io.netty.channel.LoggingHandler.Event;
import io.netty.channel.local.LocalAddress;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.nio.channels.ClosedChannelException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class ReentrantChannelTest extends BaseChannelTest {

View File

@ -18,13 +18,15 @@ package io.netty.channel;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SimpleUserEventChannelHandlerTest {
@ -32,7 +34,7 @@ public class SimpleUserEventChannelHandlerTest {
private AllEventCatcher allEventCatcher;
private EmbeddedChannel channel;
@Before
@BeforeEach
public void setUp() {
fooEventCatcher = new FooEventCatcher();
allEventCatcher = new AllEventCatcher();

View File

@ -21,9 +21,10 @@ import ch.qos.logback.core.Appender;
import io.netty.channel.local.LocalChannel;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.SingleThreadEventExecutor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
@ -43,7 +44,10 @@ import java.util.concurrent.atomic.AtomicLong;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class SingleThreadEventLoopTest {
@ -52,13 +56,13 @@ public class SingleThreadEventLoopTest {
private SingleThreadEventLoopA loopA;
private SingleThreadEventLoopB loopB;
@Before
@BeforeEach
public void newEventLoop() {
loopA = new SingleThreadEventLoopA();
loopB = new SingleThreadEventLoopB();
}
@After
@AfterEach
public void stopEventLoop() {
if (!loopA.isShuttingDown()) {
loopA.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS);
@ -140,12 +144,14 @@ public class SingleThreadEventLoopTest {
is(greaterThanOrEqualTo(TimeUnit.MILLISECONDS.toNanos(500))));
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void scheduleTaskAtFixedRateA() throws Exception {
testScheduleTaskAtFixedRate(loopA);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void scheduleTaskAtFixedRateB() throws Exception {
testScheduleTaskAtFixedRate(loopB);
}
@ -185,12 +191,14 @@ public class SingleThreadEventLoopTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void scheduleLaggyTaskAtFixedRateA() throws Exception {
testScheduleLaggyTaskAtFixedRate(loopA);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void scheduleLaggyTaskAtFixedRateB() throws Exception {
testScheduleLaggyTaskAtFixedRate(loopB);
}
@ -236,12 +244,14 @@ public class SingleThreadEventLoopTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void scheduleTaskWithFixedDelayA() throws Exception {
testScheduleTaskWithFixedDelay(loopA);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void scheduleTaskWithFixedDelayB() throws Exception {
testScheduleTaskWithFixedDelay(loopB);
}
@ -320,7 +330,8 @@ public class SingleThreadEventLoopTest {
assertEquals(NUM_TASKS, ranTasks.get());
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
@SuppressWarnings("deprecation")
public void testRegistrationAfterShutdown() throws Exception {
loopA.shutdown();
@ -349,7 +360,8 @@ public class SingleThreadEventLoopTest {
}
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
@SuppressWarnings("deprecation")
public void testRegistrationAfterShutdown2() throws Exception {
loopA.shutdown();
@ -384,7 +396,8 @@ public class SingleThreadEventLoopTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testGracefulShutdownQuietPeriod() throws Exception {
loopA.shutdownGracefully(1, Integer.MAX_VALUE, TimeUnit.SECONDS);
// Keep Scheduling tasks for another 2 seconds.
@ -406,7 +419,8 @@ public class SingleThreadEventLoopTest {
is(greaterThanOrEqualTo(TimeUnit.SECONDS.toNanos(1))));
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testGracefulShutdownTimeout() throws Exception {
loopA.shutdownGracefully(2, 2, TimeUnit.SECONDS);
// Keep Scheduling tasks for another 3 seconds.

View File

@ -15,10 +15,11 @@
*/
package io.netty.channel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SucceededChannelFutureTest {
@Test

View File

@ -20,13 +20,14 @@ import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelId;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class EmbeddedChannelIdTest {
@Test
@ -50,9 +51,9 @@ public class EmbeddedChannelIdTest {
inStream.close();
}
Assert.assertEquals(normalInstance, deserializedInstance);
Assert.assertEquals(normalInstance.hashCode(), deserializedInstance.hashCode());
Assert.assertEquals(0, normalInstance.compareTo(deserializedInstance));
assertEquals(normalInstance, deserializedInstance);
assertEquals(normalInstance.hashCode(), deserializedInstance.hashCode());
assertEquals(0, normalInstance.compareTo(deserializedInstance));
}
}

View File

@ -15,12 +15,12 @@
*/
package io.netty.channel.embedded;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import io.netty.channel.ChannelOutboundInvoker;
import java.nio.channels.ClosedChannelException;
@ -32,7 +32,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -84,7 +85,8 @@ public class EmbeddedChannelTest {
assertFalse(channel.finish());
}
@Test(timeout = 2000)
@Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void promiseDoesNotInfiniteLoop() throws InterruptedException {
EmbeddedChannel channel = new EmbeddedChannel();
channel.closeFuture().addListener((ChannelFutureListener) future -> future.channel().close());
@ -143,7 +145,8 @@ public class EmbeddedChannelTest {
assertTrue(future.isCancelled());
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testHandlerAddedExecutedInEventLoop() throws Throwable {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> error = new AtomicReference<>();
@ -188,13 +191,15 @@ public class EmbeddedChannelTest {
}
// See https://github.com/netty/netty/issues/4316.
@Test(timeout = 2000)
@Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testFireChannelInactiveAndUnregisteredOnClose() throws InterruptedException {
testFireChannelInactiveAndUnregistered(ChannelOutboundInvoker::close);
testFireChannelInactiveAndUnregistered(channel -> channel.close(channel.newPromise()));
}
@Test(timeout = 2000)
@Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testFireChannelInactiveAndUnregisteredOnDisconnect() throws InterruptedException {
testFireChannelInactiveAndUnregistered(ChannelOutboundInvoker::disconnect);
@ -532,7 +537,8 @@ public class EmbeddedChannelTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testChannelInactiveFired() throws InterruptedException {
final AtomicBoolean inactive = new AtomicBoolean();
EmbeddedChannel channel = new EmbeddedChannel(new ChannelHandler() {

View File

@ -24,7 +24,7 @@ import io.netty.channel.MultithreadEventLoopGroup;
import io.netty.channel.nio.NioHandler;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class DefaultChannelGroupTest {

View File

@ -40,9 +40,10 @@ import io.netty.util.concurrent.Promise;
import io.netty.util.concurrent.RejectedExecutionHandler;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.net.ConnectException;
import java.nio.channels.ClosedChannelException;
@ -56,11 +57,12 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class LocalChannelTest {
@ -72,14 +74,14 @@ public class LocalChannelTest {
private static EventLoopGroup group2;
private static EventLoopGroup sharedGroup;
@BeforeClass
@BeforeAll
public static void beforeClass() {
group1 = new MultithreadEventLoopGroup(2, LocalHandler.newFactory());
group2 = new MultithreadEventLoopGroup(2, LocalHandler.newFactory());
sharedGroup = new MultithreadEventLoopGroup(1, LocalHandler.newFactory());
}
@AfterClass
@AfterAll
public static void afterClass() throws InterruptedException {
Future<?> group1Future = group1.shutdownGracefully(0, 0, SECONDS);
Future<?> group2Future = group2.shutdownGracefully(0, 0, SECONDS);
@ -130,9 +132,9 @@ public class LocalChannelTest {
closeChannel(sc);
sc.closeFuture().sync();
assertNull(String.format(
assertNull(LocalChannelRegistry.get(TEST_ADDRESS), String.format(
"Expected null, got channel '%s' for local address '%s'",
LocalChannelRegistry.get(TEST_ADDRESS), TEST_ADDRESS), LocalChannelRegistry.get(TEST_ADDRESS));
LocalChannelRegistry.get(TEST_ADDRESS), TEST_ADDRESS));
} finally {
closeChannel(cc);
closeChannel(sc);
@ -284,7 +286,7 @@ public class LocalChannelTest {
}
});
ChannelFuture future = bootstrap.connect(sc.localAddress());
assertTrue("Connection should finish, not time out", future.await(2000));
assertTrue(future.await(2000), "Connection should finish, not time out");
cc = future.channel();
} finally {
closeChannel(cc);
@ -764,7 +766,8 @@ public class LocalChannelTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testConnectFutureBeforeChannelActive() throws Exception {
Bootstrap cb = new Bootstrap();
ServerBootstrap sb = new ServerBootstrap();
@ -815,14 +818,14 @@ public class LocalChannelTest {
}
}
@Test(expected = ConnectException.class)
@Test
public void testConnectionRefused() throws Throwable {
try {
Bootstrap sb = new Bootstrap();
sb.group(group1)
assertTrue(assertThrows(CompletionException.class, () -> sb.group(group1)
.channel(LocalChannel.class)
.handler(new TestHandler())
.connect(LocalAddress.ANY).syncUninterruptibly();
.connect(LocalAddress.ANY).syncUninterruptibly()).getCause() instanceof ConnectException);
} catch (CompletionException e) {
throw e.getCause();
}
@ -922,12 +925,14 @@ public class LocalChannelTest {
});
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testAutoReadDisabledSharedGroup() throws Exception {
testAutoReadDisabled(sharedGroup, sharedGroup);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testAutoReadDisabledDifferentGroup() throws Exception {
testAutoReadDisabled(group1, group2);
}
@ -985,22 +990,26 @@ public class LocalChannelTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testMaxMessagesPerReadRespectedWithAutoReadSharedGroup() throws Exception {
testMaxMessagesPerReadRespected(sharedGroup, sharedGroup, true);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testMaxMessagesPerReadRespectedWithoutAutoReadSharedGroup() throws Exception {
testMaxMessagesPerReadRespected(sharedGroup, sharedGroup, false);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testMaxMessagesPerReadRespectedWithAutoReadDifferentGroup() throws Exception {
testMaxMessagesPerReadRespected(group1, group2, true);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testMaxMessagesPerReadRespectedWithoutAutoReadDifferentGroup() throws Exception {
testMaxMessagesPerReadRespected(group1, group2, false);
}
@ -1042,22 +1051,26 @@ public class LocalChannelTest {
}
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testServerMaxMessagesPerReadRespectedWithAutoReadSharedGroup() throws Exception {
testServerMaxMessagesPerReadRespected(sharedGroup, sharedGroup, true);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testServerMaxMessagesPerReadRespectedWithoutAutoReadSharedGroup() throws Exception {
testServerMaxMessagesPerReadRespected(sharedGroup, sharedGroup, false);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testServerMaxMessagesPerReadRespectedWithAutoReadDifferentGroup() throws Exception {
testServerMaxMessagesPerReadRespected(group1, group2, true);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testServerMaxMessagesPerReadRespectedWithoutAutoReadDifferentGroup() throws Exception {
testServerMaxMessagesPerReadRespected(group1, group2, false);
}

View File

@ -24,11 +24,13 @@ import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.MultithreadEventLoopGroup;
import io.netty.util.ReferenceCountUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class LocalTransportThreadModelTest2 {
@ -36,7 +38,8 @@ public class LocalTransportThreadModelTest2 {
static final int messageCountPerRun = 4;
@Test(timeout = 15000)
@Test
@Timeout(value = 15000, unit = TimeUnit.MILLISECONDS)
public void testSocketReuse() throws InterruptedException {
ServerBootstrap serverBootstrap = new ServerBootstrap();
LocalHandler serverHandler = new LocalHandler("SERVER");

View File

@ -28,7 +28,8 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.IntSupplier;
import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.Future;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -43,7 +44,10 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class NioEventLoopTest extends AbstractEventLoopTest {
@ -128,7 +132,8 @@ public class NioEventLoopTest extends AbstractEventLoopTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testSelectableChannel() throws Exception {
final NioHandler nioHandler = (NioHandler) NioHandler.newFactory().newHandler();
EventLoop loop = new SingleThreadEventLoop(new DefaultThreadFactory("ioPool"), nioHandler);

View File

@ -15,8 +15,8 @@
*/
package io.netty.channel.nio;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@ -24,7 +24,12 @@ import java.nio.channels.SelectionKey;
import java.util.Iterator;
import java.util.NoSuchElementException;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class SelectedSelectionKeySetTest {
@Mock
@ -35,7 +40,7 @@ public class SelectedSelectionKeySetTest {
@Mock
private SelectionKey mockKey3;
@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}

View File

@ -16,7 +16,7 @@
package io.netty.channel.socket;
import io.netty.util.NetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.net.InetAddress;

View File

@ -24,7 +24,7 @@ import io.netty.channel.nio.NioHandler;
import io.netty.util.concurrent.AbstractEventExecutor;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.ScheduledFuture;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.SocketOption;
@ -33,7 +33,11 @@ import java.nio.channels.NetworkChannel;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
public abstract class AbstractNioChannelTest<T extends AbstractNioChannel> {

View File

@ -26,14 +26,14 @@ import io.netty.channel.nio.NioHandler;
import io.netty.channel.socket.DatagramChannel;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.channels.NetworkChannel;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class NioDatagramChannelTest extends AbstractNioChannelTest<NioDatagramChannel> {
@ -60,7 +60,7 @@ public class NioDatagramChannelTest extends AbstractNioChannelTest<NioDatagramCh
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
channelGroup.add(datagramChannel);
}
Assert.assertEquals(100, channelGroup.size());
assertEquals(100, channelGroup.size());
} finally {
channelGroup.close().sync();
group.shutdownGracefully().sync();

View File

@ -19,8 +19,7 @@ import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.MultithreadEventLoopGroup;
import io.netty.channel.nio.NioHandler;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -29,6 +28,9 @@ import java.net.StandardSocketOptions;
import java.nio.channels.NetworkChannel;
import java.nio.channels.ServerSocketChannel;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class NioServerSocketChannelTest extends AbstractNioChannelTest<NioServerSocketChannel> {
@Test
@ -40,8 +42,8 @@ public class NioServerSocketChannelTest extends AbstractNioChannelTest<NioServer
try {
serverSocketChannel.register().syncUninterruptibly();
serverSocketChannel.bind(new InetSocketAddress(0)).syncUninterruptibly();
Assert.assertFalse(serverSocketChannel.closeOnReadError(new IOException()));
Assert.assertTrue(serverSocketChannel.closeOnReadError(new IllegalArgumentException()));
assertFalse(serverSocketChannel.closeOnReadError(new IOException()));
assertTrue(serverSocketChannel.closeOnReadError(new IllegalArgumentException()));
serverSocketChannel.close().syncUninterruptibly();
} finally {
group.shutdownGracefully();
@ -55,11 +57,11 @@ public class NioServerSocketChannelTest extends AbstractNioChannelTest<NioServer
try {
serverSocketChannel.register().syncUninterruptibly();
Channel channel = serverSocketChannel.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
Assert.assertTrue(channel.isActive());
Assert.assertTrue(channel.isOpen());
assertTrue(channel.isActive());
assertTrue(channel.isOpen());
channel.close().syncUninterruptibly();
Assert.assertFalse(channel.isOpen());
Assert.assertFalse(channel.isActive());
assertFalse(channel.isOpen());
assertFalse(channel.isActive());
} finally {
group.shutdownGracefully();
}

View File

@ -35,7 +35,8 @@ import io.netty.channel.nio.NioHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.io.DataInput;
import java.io.DataInputStream;
@ -53,10 +54,10 @@ import java.util.Queue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
public class NioSocketChannelTest extends AbstractNioChannelTest<NioSocketChannel> {
@ -158,7 +159,8 @@ public class NioSocketChannelTest extends AbstractNioChannelTest<NioSocketChanne
}
// Test for https://github.com/netty/netty/issues/4805
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testChannelReRegisterReadSameEventLoop() throws Exception {
final EventLoopGroup group = new MultithreadEventLoopGroup(2, NioHandler.newFactory());
final CountDownLatch latch = new CountDownLatch(1);
@ -223,7 +225,8 @@ public class NioSocketChannelTest extends AbstractNioChannelTest<NioSocketChanne
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testShutdownOutputAndClose() throws IOException {
EventLoopGroup group = new MultithreadEventLoopGroup(1, NioHandler.newFactory());
ServerSocket socket = new ServerSocket();