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 Norman Maurer
parent 22faf32c25
commit bfd2c5ac8a
37 changed files with 648 additions and 404 deletions

View File

@ -43,8 +43,10 @@ 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 org.junit.jupiter.api.function.Executable;
import java.net.ConnectException;
import java.net.SocketAddress;
@ -58,10 +60,19 @@ import java.util.UUID;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
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.hamcrest.Matchers.sameInstance;
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 {
@ -69,7 +80,7 @@ public class BootstrapTest {
private static final EventLoopGroup groupB = new DefaultEventLoopGroup(1);
private static final ChannelInboundHandler dummyHandler = new DummyHandler();
@AfterClass
@AfterAll
public static void destroy() {
groupA.shutdownGracefully();
groupB.shutdownGracefully();
@ -118,7 +129,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);
@ -154,7 +166,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);
@ -267,7 +280,8 @@ public class BootstrapTest {
}
}
@Test(expected = ConnectException.class, timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testLateRegistrationConnect() throws Exception {
EventLoopGroup group = new DelayedEventLoopGroup();
try {
@ -275,7 +289,12 @@ public class BootstrapTest {
bootstrapA.group(group);
bootstrapA.channel(LocalChannel.class);
bootstrapA.handler(dummyHandler);
bootstrapA.connect(LocalAddress.ANY).syncUninterruptibly();
assertThrows(ConnectException.class, new Executable() {
@Override
public void execute() {
bootstrapA.connect(LocalAddress.ANY).syncUninterruptibly();
}
});
} finally {
group.shutdownGracefully();
}

View File

@ -29,20 +29,23 @@ import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalEventLoopGroup;
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<Throwable>();
@ -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,11 +21,12 @@ 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 org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
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 {
@ -53,9 +54,9 @@ public class AbstractChannelTest {
// This allows us to have a single-threaded test
when(eventLoop.inEventLoop()).thenReturn(true);
doAnswer(new Answer() {
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
public Object answer(InvocationOnMock invocationOnMock) {
((Runnable) invocationOnMock.getArgument(0)).run();
return null;
}

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

@ -22,11 +22,12 @@ import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.EventExecutorGroup;
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 {
@ -43,11 +44,11 @@ public abstract class AbstractEventLoopTest {
ChannelFuture future = bootstrap.channel(newChannel()).group(group)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
public void initChannel(SocketChannel ch) {
}
}).handler(new ChannelInitializer<ServerSocketChannel>() {
@Override
public void initChannel(ServerSocketChannel ch) throws Exception {
public void initChannel(ServerSocketChannel ch) {
ch.pipeline().addLast(new TestChannelHandler());
ch.pipeline().addLast(eventExecutorGroup, new TestChannelHandler2());
}
@ -63,7 +64,8 @@ public abstract class AbstractEventLoopTest {
assertSame(executor, future.channel().pipeline().context(TestChannelHandler2.class).executor());
}
@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;
@ -23,7 +22,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalServerChannel;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
class BaseChannelTest {

View File

@ -23,9 +23,10 @@ import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalServerChannel;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.Future;
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.util.Iterator;
import java.util.Map;
@ -37,11 +38,12 @@ 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.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
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;
@ -51,7 +53,7 @@ public class ChannelInitializerTest {
private Bootstrap client;
private InspectableHandler testHandler;
@Before
@BeforeEach
public void setUp() {
group = new DefaultEventLoopGroup(1);
server = new ServerBootstrap()
@ -65,7 +67,7 @@ public class ChannelInitializerTest {
testHandler = new InspectableHandler();
}
@After
@AfterEach
public void tearDown() {
group.shutdownGracefully(0, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).syncUninterruptibly();
}
@ -120,11 +122,11 @@ public class ChannelInitializerTest {
client.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
ch.pipeline().addLast(handler1);
ch.pipeline().addLast(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
ch.pipeline().addLast(handler2);
ch.pipeline().addLast(handler3);
}
@ -159,14 +161,14 @@ public class ChannelInitializerTest {
final AtomicInteger registeredCalled = new AtomicInteger(0);
final ChannelInboundHandlerAdapter handler1 = new ChannelInboundHandlerAdapter() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
public void channelRegistered(ChannelHandlerContext ctx) {
registeredCalled.incrementAndGet();
}
};
final AtomicInteger initChannelCalled = new AtomicInteger(0);
client.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
initChannelCalled.incrementAndGet();
ch.pipeline().addLast(handler1);
ch.pipeline().fireChannelRegistered();
@ -190,7 +192,8 @@ public class ChannelInitializerTest {
}
}
@Test(timeout = TIMEOUT_MILLIS)
@Test
@Timeout(value = TIMEOUT_MILLIS, unit = TimeUnit.MILLISECONDS)
public void firstHandlerInPipelineShouldReceiveChannelRegisteredEvent() {
testChannelRegisteredEventPropagation(new ChannelInitializer<LocalChannel>() {
@Override
@ -200,7 +203,8 @@ public class ChannelInitializerTest {
});
}
@Test(timeout = TIMEOUT_MILLIS)
@Test
@Timeout(value = TIMEOUT_MILLIS, unit = TimeUnit.MILLISECONDS)
public void lastHandlerInPipelineShouldReceiveChannelRegisteredEvent() {
testChannelRegisteredEventPropagation(new ChannelInitializer<LocalChannel>() {
@Override
@ -224,10 +228,10 @@ public class ChannelInitializerTest {
final AtomicBoolean called = new AtomicBoolean();
EmbeddedChannel channel = new EmbeddedChannel(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
ChannelHandler handler = new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
called.set(true);
}
};
@ -256,7 +260,8 @@ public class ChannelInitializerTest {
}
@SuppressWarnings("deprecation")
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testChannelInitializerEventExecutor() throws Throwable {
final AtomicInteger invokeCount = new AtomicInteger();
final AtomicInteger completeCount = new AtomicInteger();

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

@ -22,18 +22,23 @@ import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.RejectedExecutionHandlers;
import io.netty.util.concurrent.SingleThreadEventExecutor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.util.Queue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
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 {
@ -61,11 +66,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);
@ -86,7 +91,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());
@ -110,7 +115,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());
@ -138,11 +143,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()));
}
@ -187,27 +192,27 @@ public class ChannelOutboundBufferTest {
}
@Override
protected void doBind(SocketAddress localAddress) throws Exception {
protected void doBind(SocketAddress localAddress) {
throw new UnsupportedOperationException();
}
@Override
protected void doDisconnect() throws Exception {
protected void doDisconnect() {
throw new UnsupportedOperationException();
}
@Override
protected void doClose() throws Exception {
protected void doClose() {
throw new UnsupportedOperationException();
}
@Override
protected void doBeginRead() throws Exception {
protected void doBeginRead() {
throw new UnsupportedOperationException();
}
@Override
protected void doWrite(ChannelOutboundBuffer in) throws Exception {
protected void doWrite(ChannelOutboundBuffer in) {
throw new UnsupportedOperationException();
}
@ -244,7 +249,7 @@ public class ChannelOutboundBufferTest {
final StringBuilder buf = new StringBuilder();
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
public void channelWritabilityChanged(ChannelHandlerContext ctx) {
buf.append(ctx.channel().isWritable());
buf.append(' ');
}
@ -279,7 +284,7 @@ public class ChannelOutboundBufferTest {
final StringBuilder buf = new StringBuilder();
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
public void channelWritabilityChanged(ChannelHandlerContext ctx) {
buf.append(ctx.channel().isWritable());
buf.append(' ');
}
@ -313,7 +318,7 @@ public class ChannelOutboundBufferTest {
final StringBuilder buf = new StringBuilder();
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
public void channelWritabilityChanged(ChannelHandlerContext ctx) {
buf.append(ctx.channel().isWritable());
buf.append(' ');
}
@ -353,7 +358,7 @@ public class ChannelOutboundBufferTest {
final StringBuilder buf = new StringBuilder();
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
public void channelWritabilityChanged(ChannelHandlerContext ctx) {
buf.append(ctx.channel().isWritable());
buf.append(' ');
}
@ -387,7 +392,8 @@ public class ChannelOutboundBufferTest {
safeClose(ch);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testWriteTaskRejected() throws Exception {
final SingleThreadEventExecutor executor = new SingleThreadEventExecutor(
null, new DefaultThreadFactory("executorPool"),
@ -413,7 +419,7 @@ public class ChannelOutboundBufferTest {
EmbeddedChannel ch = new EmbeddedChannel();
ch.pipeline().addLast(executor, "handler", new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
promise.setFailure(new AssertionError("Should not be called"));
}

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;
@ -67,7 +67,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,21 @@
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 org.junit.jupiter.api.function.Executable;
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,39 +60,64 @@ public class CombinedChannelDuplexHandlerTest {
DISCONNECT
}
@Test(expected = IllegalStateException.class)
@Test
public void testInboundRemoveBeforeAdded() {
CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler> handler =
final CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler> handler =
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>(
new ChannelInboundHandlerAdapter(), new ChannelOutboundHandlerAdapter());
handler.removeInboundHandler();
assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() {
handler.removeInboundHandler();
}
});
}
@Test(expected = IllegalStateException.class)
@Test
public void testOutboundRemoveBeforeAdded() {
CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler> handler =
final CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler> handler =
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>(
new ChannelInboundHandlerAdapter(), new ChannelOutboundHandlerAdapter());
handler.removeOutboundHandler();
assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() {
handler.removeOutboundHandler();
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testInboundHandlerImplementsOutboundHandler() {
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>(
new ChannelDuplexHandler(), new ChannelOutboundHandlerAdapter());
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>(
new ChannelDuplexHandler(), new ChannelOutboundHandlerAdapter());
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testOutboundHandlerImplementsInboundHandler() {
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>(
new ChannelInboundHandlerAdapter(), new ChannelDuplexHandler());
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>(
new ChannelInboundHandlerAdapter(), new ChannelDuplexHandler());
}
});
}
@Test(expected = IllegalStateException.class)
public void testInitNotCalledBeforeAdded() throws Exception {
CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler> handler =
@Test
public void testInitNotCalledBeforeAdded() {
final CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler> handler =
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>() { };
handler.handlerAdded(null);
assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() throws Throwable {
handler.handlerAdded(null);
}
});
}
@Test
@ -95,15 +127,16 @@ public class CombinedChannelDuplexHandlerTest {
ChannelInboundHandler inboundHandler = new ChannelInboundHandlerAdapter() {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
assertSame(exception, cause);
queue.add(this);
ctx.fireExceptionCaught(cause);
}
};
ChannelOutboundHandler outboundHandler = new ChannelOutboundHandlerAdapter() {
@SuppressWarnings("deprecation")
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
assertSame(exception, cause);
queue.add(this);
ctx.fireExceptionCaught(cause);
@ -111,7 +144,7 @@ public class CombinedChannelDuplexHandlerTest {
};
ChannelInboundHandler lastHandler = new ChannelInboundHandlerAdapter() {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
assertSame(exception, cause);
queue.add(this);
}
@ -133,57 +166,57 @@ public class CombinedChannelDuplexHandlerTest {
ChannelInboundHandler inboundHandler = new ChannelInboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
public void handlerAdded(ChannelHandlerContext ctx) {
queue.add(Event.HANDLER_ADDED);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
public void handlerRemoved(ChannelHandlerContext ctx) {
queue.add(Event.HANDLER_REMOVED);
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
public void channelRegistered(ChannelHandlerContext ctx) {
queue.add(Event.REGISTERED);
}
@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
public void channelUnregistered(ChannelHandlerContext ctx) {
queue.add(Event.UNREGISTERED);
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
public void channelActive(ChannelHandlerContext ctx) {
queue.add(Event.ACTIVE);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
public void channelInactive(ChannelHandlerContext ctx) {
queue.add(Event.INACTIVE);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
public void channelRead(ChannelHandlerContext ctx, Object msg) {
queue.add(Event.CHANNEL_READ);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
public void channelReadComplete(ChannelHandlerContext ctx) {
queue.add(Event.CHANNEL_READ_COMPLETE);
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
queue.add(Event.USER_EVENT_TRIGGERED);
}
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
public void channelWritabilityChanged(ChannelHandlerContext ctx) {
queue.add(Event.CHANNEL_WRITABILITY_CHANGED);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
queue.add(Event.EXCEPTION_CAUGHT);
}
};
@ -228,54 +261,53 @@ public class CombinedChannelDuplexHandlerTest {
ChannelInboundHandler inboundHandler = new ChannelInboundHandlerAdapter();
ChannelOutboundHandler outboundHandler = new ChannelOutboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
public void handlerAdded(ChannelHandlerContext ctx) {
queue.add(Event.HANDLER_ADDED);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
public void handlerRemoved(ChannelHandlerContext ctx) {
queue.add(Event.HANDLER_REMOVED);
}
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
throws Exception {
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) {
queue.add(Event.BIND);
}
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
SocketAddress localAddress, ChannelPromise promise) throws Exception {
SocketAddress localAddress, ChannelPromise promise) {
queue.add(Event.CONNECT);
}
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
queue.add(Event.DISCONNECT);
}
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
public void close(ChannelHandlerContext ctx, ChannelPromise promise) {
queue.add(Event.CLOSE);
}
@Override
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) {
queue.add(Event.DEREGISTER);
}
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
public void read(ChannelHandlerContext ctx) {
queue.add(Event.READ);
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
queue.add(Event.WRITE);
}
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
public void flush(ChannelHandlerContext ctx) {
queue.add(Event.FLUSH);
}
};
@ -322,38 +354,39 @@ public class CombinedChannelDuplexHandlerTest {
channel.pipeline().deregister();
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testPromisesPassed() {
ChannelOutboundHandler outboundHandler = new ChannelOutboundHandlerAdapter() {
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
ChannelPromise promise) throws Exception {
ChannelPromise promise) {
promise.setSuccess();
}
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
SocketAddress localAddress, ChannelPromise promise) throws Exception {
SocketAddress localAddress, ChannelPromise promise) {
promise.setSuccess();
}
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
promise.setSuccess();
}
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
public void close(ChannelHandlerContext ctx, ChannelPromise promise) {
promise.setSuccess();
}
@Override
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) {
promise.setSuccess();
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
promise.setSuccess();
}
};
@ -388,13 +421,18 @@ public class CombinedChannelDuplexHandlerTest {
ch.finish();
}
@Test(expected = IllegalStateException.class)
@Test
public void testNotSharable() {
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>() {
assertThrows(IllegalStateException.class, new Executable() {
@Override
public boolean isSharable() {
return true;
public void execute() {
new CombinedChannelDuplexHandler<ChannelInboundHandler, ChannelOutboundHandler>() {
@Override
public boolean isSharable() {
return true;
}
};
}
};
});
}
}

View File

@ -15,22 +15,30 @@
*/
package io.netty.channel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
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 Executable() {
@Override
public void execute() {
new CompleteChannelFutureImpl(null);
}
});
}
@Test
public void shouldNotDoAnythingOnRemove() throws Exception {
public void shouldNotDoAnythingOnRemove() {
Channel channel = Mockito.mock(Channel.class);
CompleteChannelFuture future = new CompleteChannelFutureImpl(channel);
ChannelFutureListener l = Mockito.mock(ChannelFutureListener.class);

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.InetSocketAddress;
@ -25,9 +25,9 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
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 io.netty.bootstrap.Bootstrap;
@ -35,12 +35,12 @@ public class DefaultChannelPipelineTailTest {
private static EventLoopGroup GROUP;
@BeforeClass
@BeforeAll
public static void init() {
GROUP = new DefaultEventLoopGroup(1);
}
@AfterClass
@AfterAll
public static void destroy() {
GROUP.shutdownGracefully();
}
@ -305,20 +305,20 @@ public class DefaultChannelPipelineTailTest {
}
@Override
protected void doBind(SocketAddress localAddress) throws Exception {
protected void doBind(SocketAddress localAddress) {
}
@Override
protected void doDisconnect() throws Exception {
protected void doDisconnect() {
}
@Override
protected void doClose() throws Exception {
protected void doClose() {
closed = true;
}
@Override
protected void doBeginRead() throws Exception {
protected void doBeginRead() {
}
@Override

View File

@ -41,10 +41,12 @@ import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise;
import io.netty.util.concurrent.UnorderedThreadPoolEventExecutor;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.function.Executable;
import java.net.SocketAddress;
import java.util.ArrayDeque;
@ -64,14 +66,15 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
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.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
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.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
public class DefaultChannelPipelineTest {
@ -80,12 +83,12 @@ public class DefaultChannelPipelineTest {
private Channel self;
private Channel peer;
@BeforeClass
@BeforeAll
public static void beforeClass() throws Exception {
group = new DefaultEventLoopGroup(1);
}
@AfterClass
@AfterAll
public static void afterClass() throws Exception {
group.shutdownGracefully().sync();
}
@ -96,12 +99,12 @@ public class DefaultChannelPipelineTest {
sb.group(group).channel(LocalServerChannel.class);
sb.childHandler(new ChannelInboundHandlerAdapter() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
public void channelRegistered(ChannelHandlerContext ctx) {
peerRef.set(ctx.channel());
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ReferenceCountUtil.release(msg);
}
});
@ -112,7 +115,7 @@ public class DefaultChannelPipelineTest {
b.group(group).channel(LocalChannel.class);
b.handler(new ChannelInitializer<LocalChannel>() {
@Override
protected void initChannel(LocalChannel ch) throws Exception {
protected void initChannel(LocalChannel ch) {
ch.pipeline().addLast(handlers);
}
});
@ -123,7 +126,7 @@ public class DefaultChannelPipelineTest {
bindFuture.channel().close().sync();
}
@After
@AfterEach
public void tearDown() throws Exception {
if (peer != null) {
peer.close();
@ -230,14 +233,19 @@ public class DefaultChannelPipelineTest {
assertNotNull(pipeline.get("handler1"));
}
@Test(expected = NoSuchElementException.class)
@Test
public void testRemoveThrowNoSuchElementException() {
DefaultChannelPipeline pipeline = new DefaultChannelPipeline(new LocalChannel());
final DefaultChannelPipeline pipeline = new DefaultChannelPipeline(new LocalChannel());
ChannelHandler handler1 = newHandler();
pipeline.addLast("handler1", handler1);
pipeline.remove("handlerXXX");
assertThrows(NoSuchElementException.class, new Executable() {
@Override
public void execute() {
pipeline.remove("handlerXXX");
}
});
}
@Test
@ -265,17 +273,22 @@ public class DefaultChannelPipelineTest {
assertSame(pipeline.get("handler2"), newHandler2);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testReplaceHandlerChecksDuplicateNames() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
final ChannelPipeline pipeline = new LocalChannel().pipeline();
ChannelHandler handler1 = newHandler();
ChannelHandler handler2 = newHandler();
pipeline.addLast("handler1", handler1);
pipeline.addLast("handler2", handler2);
ChannelHandler newHandler1 = newHandler();
pipeline.replace("handler1", "handler2", newHandler1);
final ChannelHandler newHandler1 = newHandler();
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
pipeline.replace("handler1", "handler2", newHandler1);
}
});
}
@Test
@ -334,7 +347,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();
@ -372,7 +386,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();
@ -421,10 +436,10 @@ public class DefaultChannelPipelineTest {
ChannelPipeline pipeline = new LocalChannel().pipeline();
pipeline.addLast(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
public void channelRegistered(ChannelHandlerContext ctx) {
latch.countDown();
}
});
@ -493,7 +508,8 @@ public class DefaultChannelPipelineTest {
verifyContextNumber(pipeline, 8);
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testLifeCycleAwareness() throws Exception {
setUp();
@ -542,7 +558,8 @@ public class DefaultChannelPipelineTest {
removeLatch.await();
}
@Test(timeout = 100000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testRemoveAndForwardInbound() throws Exception {
final BufferedTestHandler handler1 = new BufferedTestHandler();
final BufferedTestHandler handler2 = new BufferedTestHandler();
@ -563,7 +580,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();
@ -584,7 +602,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();
@ -604,7 +623,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();
@ -630,7 +650,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();
@ -660,7 +681,7 @@ public class DefaultChannelPipelineTest {
// Tests for https://github.com/netty/netty/issues/2349
@Test
public void testCancelBind() throws Exception {
public void testCancelBind() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
@ -671,7 +692,7 @@ public class DefaultChannelPipelineTest {
}
@Test
public void testCancelConnect() throws Exception {
public void testCancelConnect() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
@ -682,7 +703,7 @@ public class DefaultChannelPipelineTest {
}
@Test
public void testCancelDisconnect() throws Exception {
public void testCancelDisconnect() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
@ -693,7 +714,7 @@ public class DefaultChannelPipelineTest {
}
@Test
public void testCancelClose() throws Exception {
public void testCancelClose() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
@ -703,51 +724,66 @@ public class DefaultChannelPipelineTest {
assertTrue(future.isCancelled());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testWrongPromiseChannel() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
final ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel()).sync();
ChannelPipeline pipeline2 = new LocalChannel().pipeline();
group.register(pipeline2.channel()).sync();
try {
ChannelPromise promise2 = pipeline2.channel().newPromise();
pipeline.close(promise2);
final ChannelPromise promise2 = pipeline2.channel().newPromise();
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
pipeline.close(promise2);
}
});
} finally {
pipeline.close();
pipeline2.close();
}
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testUnexpectedVoidChannelPromise() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
final ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel()).sync();
try {
ChannelPromise promise = new VoidChannelPromise(pipeline.channel(), false);
pipeline.close(promise);
} finally {
pipeline.close();
}
}
@Test(expected = IllegalArgumentException.class)
public void testUnexpectedVoidChannelPromiseCloseFuture() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel()).sync();
try {
ChannelPromise promise = (ChannelPromise) pipeline.channel().closeFuture();
pipeline.close(promise);
final ChannelPromise promise = new VoidChannelPromise(pipeline.channel(), false);
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
pipeline.close(promise);
}
});
} finally {
pipeline.close();
}
}
@Test
public void testCancelDeregister() throws Exception {
public void testUnexpectedVoidChannelPromiseCloseFuture() throws Exception {
final ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel()).sync();
try {
final ChannelPromise promise = (ChannelPromise) pipeline.channel().closeFuture();
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
pipeline.close(promise);
}
});
} finally {
pipeline.close();
}
}
@Test
public void testCancelDeregister() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
@ -758,7 +794,7 @@ public class DefaultChannelPipelineTest {
}
@Test
public void testCancelWrite() throws Exception {
public void testCancelWrite() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
@ -772,7 +808,7 @@ public class DefaultChannelPipelineTest {
}
@Test
public void testCancelWriteAndFlush() throws Exception {
public void testCancelWriteAndFlush() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
group.register(pipeline.channel());
@ -786,37 +822,38 @@ public class DefaultChannelPipelineTest {
}
@Test
public void testFirstContextEmptyPipeline() throws Exception {
public void testFirstContextEmptyPipeline() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
assertNull(pipeline.firstContext());
}
@Test
public void testLastContextEmptyPipeline() throws Exception {
public void testLastContextEmptyPipeline() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
assertNull(pipeline.lastContext());
}
@Test
public void testFirstHandlerEmptyPipeline() throws Exception {
public void testFirstHandlerEmptyPipeline() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
assertNull(pipeline.first());
}
@Test
public void testLastHandlerEmptyPipeline() throws Exception {
public void testLastHandlerEmptyPipeline() {
ChannelPipeline pipeline = new LocalChannel().pipeline();
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<Throwable>();
final CountDownLatch latch = new CountDownLatch(1);
EmbeddedChannel channel = new EmbeddedChannel(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
throw exception;
}
@ -839,17 +876,17 @@ public class DefaultChannelPipelineTest {
ChannelPipeline pipeline = new LocalChannel().pipeline();
pipeline.addLast(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
protected void initChannel(Channel ch) {
ch.pipeline().addLast(new WrapperExecutor(),
new ChannelInboundHandlerAdapter() {
@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
public void channelUnregistered(ChannelHandlerContext ctx) {
channelLatch.countDown();
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
public void handlerRemoved(ChannelHandlerContext ctx) {
handlerLatch.countDown();
}
});
@ -863,7 +900,8 @@ public class DefaultChannelPipelineTest {
assertTrue(handlerLatch.await(2, TimeUnit.SECONDS));
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddHandlerBeforeRegisteredThenRemove() {
final EventLoop loop = group.next();
@ -877,7 +915,8 @@ public class DefaultChannelPipelineTest {
handler.removedPromise.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);
@ -890,7 +929,7 @@ public class DefaultChannelPipelineTest {
handler.addedPromise.syncUninterruptibly();
pipeline.replace(handler, null, new ChannelHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
public void handlerAdded(ChannelHandlerContext ctx) {
latch.countDown();
}
});
@ -926,7 +965,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testHandlerAddedAndRemovedCalledInCorrectOrder() throws Throwable {
final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1);
final EventExecutorGroup group2 = new DefaultEventExecutorGroup(1);
@ -969,7 +1009,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testHandlerAddedExceptionFromChildHandlerIsPropagated() {
final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1);
try {
@ -993,7 +1034,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testHandlerRemovedExceptionFromChildHandlerIsPropagated() {
final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1);
try {
@ -1016,7 +1058,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testHandlerAddedThrowsAndRemovedThrowsException() throws InterruptedException {
final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1);
try {
@ -1054,7 +1097,8 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 2000)
@Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testAddRemoveHandlerCalledOnceRegistered() throws Throwable {
ChannelPipeline pipeline = new LocalChannel().pipeline();
CallbackCheckHandler handler = new CallbackCheckHandler();
@ -1075,7 +1119,8 @@ public class DefaultChannelPipelineTest {
assertTrue(handler.removedHandler.get());
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddReplaceHandlerCalledOnceRegistered() throws Throwable {
ChannelPipeline pipeline = new LocalChannel().pipeline();
CallbackCheckHandler handler = new CallbackCheckHandler();
@ -1109,7 +1154,8 @@ public class DefaultChannelPipelineTest {
assertTrue(handler2.removedHandler.get());
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddBefore() throws Throwable {
ChannelPipeline pipeline1 = new LocalChannel().pipeline();
ChannelPipeline pipeline2 = new LocalChannel().pipeline();
@ -1133,44 +1179,48 @@ public class DefaultChannelPipelineTest {
}
}
@Test(timeout = 3000)
public void testAddInListenerNio() throws Throwable {
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddInListenerNio() {
testAddInListener(new NioSocketChannel(), new NioEventLoopGroup(1));
}
@Test(timeout = 3000)
public void testAddInListenerOio() throws Throwable {
@SuppressWarnings("deprecation")
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddInListenerOio() {
testAddInListener(new OioSocketChannel(), new OioEventLoopGroup(1));
}
@Test(timeout = 3000)
public void testAddInListenerLocal() throws Throwable {
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testAddInListenerLocal() {
testAddInListener(new LocalChannel(), new DefaultEventLoopGroup(1));
}
private static void testAddInListener(Channel channel, EventLoopGroup group) throws Throwable {
private static void testAddInListener(Channel channel, EventLoopGroup group) {
ChannelPipeline pipeline1 = channel.pipeline();
try {
final Object event = new Object();
final Promise<Object> promise = ImmediateEventExecutor.INSTANCE.newPromise();
group.register(pipeline1.channel()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
ChannelPipeline pipeline = future.channel().pipeline();
final AtomicBoolean handlerAddedCalled = new AtomicBoolean();
pipeline.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
public void handlerAdded(ChannelHandlerContext ctx) {
handlerAddedCalled.set(true);
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
promise.setSuccess(event);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
promise.setFailure(cause);
}
});
@ -1203,7 +1253,8 @@ public class DefaultChannelPipelineTest {
pipeline.addBefore("test", null, newHandler());
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testUnorderedEventExecutor() throws Throwable {
ChannelPipeline pipeline1 = new LocalChannel().pipeline();
EventExecutorGroup eventExecutors = new UnorderedThreadPoolEventExecutor(2);
@ -1214,13 +1265,13 @@ public class DefaultChannelPipelineTest {
final CountDownLatch latch = new CountDownLatch(1);
pipeline1.addLast(eventExecutors, new ChannelInboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
public void handlerAdded(ChannelHandlerContext ctx) {
// Just block one of the two threads.
LockSupport.park();
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
latch.countDown();
}
});
@ -1272,8 +1323,9 @@ public class DefaultChannelPipelineTest {
group.shutdownGracefully(0, 0, TimeUnit.SECONDS);
}
@Test(timeout = 3000)
public void testVoidPromiseNotify() throws Throwable {
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testVoidPromiseNotify() {
ChannelPipeline pipeline1 = new LocalChannel().pipeline();
EventLoopGroup defaultGroup = new DefaultEventLoopGroup(1);
@ -1604,7 +1656,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");
}
}
@ -1694,7 +1746,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");
}
}
@ -1780,12 +1832,14 @@ public class DefaultChannelPipelineTest {
channel2.close().syncUninterruptibly();
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testHandlerAddedFailedButHandlerStillRemoved() throws InterruptedException {
testHandlerAddedFailedButHandlerStillRemoved0(false);
}
@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testHandlerAddedFailedButHandlerStillRemovedWithLaterRegister() throws InterruptedException {
testHandlerAddedFailedButHandlerStillRemoved0(true);
}
@ -1841,12 +1895,14 @@ public class DefaultChannelPipelineTest {
}
}
@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);
}
@ -1930,7 +1986,7 @@ public class DefaultChannelPipelineTest {
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
public void handlerRemoved(ChannelHandlerContext ctx) {
if (!removedHandler.trySuccess(true)) {
error.set(new AssertionError("handlerRemoved(...) called multiple times: " + ctx.name()));
} else if (addedHandler.getNow() == Boolean.FALSE) {
@ -1985,7 +2041,7 @@ public class DefaultChannelPipelineTest {
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
public void handlerRemoved(ChannelHandlerContext ctx) {
removedQueue.add(this);
checkExecutor(ctx);
}
@ -2026,7 +2082,7 @@ public class DefaultChannelPipelineTest {
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
public void handlerRemoved(ChannelHandlerContext ctx) {
assertExecutor(ctx, removedPromise);
}
@ -2058,7 +2114,7 @@ public class DefaultChannelPipelineTest {
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
public void handlerRemoved(ChannelHandlerContext ctx) {
error.set(new AssertionError());
}
}
@ -2156,8 +2212,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,40 @@ 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 org.junit.jupiter.api.function.Executable;
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 Executable() {
@Override
public void execute() {
new DefaultChannelPromise(null);
}
});
}
@Test(expected = NullPointerException.class)
@Test
public void testChannelWithNullExecutor() {
new DefaultChannelPromise(new EmbeddedChannel(), null);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
new DefaultChannelPromise(new EmbeddedChannel(), null);
}
});
}
@Test(expected = NullPointerException.class)
@Test
public void testNullChannelWithExecutor() {
new DefaultChannelPromise(null, ImmediateEventExecutor.INSTANCE);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
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;
@ -26,9 +26,9 @@ import java.io.RandomAccessFile;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
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,13 @@
*/
package io.netty.channel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
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 +34,13 @@ 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 Executable() {
@Override
public void execute() {
new FailedChannelFuture(Mockito.mock(Channel.class), null, null);
}
});
}
}

View File

@ -20,7 +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.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
@ -29,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 {
@ -38,12 +45,12 @@ 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(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
assertQueueEmpty(queue);
}
});
@ -57,12 +64,12 @@ 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(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
assertQueueEmpty(queue);
}
});
@ -102,13 +109,13 @@ public class PendingWriteQueueTest {
final EmbeddedChannel channel = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
public void handlerAdded(ChannelHandlerContext ctx) {
ctxRef.set(ctx);
queueRef.set(new PendingWriteQueue(ctx));
}
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
public void channelWritabilityChanged(ChannelHandlerContext ctx) {
final PendingWriteQueue queue = queueRef.get();
final ByteBuf msg = (ByteBuf) queue.current();
@ -212,7 +219,7 @@ public class PendingWriteQueueTest {
ChannelPromise promise = channel.newPromise();
promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
queue.removeAndFailAll(new IllegalStateException());
}
});
@ -299,13 +306,13 @@ public class PendingWriteQueueTest {
final ChannelPromise promise3 = channel.newPromise();
promise3.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
failOrder.add(3);
}
});
promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
failOrder.add(1);
queue.add(3L, promise3);
}
@ -315,7 +322,7 @@ public class PendingWriteQueueTest {
ChannelPromise promise2 = channel.newPromise();
promise2.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
failOrder.add(2);
}
});
@ -341,7 +348,7 @@ public class PendingWriteQueueTest {
ChannelPromise promise = channel.newPromise();
promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
public void operationComplete(ChannelFuture future) {
queue.removeAndWriteAll();
}
});
@ -385,7 +392,7 @@ public class PendingWriteQueueTest {
public void channelActive(ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
assertQueueEmpty(queue);
assertTrue("Should be writable", ctx.channel().isWritable());
assertTrue(ctx.channel().isWritable(), "Should be writable");
}
@Override

View File

@ -22,12 +22,13 @@ import io.netty.channel.local.LocalAddress;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
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 org.hamcrest.MatcherAssert;
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;
@ -42,7 +43,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 {
@ -55,14 +59,14 @@ public class SingleThreadEventLoopTest {
private SingleThreadEventLoopB loopB;
private SingleThreadEventLoopC loopC;
@Before
@BeforeEach
public void newEventLoop() {
loopA = new SingleThreadEventLoopA();
loopB = new SingleThreadEventLoopB();
loopC = new SingleThreadEventLoopC();
}
@After
@AfterEach
public void stopEventLoop() {
if (!loopA.isShuttingDown()) {
loopA.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS);
@ -170,12 +174,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);
}
@ -218,12 +224,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);
}
@ -272,12 +280,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);
}
@ -362,7 +372,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();
@ -389,7 +400,8 @@ public class SingleThreadEventLoopTest {
}
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
@SuppressWarnings("deprecation")
public void testRegistrationAfterShutdown2() throws Exception {
loopA.shutdown();
@ -428,7 +440,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.
@ -450,7 +463,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.
@ -474,7 +488,8 @@ public class SingleThreadEventLoopTest {
assertThat(loopA.isShutdown(), is(true));
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testOnEventLoopIteration() throws Exception {
CountingRunnable onIteration = new CountingRunnable();
loopC.executeAfterEventLoopIteration(onIteration);
@ -487,7 +502,8 @@ public class SingleThreadEventLoopTest {
onIteration.getInvocationCount(), is(1));
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testRemoveOnEventLoopIteration() throws Exception {
CountingRunnable onIteration1 = new CountingRunnable();
loopC.executeAfterEventLoopIteration(onIteration1);

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 java.nio.channels.ClosedChannelException;
import java.util.ArrayDeque;
@ -31,7 +31,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;
@ -87,7 +88,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(new ChannelFutureListener() {
@ -164,7 +166,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<Throwable>();
@ -209,7 +212,8 @@ 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(new Action() {
@Override
@ -225,7 +229,8 @@ public class EmbeddedChannelTest {
});
}
@Test(timeout = 2000)
@Test
@Timeout(value = 2000, unit = TimeUnit.MILLISECONDS)
public void testFireChannelInactiveAndUnregisteredOnDisconnect() throws InterruptedException {
testFireChannelInactiveAndUnregistered(new Action() {
@Override
@ -586,7 +591,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 ChannelInboundHandlerAdapter() {

View File

@ -23,7 +23,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
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

@ -38,9 +38,11 @@ import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
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 org.junit.jupiter.api.function.Executable;
import java.net.ConnectException;
import java.nio.channels.ClosedChannelException;
@ -53,11 +55,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 {
@ -69,14 +72,14 @@ public class LocalChannelTest {
private static EventLoopGroup group2;
private static EventLoopGroup sharedGroup;
@BeforeClass
@BeforeAll
public static void beforeClass() {
group1 = new DefaultEventLoopGroup(2);
group2 = new DefaultEventLoopGroup(2);
sharedGroup = new DefaultEventLoopGroup(1);
}
@AfterClass
@AfterAll
public static void afterClass() throws InterruptedException {
Future<?> group1Future = group1.shutdownGracefully(0, 0, SECONDS);
Future<?> group2Future = group2.shutdownGracefully(0, 0, SECONDS);
@ -130,9 +133,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);
@ -283,7 +286,7 @@ public class LocalChannelTest {
}
});
ChannelFuture future = bootstrap.connect(sc.localAddress());
assertTrue("Connection should finish, not time out", future.await(200));
assertTrue(future.await(2000), "Connection should finish, not time out");
cc = future.channel();
} finally {
closeChannel(cc);
@ -803,7 +806,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();
@ -854,13 +858,18 @@ public class LocalChannelTest {
}
}
@Test(expected = ConnectException.class)
@Test
public void testConnectionRefused() {
Bootstrap sb = new Bootstrap();
final Bootstrap sb = new Bootstrap();
sb.group(group1)
.channel(LocalChannel.class)
.handler(new TestHandler())
.connect(LocalAddress.ANY).syncUninterruptibly();
.handler(new TestHandler());
assertThrows(ConnectException.class, new Executable() {
@Override
public void execute() {
sb.connect(LocalAddress.ANY).syncUninterruptibly();
}
});
}
private static final class LatchChannelFutureListener extends CountDownLatch implements ChannelFutureListener {
@ -960,12 +969,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);
}
@ -1023,22 +1034,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);
}
@ -1080,22 +1095,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.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.DefaultEventLoopGroup;
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

@ -32,7 +32,8 @@ import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.RejectedExecutionHandlers;
import io.netty.util.concurrent.ThreadPerTaskExecutor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -51,7 +52,11 @@ 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.assertEquals;
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 {
@ -156,7 +161,8 @@ public class NioEventLoopTest extends AbstractEventLoopTest {
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testSelectableChannel() throws Exception {
NioEventLoopGroup group = new NioEventLoopGroup(1);
NioEventLoop loop = (NioEventLoop) group.next();
@ -269,7 +275,8 @@ public class NioEventLoopTest extends AbstractEventLoopTest {
}
}
@Test(timeout = 3000L)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testChannelsRegistered() throws Exception {
NioEventLoopGroup group = new NioEventLoopGroup(1);
final NioEventLoop loop = (NioEventLoop) group.next();

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

@ -17,14 +17,17 @@ package io.netty.channel.socket.nio;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.AbstractNioChannel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.channels.NetworkChannel;
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;
public abstract class AbstractNioChannelTest<T extends AbstractNioChannel> {

View File

@ -24,14 +24,14 @@ import io.netty.channel.nio.NioEventLoopGroup;
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> {
@ -58,7 +58,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

@ -18,8 +18,8 @@ package io.netty.channel.socket.nio;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -28,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
@ -38,8 +41,8 @@ public class NioServerSocketChannelTest extends AbstractNioChannelTest<NioServer
try {
group.register(serverSocketChannel).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();
@ -53,11 +56,11 @@ public class NioServerSocketChannelTest extends AbstractNioChannelTest<NioServer
try {
group.register(serverSocketChannel).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.socket.SocketChannel;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.io.DataInput;
import java.io.DataInputStream;
@ -52,10 +53,12 @@ import java.nio.channels.NetworkChannel;
import java.util.Queue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertNotSame;
public class NioSocketChannelTest extends AbstractNioChannelTest<NioSocketChannel> {
@ -160,12 +163,14 @@ 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 {
testChannelReRegisterRead(true);
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testChannelReRegisterReadDifferentEventLoop() throws Exception {
testChannelReRegisterRead(false);
}
@ -247,7 +252,8 @@ public class NioSocketChannelTest extends AbstractNioChannelTest<NioSocketChanne
}
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testShutdownOutputAndClose() throws IOException {
NioEventLoopGroup group = new NioEventLoopGroup(1);
ServerSocket socket = new ServerSocket();