Migrate testsuite, transport-native-epoll, transport-native-kqueue, and transport-native-unix-common-tests tests to JUnit 5 (#11320)

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-27 05:07:41 -07:00 committed by Norman Maurer
parent b89a807d15
commit bc7434aedb
99 changed files with 1519 additions and 987 deletions

View File

@ -89,6 +89,11 @@
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.junit.vintage</groupId> <groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId> <artifactId>junit-vintage-engine</artifactId>

View File

@ -21,37 +21,25 @@ import io.netty.testsuite.util.TestUtils;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule; import org.junit.jupiter.api.TestInfo;
import org.junit.rules.TestName;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
public abstract class AbstractComboTestsuiteTest<SB extends AbstractBootstrap<?, ?>, public abstract class AbstractComboTestsuiteTest<SB extends AbstractBootstrap<?, ?>,
CB extends AbstractBootstrap<?, ?>> { CB extends AbstractBootstrap<?, ?>> {
private final Class<SB> sbClazz;
private final Class<CB> cbClazz;
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile CB cb; protected volatile CB cb;
protected volatile SB sb; protected volatile SB sb;
protected AbstractComboTestsuiteTest(Class<SB> sbClazz, Class<CB> cbClazz) {
this.sbClazz = sbClazz;
this.cbClazz = cbClazz;
}
protected abstract List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> newFactories(); protected abstract List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> newFactories();
protected List<ByteBufAllocator> newAllocators() { protected List<ByteBufAllocator> newAllocators() {
return TestsuitePermutation.allocator(); return TestsuitePermutation.allocator();
} }
@Rule protected void run(TestInfo testInfo, Runner<SB, CB> runner) throws Throwable {
public final TestName testName = new TestName();
protected void run() throws Throwable {
List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> combos = newFactories(); List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> combos = newFactories();
String methodName = TestUtils.testMethodName(testInfo);
for (ByteBufAllocator allocator: newAllocators()) { for (ByteBufAllocator allocator: newAllocators()) {
int i = 0; int i = 0;
for (TestsuitePermutation.BootstrapComboFactory<SB, CB> e: combos) { for (TestsuitePermutation.BootstrapComboFactory<SB, CB> e: combos) {
@ -60,17 +48,15 @@ public abstract class AbstractComboTestsuiteTest<SB extends AbstractBootstrap<?,
configure(sb, cb, allocator); configure(sb, cb, allocator);
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d (%s + %s) with %s", "Running: %s %d of %d (%s + %s) with %s",
testName.getMethodName(), ++ i, combos.size(), sb, cb, StringUtil.simpleClassName(allocator))); methodName, ++ i, combos.size(), sb, cb, StringUtil.simpleClassName(allocator)));
try { runner.run(sb, cb);
Method m = getClass().getMethod(
TestUtils.testMethodName(testName), sbClazz, cbClazz);
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
} }
} }
} }
protected abstract void configure(SB sb, CB cb, ByteBufAllocator allocator); protected abstract void configure(SB sb, CB cb, ByteBufAllocator allocator);
public interface Runner<SB extends AbstractBootstrap<?, ?>, CB extends AbstractBootstrap<?, ?>> {
void run(SB sb, CB cb) throws Throwable;
}
} }

View File

@ -15,18 +15,6 @@
*/ */
package io.netty.testsuite.transport; package io.netty.testsuite.transport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -39,10 +27,22 @@ import io.netty.channel.local.LocalAddress;
import io.netty.channel.local.LocalServerChannel; import io.netty.channel.local.LocalServerChannel;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
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 abstract class AbstractSingleThreadEventLoopTest { public abstract class AbstractSingleThreadEventLoopTest {
@Test(timeout = 5000) @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testChannelsRegistered() throws Exception { public void testChannelsRegistered() throws Exception {
EventLoopGroup group = newEventLoopGroup(); EventLoopGroup group = newEventLoopGroup();
final SingleThreadEventLoop loop = (SingleThreadEventLoop) group.next(); final SingleThreadEventLoop loop = (SingleThreadEventLoop) group.next();
@ -106,7 +106,8 @@ public abstract class AbstractSingleThreadEventLoopTest {
} }
// Copied from AbstractEventLoopTest // Copied from AbstractEventLoopTest
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testShutdownGracefullyNoQuietPeriod() throws Exception { public void testShutdownGracefullyNoQuietPeriod() throws Exception {
EventLoopGroup loop = newEventLoopGroup(); EventLoopGroup loop = newEventLoopGroup();
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();

View File

@ -21,33 +21,23 @@ import io.netty.testsuite.util.TestUtils;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule; import org.junit.jupiter.api.TestInfo;
import org.junit.rules.TestName;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List; import java.util.List;
public abstract class AbstractTestsuiteTest<T extends AbstractBootstrap<?, ?>> { public abstract class AbstractTestsuiteTest<T extends AbstractBootstrap<?, ?>> {
private final Class<T> clazz;
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile T cb; protected volatile T cb;
protected AbstractTestsuiteTest(Class<T> clazz) {
this.clazz = clazz;
}
protected abstract List<TestsuitePermutation.BootstrapFactory<T>> newFactories(); protected abstract List<TestsuitePermutation.BootstrapFactory<T>> newFactories();
protected List<ByteBufAllocator> newAllocators() { protected List<ByteBufAllocator> newAllocators() {
return TestsuitePermutation.allocator(); return TestsuitePermutation.allocator();
} }
@Rule protected void run(TestInfo testInfo, Runner<T> runner) throws Throwable {
public final TestName testName = new TestName();
protected void run() throws Throwable {
List<TestsuitePermutation.BootstrapFactory<T>> combos = newFactories(); List<TestsuitePermutation.BootstrapFactory<T>> combos = newFactories();
String methodName = TestUtils.testMethodName(testInfo);
for (ByteBufAllocator allocator: newAllocators()) { for (ByteBufAllocator allocator: newAllocators()) {
int i = 0; int i = 0;
for (TestsuitePermutation.BootstrapFactory<T> e: combos) { for (TestsuitePermutation.BootstrapFactory<T> e: combos) {
@ -55,17 +45,15 @@ public abstract class AbstractTestsuiteTest<T extends AbstractBootstrap<?, ?>> {
configure(cb, allocator); configure(cb, allocator);
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d with %s", "Running: %s %d of %d with %s",
testName.getMethodName(), ++ i, combos.size(), StringUtil.simpleClassName(allocator))); methodName, ++ i, combos.size(), StringUtil.simpleClassName(allocator)));
try { runner.run(cb);
Method m = getClass().getMethod(
TestUtils.testMethodName(testName), clazz);
m.invoke(this, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
} }
} }
} }
protected abstract void configure(T bootstrap, ByteBufAllocator allocator); protected abstract void configure(T bootstrap, ByteBufAllocator allocator);
public interface Runner<CB extends AbstractBootstrap<?, ?>> {
void run(CB cb) throws Throwable;
}
} }

View File

@ -27,11 +27,6 @@ import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
public abstract class AbstractSctpTest extends AbstractComboTestsuiteTest<ServerBootstrap, Bootstrap> { public abstract class AbstractSctpTest extends AbstractComboTestsuiteTest<ServerBootstrap, Bootstrap> {
protected AbstractSctpTest() {
super(ServerBootstrap.class, Bootstrap.class);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return SctpTestPermutation.sctpChannel(); return SctpTestPermutation.sctpChannel();

View File

@ -28,14 +28,15 @@ import io.netty.handler.codec.sctp.SctpInboundByteStreamHandler;
import io.netty.handler.codec.sctp.SctpMessageCompletionHandler; import io.netty.handler.codec.sctp.SctpMessageCompletionHandler;
import io.netty.handler.codec.sctp.SctpOutboundByteStreamHandler; import io.netty.handler.codec.sctp.SctpOutboundByteStreamHandler;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import org.junit.Assume; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.TestInfo;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class SctpEchoTest extends AbstractSctpTest { public class SctpEchoTest extends AbstractSctpTest {
@ -47,9 +48,14 @@ public class SctpEchoTest extends AbstractSctpTest {
} }
@Test @Test
public void testSimpleEcho() throws Throwable { public void testSimpleEcho(TestInfo testInfo) throws Throwable {
Assume.assumeTrue(TestUtils.isSctpSupported()); assumeTrue(TestUtils.isSctpSupported());
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSimpleEcho(serverBootstrap, bootstrap);
}
});
} }
public void testSimpleEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -57,9 +63,14 @@ public class SctpEchoTest extends AbstractSctpTest {
} }
@Test @Test
public void testSimpleEchoUnordered() throws Throwable { public void testSimpleEchoUnordered(TestInfo testInfo) throws Throwable {
Assume.assumeTrue(TestUtils.isSctpSupported()); assumeTrue(TestUtils.isSctpSupported());
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSimpleEchoUnordered(serverBootstrap, bootstrap);
}
});
} }
public void testSimpleEchoUnordered(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoUnordered(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -27,11 +27,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public abstract class AbstractClientSocketTest extends AbstractTestsuiteTest<Bootstrap> { public abstract class AbstractClientSocketTest extends AbstractTestsuiteTest<Bootstrap> {
protected AbstractClientSocketTest() {
super(Bootstrap.class);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapFactory<Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapFactory<Bootstrap>> newFactories() {
return SocketTestPermutation.INSTANCE.clientSocket(); return SocketTestPermutation.INSTANCE.clientSocket();

View File

@ -28,11 +28,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public abstract class AbstractDatagramTest extends AbstractComboTestsuiteTest<Bootstrap, Bootstrap> { public abstract class AbstractDatagramTest extends AbstractComboTestsuiteTest<Bootstrap, Bootstrap> {
protected AbstractDatagramTest() {
super(Bootstrap.class, Bootstrap.class);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<Bootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<Bootstrap, Bootstrap>> newFactories() {
return SocketTestPermutation.INSTANCE.datagram(socketInternetProtocalFamily()); return SocketTestPermutation.INSTANCE.datagram(socketInternetProtocalFamily());

View File

@ -28,10 +28,6 @@ import java.util.List;
public abstract class AbstractServerSocketTest extends AbstractTestsuiteTest<ServerBootstrap> { public abstract class AbstractServerSocketTest extends AbstractTestsuiteTest<ServerBootstrap> {
protected AbstractServerSocketTest() {
super(ServerBootstrap.class);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapFactory<ServerBootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapFactory<ServerBootstrap>> newFactories() {
return SocketTestPermutation.INSTANCE.serverSocket(); return SocketTestPermutation.INSTANCE.serverSocket();

View File

@ -30,11 +30,14 @@ import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -45,9 +48,15 @@ public abstract class AbstractSocketReuseFdTest extends AbstractSocketTest {
@Override @Override
protected abstract List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories(); protected abstract List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories();
@Test(timeout = 60000) @Test
public void testReuseFd() throws Throwable { @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS)
run(); public void testReuseFd(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testReuseFd(serverBootstrap, bootstrap);
}
});
} }
public void testReuseFd(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testReuseFd(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -23,22 +23,33 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.ChannelInputShutdownEvent; import io.netty.channel.socket.ChannelInputShutdownEvent;
import io.netty.channel.socket.DuplexChannel; import io.netty.channel.socket.DuplexChannel;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
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 abstract class AbstractSocketShutdownOutputByPeerTest<Socket> extends AbstractServerSocketTest { public abstract class AbstractSocketShutdownOutputByPeerTest<Socket> extends AbstractServerSocketTest {
@Test(timeout = 30000) @Test
public void testShutdownOutput() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testShutdownOutput(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap) throws Throwable {
testShutdownOutput(serverBootstrap);
}
});
} }
public void testShutdownOutput(ServerBootstrap sb) throws Throwable { public void testShutdownOutput(ServerBootstrap sb) throws Throwable {
@ -78,9 +89,15 @@ public abstract class AbstractSocketShutdownOutputByPeerTest<Socket> extends Abs
} }
} }
@Test(timeout = 30000) @Test
public void testShutdownOutputWithoutOption() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testShutdownOutputWithoutOption(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap) throws Throwable {
testShutdownOutputWithoutOption(serverBootstrap);
}
});
} }
public void testShutdownOutputWithoutOption(ServerBootstrap sb) throws Throwable { public void testShutdownOutputWithoutOption(ServerBootstrap sb) throws Throwable {

View File

@ -28,11 +28,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public abstract class AbstractSocketTest extends AbstractComboTestsuiteTest<ServerBootstrap, Bootstrap> { public abstract class AbstractSocketTest extends AbstractComboTestsuiteTest<ServerBootstrap, Bootstrap> {
protected AbstractSocketTest() {
super(ServerBootstrap.class, Bootstrap.class);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return SocketTestPermutation.INSTANCE.socket(); return SocketTestPermutation.INSTANCE.socket();

View File

@ -28,21 +28,30 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class CompositeBufferGatheringWriteTest extends AbstractSocketTest { public class CompositeBufferGatheringWriteTest extends AbstractSocketTest {
private static final int EXPECTED_BYTES = 20; private static final int EXPECTED_BYTES = 20;
@Test(timeout = 10000) @Test
public void testSingleCompositeBufferWrite() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
run(); public void testSingleCompositeBufferWrite(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSingleCompositeBufferWrite(serverBootstrap, bootstrap);
}
});
} }
public void testSingleCompositeBufferWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSingleCompositeBufferWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -136,9 +145,15 @@ public class CompositeBufferGatheringWriteTest extends AbstractSocketTest {
} }
} }
@Test(timeout = 10000) @Test
public void testCompositeBufferPartialWriteDoesNotCorruptData() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
run(); public void testCompositeBufferPartialWriteDoesNotCorruptData(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testCompositeBufferPartialWriteDoesNotCorruptData(serverBootstrap, bootstrap);
}
});
} }
protected void compositeBufferPartialWriteDoesNotCorruptDataInitServerConfig(ChannelConfig config, protected void compositeBufferPartialWriteDoesNotCorruptDataInitServerConfig(ChannelConfig config,

View File

@ -28,12 +28,16 @@ import io.netty.util.NetUtil;
import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Assume; import org.junit.jupiter.api.TestInfo;
import org.junit.Test; import org.junit.jupiter.api.Timeout;
import java.net.PortUnreachableException; import java.net.PortUnreachableException;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
public class DatagramConnectNotExistsTest extends AbstractClientSocketTest { public class DatagramConnectNotExistsTest extends AbstractClientSocketTest {
@ -42,15 +46,21 @@ public class DatagramConnectNotExistsTest extends AbstractClientSocketTest {
return SocketTestPermutation.INSTANCE.datagramSocket(); return SocketTestPermutation.INSTANCE.datagramSocket();
} }
@Test(timeout = 10000) @Test
public void testConnectNotExists() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
run(); public void testConnectNotExists(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) {
testConnectNotExists(bootstrap);
}
});
} }
public void testConnectNotExists(Bootstrap cb) throws Throwable { public void testConnectNotExists(Bootstrap cb) {
// Currently not works on windows // Currently not works on windows
// See https://github.com/netty/netty/issues/11285 // See https://github.com/netty/netty/issues/11285
Assume.assumeFalse(PlatformDependent.isWindows()); assumeFalse(PlatformDependent.isWindows());
final Promise<Throwable> promise = ImmediateEventExecutor.INSTANCE.newPromise(); final Promise<Throwable> promise = ImmediateEventExecutor.INSTANCE.newPromise();
cb.handler(new ChannelInboundHandlerAdapter() { cb.handler(new ChannelInboundHandlerAdapter() {
@Override @Override
@ -61,11 +71,11 @@ public class DatagramConnectNotExistsTest extends AbstractClientSocketTest {
ChannelFuture future = cb.connect(NetUtil.LOCALHOST, SocketTestPermutation.BAD_PORT); ChannelFuture future = cb.connect(NetUtil.LOCALHOST, SocketTestPermutation.BAD_PORT);
try { try {
Channel datagramChannel = future.syncUninterruptibly().channel(); Channel datagramChannel = future.syncUninterruptibly().channel();
Assert.assertTrue(datagramChannel.isActive()); assertTrue(datagramChannel.isActive());
datagramChannel.writeAndFlush( datagramChannel.writeAndFlush(
Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)).syncUninterruptibly(); Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)).syncUninterruptibly();
if (!(datagramChannel instanceof OioDatagramChannel)) { if (!(datagramChannel instanceof OioDatagramChannel)) {
Assert.assertTrue(promise.syncUninterruptibly().getNow() instanceof PortUnreachableException); assertTrue(promise.syncUninterruptibly().getNow() instanceof PortUnreachableException);
} }
} finally { } finally {
future.channel().close(); future.channel().close();

View File

@ -18,7 +18,8 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.socket.InternetProtocolFamily; import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import org.junit.Assume;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
public class DatagramMulticastIPv6Test extends DatagramMulticastTest { public class DatagramMulticastIPv6Test extends DatagramMulticastTest {
@ -26,7 +27,7 @@ public class DatagramMulticastIPv6Test extends DatagramMulticastTest {
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable { public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
// Not works on windows atm. // Not works on windows atm.
// See https://github.com/netty/netty/issues/11285 // See https://github.com/netty/netty/issues/11285
Assume.assumeFalse(PlatformDependent.isWindows()); assumeFalse(PlatformDependent.isWindows());
super.testMulticast(sb, cb); super.testMulticast(sb, cb);
} }

View File

@ -26,8 +26,8 @@ import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.channel.socket.oio.OioDatagramChannel; import io.netty.channel.socket.oio.OioDatagramChannel;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.util.internal.SocketUtils; import io.netty.util.internal.SocketUtils;
import org.junit.Assume; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
@ -40,19 +40,28 @@ import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; 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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class DatagramMulticastTest extends AbstractDatagramTest { public class DatagramMulticastTest extends AbstractDatagramTest {
@Test @Test
public void testMulticast() throws Throwable { public void testMulticast(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testMulticast(bootstrap, bootstrap2);
}
});
} }
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable { public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
NetworkInterface iface = multicastNetworkInterface(); NetworkInterface iface = multicastNetworkInterface();
Assume.assumeNotNull("No NetworkInterface found that supports multicast and " + assumeTrue(iface != null, "No NetworkInterface found that supports multicast and " +
socketInternetProtocalFamily(), iface); socketInternetProtocalFamily());
MulticastTestHandler mhandler = new MulticastTestHandler(); MulticastTestHandler mhandler = new MulticastTestHandler();

View File

@ -19,7 +19,7 @@ import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement; import io.netty.util.internal.SuppressJava6Requirement;
import org.junit.Assume; import org.junit.Assume;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import java.io.IOException; import java.io.IOException;
import java.net.StandardProtocolFamily; import java.net.StandardProtocolFamily;
@ -29,7 +29,7 @@ import java.nio.channels.spi.SelectorProvider;
public class DatagramUnicastIPv6Test extends DatagramUnicastTest { public class DatagramUnicastIPv6Test extends DatagramUnicastTest {
@SuppressJava6Requirement(reason = "Guarded by java version check") @SuppressJava6Requirement(reason = "Guarded by java version check")
@BeforeClass @BeforeAll
public static void assumeIpv6Supported() { public static void assumeIpv6Supported() {
try { try {
if (PlatformDependent.javaVersion() < 7) { if (PlatformDependent.javaVersion() < 7) {

View File

@ -29,7 +29,8 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
@ -42,7 +43,12 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class DatagramUnicastTest extends AbstractDatagramTest { public class DatagramUnicastTest extends AbstractDatagramTest {
@ -52,8 +58,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testBindWithPortOnly() throws Throwable { public void testBindWithPortOnly(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testBindWithPortOnly(bootstrap, bootstrap2);
}
});
} }
public void testBindWithPortOnly(Bootstrap sb, Bootstrap cb) throws Throwable { public void testBindWithPortOnly(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -67,8 +78,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testSimpleSendDirectByteBuf() throws Throwable { public void testSimpleSendDirectByteBuf(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSimpleSendDirectByteBuf(bootstrap, bootstrap2);
}
});
} }
public void testSimpleSendDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleSendDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -77,8 +93,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testSimpleSendHeapByteBuf() throws Throwable { public void testSimpleSendHeapByteBuf(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSimpleSendHeapByteBuf(bootstrap, bootstrap2);
}
});
} }
public void testSimpleSendHeapByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleSendHeapByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -87,8 +108,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testSimpleSendCompositeDirectByteBuf() throws Throwable { public void testSimpleSendCompositeDirectByteBuf(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSimpleSendCompositeDirectByteBuf(bootstrap, bootstrap2);
}
});
} }
public void testSimpleSendCompositeDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleSendCompositeDirectByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -104,8 +130,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testSimpleSendCompositeHeapByteBuf() throws Throwable { public void testSimpleSendCompositeHeapByteBuf(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSimpleSendCompositeHeapByteBuf(bootstrap, bootstrap2);
}
});
} }
public void testSimpleSendCompositeHeapByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleSendCompositeHeapByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -121,8 +152,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testSimpleSendCompositeMixedByteBuf() throws Throwable { public void testSimpleSendCompositeMixedByteBuf(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSimpleSendCompositeMixedByteBuf(bootstrap, bootstrap2);
}
});
} }
public void testSimpleSendCompositeMixedByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleSendCompositeMixedByteBuf(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -138,8 +174,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testSimpleSendWithoutBind() throws Throwable { public void testSimpleSendWithoutBind(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSimpleSendWithoutBind(bootstrap, bootstrap2);
}
});
} }
public void testSimpleSendWithoutBind(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleSendWithoutBind(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -156,8 +197,13 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
} }
@Test @Test
public void testSimpleSendWithConnect() throws Throwable { public void testSimpleSendWithConnect(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSimpleSendWithConnect(bootstrap, bootstrap2);
}
});
} }
public void testSimpleSendWithConnect(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleSendWithConnect(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -325,8 +371,8 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
ChannelFuture future = cc.writeAndFlush( ChannelFuture future = cc.writeAndFlush(
buf.retain().duplicate()).awaitUninterruptibly(); buf.retain().duplicate()).awaitUninterruptibly();
assertTrue("NotYetConnectedException expected, got: " + future.cause(), assertTrue(future.cause() instanceof NotYetConnectedException,
future.cause() instanceof NotYetConnectedException); "NotYetConnectedException expected, got: " + future.cause());
} finally { } finally {
// release as we used buf.retain() before // release as we used buf.retain() before
buf.release(); buf.release();

View File

@ -22,15 +22,16 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.util.internal.SocketUtils; import io.netty.util.internal.SocketUtils;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertTrue;
public class ServerSocketSuspendTest extends AbstractServerSocketTest { public class ServerSocketSuspendTest extends AbstractServerSocketTest {
@ -38,9 +39,14 @@ public class ServerSocketSuspendTest extends AbstractServerSocketTest {
private static final long TIMEOUT = 3000000000L; private static final long TIMEOUT = 3000000000L;
@Test @Test
@Ignore("Need to investigate why it fails on osx") @Disabled("Need to investigate why it fails on osx")
public void testSuspendAndResumeAccept() throws Throwable { public void testSuspendAndResumeAccept(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap) throws Throwable {
testSuspendAndResumeAccept(serverBootstrap);
}
});
} }
public void testSuspendAndResumeAccept(ServerBootstrap sb) throws Throwable { public void testSuspendAndResumeAccept(ServerBootstrap sb) throws Throwable {

View File

@ -29,19 +29,25 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.RecvByteBufAllocator; import io.netty.channel.RecvByteBufAllocator;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.UncheckedBooleanSupplier;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketAutoReadTest extends AbstractSocketTest { public class SocketAutoReadTest extends AbstractSocketTest {
@Test @Test
public void testAutoReadOffDuringReadOnlyReadsOneTime() throws Throwable { public void testAutoReadOffDuringReadOnlyReadsOneTime(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAutoReadOffDuringReadOnlyReadsOneTime(serverBootstrap, bootstrap);
}
});
} }
public void testAutoReadOffDuringReadOnlyReadsOneTime(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAutoReadOffDuringReadOnlyReadsOneTime(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -28,12 +28,13 @@ import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
public class SocketBufReleaseTest extends AbstractSocketTest { public class SocketBufReleaseTest extends AbstractSocketTest {
@ -41,8 +42,13 @@ public class SocketBufReleaseTest extends AbstractSocketTest {
new DefaultEventExecutorGroup(1, new DefaultThreadFactory(SocketBufReleaseTest.class, true)).next(); new DefaultEventExecutorGroup(1, new DefaultThreadFactory(SocketBufReleaseTest.class, true)).next();
@Test @Test
public void testBufRelease() throws Throwable { public void testBufRelease(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testBufRelease(serverBootstrap, bootstrap);
}
});
} }
public void testBufRelease(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testBufRelease(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -23,19 +23,28 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import org.junit.Test; import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketCancelWriteTest extends AbstractSocketTest { public class SocketCancelWriteTest extends AbstractSocketTest {
@Test(timeout = 30000) @Test
public void testCancelWrite() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testCancelWrite(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testCancelWrite(serverBootstrap, bootstrap);
}
});
} }
public void testCancelWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testCancelWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -18,17 +18,26 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import org.junit.Test; import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import java.net.SocketException; import java.net.SocketException;
import java.nio.channels.NotYetConnectedException; import java.nio.channels.NotYetConnectedException;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class SocketChannelNotYetConnectedTest extends AbstractClientSocketTest { public class SocketChannelNotYetConnectedTest extends AbstractClientSocketTest {
@Test(timeout = 30000) @Test
public void testShutdownNotYetConnected() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testShutdownNotYetConnected(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testShutdownNotYetConnected(bootstrap);
}
});
} }
public void testShutdownNotYetConnected(Bootstrap cb) throws Throwable { public void testShutdownNotYetConnected(Bootstrap cb) throws Throwable {

View File

@ -21,13 +21,19 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
public class SocketCloseForciblyTest extends AbstractSocketTest { public class SocketCloseForciblyTest extends AbstractSocketTest {
@Test @Test
public void testCloseForcibly() throws Throwable { public void testCloseForcibly(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testCloseForcibly(serverBootstrap, bootstrap);
}
});
} }
public void testCloseForcibly(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testCloseForcibly(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -26,14 +26,23 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.WriteBufferWaterMark; import io.netty.channel.WriteBufferWaterMark;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class SocketConditionalWritabilityTest extends AbstractSocketTest { public class SocketConditionalWritabilityTest extends AbstractSocketTest {
@Test(timeout = 30000) @Test
public void testConditionalWritability() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testConditionalWritability(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testConditionalWritability(serverBootstrap, bootstrap);
}
});
} }
public void testConditionalWritability(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testConditionalWritability(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -29,8 +29,10 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import org.junit.AssumptionViolatedException; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import org.opentest4j.TestAbortedException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -38,21 +40,28 @@ import java.net.SocketAddress;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import static io.netty.buffer.ByteBufUtil.writeAscii; import static io.netty.buffer.ByteBufUtil.writeAscii;
import static io.netty.buffer.UnpooledByteBufAllocator.DEFAULT; import static io.netty.buffer.UnpooledByteBufAllocator.DEFAULT;
import static io.netty.util.CharsetUtil.US_ASCII; import static io.netty.util.CharsetUtil.US_ASCII;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketConnectTest extends AbstractSocketTest { public class SocketConnectTest extends AbstractSocketTest {
@Test(timeout = 30000) @Test
public void testLocalAddressAfterConnect() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testLocalAddressAfterConnect(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testLocalAddressAfterConnect(serverBootstrap, bootstrap);
}
});
} }
public void testLocalAddressAfterConnect(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testLocalAddressAfterConnect(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -87,9 +96,15 @@ public class SocketConnectTest extends AbstractSocketTest {
} }
} }
@Test(timeout = 3000) @Test
public void testChannelEventsFiredWhenClosedDirectly() throws Throwable { @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
run(); public void testChannelEventsFiredWhenClosedDirectly(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testChannelEventsFiredWhenClosedDirectly(serverBootstrap, bootstrap);
}
});
} }
public void testChannelEventsFiredWhenClosedDirectly(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testChannelEventsFiredWhenClosedDirectly(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -127,9 +142,15 @@ public class SocketConnectTest extends AbstractSocketTest {
} }
} }
@Test(timeout = 3000) @Test
public void testWriteWithFastOpenBeforeConnect() throws Throwable { @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
run(); public void testWriteWithFastOpenBeforeConnect(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testWriteWithFastOpenBeforeConnect(serverBootstrap, bootstrap);
}
});
} }
public void testWriteWithFastOpenBeforeConnect(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testWriteWithFastOpenBeforeConnect(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -168,7 +189,7 @@ public class SocketConnectTest extends AbstractSocketTest {
} }
protected void enableTcpFastOpen(ServerBootstrap sb, Bootstrap cb) { protected void enableTcpFastOpen(ServerBootstrap sb, Bootstrap cb) {
throw new AssumptionViolatedException( throw new TestAbortedException(
"Support for testing TCP_FASTOPEN not enabled for " + StringUtil.simpleClassName(this)); "Support for testing TCP_FASTOPEN not enabled for " + StringUtil.simpleClassName(this));
} }

View File

@ -26,27 +26,36 @@ import io.netty.util.NetUtil;
import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.Socket; import java.net.Socket;
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.Assume.*;
import static io.netty.testsuite.transport.socket.SocketTestPermutation.BAD_HOST; import static io.netty.testsuite.transport.socket.SocketTestPermutation.BAD_HOST;
import static io.netty.testsuite.transport.socket.SocketTestPermutation.BAD_PORT; import static io.netty.testsuite.transport.socket.SocketTestPermutation.BAD_PORT;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class SocketConnectionAttemptTest extends AbstractClientSocketTest { public class SocketConnectionAttemptTest extends AbstractClientSocketTest {
// See /etc/services // See /etc/services
private static final int UNASSIGNED_PORT = 4; private static final int UNASSIGNED_PORT = 4;
@Test(timeout = 30000) @Test
public void testConnectTimeout() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testConnectTimeout(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testConnectTimeout(bootstrap);
}
});
} }
public void testConnectTimeout(Bootstrap cb) throws Throwable { public void testConnectTimeout(Bootstrap cb) throws Throwable {
@ -59,18 +68,30 @@ public class SocketConnectionAttemptTest extends AbstractClientSocketTest {
} }
} }
@Test(timeout = 30000) @Test
public void testConnectRefused() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testConnectRefused(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testConnectRefused(bootstrap);
}
});
} }
public void testConnectRefused(Bootstrap cb) throws Throwable { public void testConnectRefused(Bootstrap cb) throws Throwable {
testConnectRefused0(cb, false); testConnectRefused0(cb, false);
} }
@Test(timeout = 30000) @Test
public void testConnectRefusedHalfClosure() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testConnectRefusedHalfClosure(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testConnectRefusedHalfClosure(bootstrap);
}
});
} }
public void testConnectRefusedHalfClosure(Bootstrap cb) throws Throwable { public void testConnectRefusedHalfClosure(Bootstrap cb) throws Throwable {
@ -94,7 +115,7 @@ public class SocketConnectionAttemptTest extends AbstractClientSocketTest {
} }
@Test @Test
public void testConnectCancellation() throws Throwable { public void testConnectCancellation(TestInfo testInfo) throws Throwable {
// Check if the test can be executed or should be skipped because of no network/internet connection // Check if the test can be executed or should be skipped because of no network/internet connection
// See https://github.com/netty/netty/issues/1474 // See https://github.com/netty/netty/issues/1474
boolean badHostTimedOut = true; boolean badHostTimedOut = true;
@ -114,10 +135,14 @@ public class SocketConnectionAttemptTest extends AbstractClientSocketTest {
} }
} }
assumeThat("The connection attempt to " + BAD_HOST + " does not time out.", assumeTrue(badHostTimedOut, "The connection attempt to " + BAD_HOST + " does not time out.");
badHostTimedOut, is(true));
run(); run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testConnectCancellation(bootstrap);
}
});
} }
public void testConnectCancellation(Bootstrap cb) throws Throwable { public void testConnectCancellation(Bootstrap cb) throws Throwable {

View File

@ -23,19 +23,28 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static io.netty.channel.ChannelOption.AUTO_READ; import static io.netty.channel.ChannelOption.AUTO_READ;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
public class SocketDataReadInitialStateTest extends AbstractSocketTest { public class SocketDataReadInitialStateTest extends AbstractSocketTest {
@Test(timeout = 10000) @Test
public void testAutoReadOffNoDataReadUntilReadCalled() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
run(); public void testAutoReadOffNoDataReadUntilReadCalled(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAutoReadOffNoDataReadUntilReadCalled(serverBootstrap, bootstrap);
}
});
} }
public void testAutoReadOffNoDataReadUntilReadCalled(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAutoReadOffNoDataReadUntilReadCalled(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -127,9 +136,15 @@ public class SocketDataReadInitialStateTest extends AbstractSocketTest {
} }
} }
@Test(timeout = 10000) @Test
public void testAutoReadOnDataReadImmediately() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
run(); public void testAutoReadOnDataReadImmediately(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAutoReadOnDataReadImmediately(serverBootstrap, bootstrap);
}
});
} }
public void testAutoReadOnDataReadImmediately(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAutoReadOnDataReadImmediately(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -27,15 +27,20 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup;
import org.junit.AfterClass; import java.util.concurrent.TimeUnit;
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 java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class SocketEchoTest extends AbstractSocketTest { public class SocketEchoTest extends AbstractSocketTest {
@ -48,73 +53,111 @@ public class SocketEchoTest extends AbstractSocketTest {
random.nextBytes(data); random.nextBytes(data);
} }
@BeforeClass @BeforeAll
public static void createGroup() { public static void createGroup() {
group = new DefaultEventExecutorGroup(2); group = new DefaultEventExecutorGroup(2);
} }
@AfterClass @AfterAll
public static void destroyGroup() throws Exception { public static void destroyGroup() throws Exception {
group.shutdownGracefully().sync(); group.shutdownGracefully().sync();
} }
@Test(timeout = 30000) @Test
public void testSimpleEcho() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testSimpleEcho(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSimpleEcho(serverBootstrap, bootstrap);
}
});
} }
public void testSimpleEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testSimpleEcho0(sb, cb, false, false, true); testSimpleEcho0(sb, cb, false, false, true);
} }
@Test(timeout = 30000) @Test
public void testSimpleEchoNotAutoRead() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testSimpleEchoNotAutoRead(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable {
testSimpleEchoNotAutoRead(sb1, cb1);
}
});
} }
public void testSimpleEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testSimpleEcho0(sb, cb, false, false, false); testSimpleEcho0(sb, cb, false, false, false);
} }
@Test//(timeout = 30000) @Test
public void testSimpleEchoWithAdditionalExecutor() throws Throwable { public void testSimpleEchoWithAdditionalExecutor(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable {
testSimpleEchoWithAdditionalExecutor(sb1, cb1);
}
});
} }
public void testSimpleEchoWithAdditionalExecutor(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoWithAdditionalExecutor(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testSimpleEcho0(sb, cb, true, false, true); testSimpleEcho0(sb, cb, true, false, true);
} }
@Test//(timeout = 30000) @Test
public void testSimpleEchoWithAdditionalExecutorNotAutoRead() throws Throwable { public void testSimpleEchoWithAdditionalExecutorNotAutoRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable {
testSimpleEchoWithAdditionalExecutorNotAutoRead(sb1, cb1);
}
});
} }
public void testSimpleEchoWithAdditionalExecutorNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoWithAdditionalExecutorNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testSimpleEcho0(sb, cb, true, false, false); testSimpleEcho0(sb, cb, true, false, false);
} }
@Test//(timeout = 30000) @Test
public void testSimpleEchoWithVoidPromise() throws Throwable { public void testSimpleEchoWithVoidPromise(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable {
testSimpleEchoWithVoidPromise(sb1, cb1);
}
});
} }
public void testSimpleEchoWithVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoWithVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testSimpleEcho0(sb, cb, false, true, true); testSimpleEcho0(sb, cb, false, true, true);
} }
@Test//(timeout = 30000) @Test
public void testSimpleEchoWithVoidPromiseNotAutoRead() throws Throwable { public void testSimpleEchoWithVoidPromiseNotAutoRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable {
testSimpleEchoWithVoidPromiseNotAutoRead(sb1, cb1);
}
});
} }
public void testSimpleEchoWithVoidPromiseNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoWithVoidPromiseNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testSimpleEcho0(sb, cb, false, true, false); testSimpleEcho0(sb, cb, false, true, false);
} }
@Test(timeout = 30000) @Test
public void testSimpleEchoWithAdditionalExecutorAndVoidPromise() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testSimpleEchoWithAdditionalExecutorAndVoidPromise(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap sb1, Bootstrap cb1) throws Throwable {
testSimpleEchoWithAdditionalExecutorAndVoidPromise(sb1, cb1);
}
});
} }
public void testSimpleEchoWithAdditionalExecutorAndVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoWithAdditionalExecutorAndVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -25,19 +25,25 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.TestInfo;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketExceptionHandlingTest extends AbstractSocketTest { public class SocketExceptionHandlingTest extends AbstractSocketTest {
@Test @Test
public void testReadPendingIsResetAfterEachRead() throws Throwable { public void testReadPendingIsResetAfterEachRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testReadPendingIsResetAfterEachRead(serverBootstrap, bootstrap);
}
});
} }
public void testReadPendingIsResetAfterEachRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testReadPendingIsResetAfterEachRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -59,9 +65,9 @@ public class SocketExceptionHandlingTest extends AbstractSocketTest {
assertTrue(serverInitializer.exceptionHandler.latch1.await(5, TimeUnit.SECONDS)); assertTrue(serverInitializer.exceptionHandler.latch1.await(5, TimeUnit.SECONDS));
// After we get the first exception, we should get no more, this is expected to timeout. // After we get the first exception, we should get no more, this is expected to timeout.
assertFalse("Encountered " + serverInitializer.exceptionHandler.count.get() + assertFalse(serverInitializer.exceptionHandler.latch2.await(1, TimeUnit.SECONDS),
" exceptions when 1 was expected", "Encountered " + serverInitializer.exceptionHandler.count.get() +
serverInitializer.exceptionHandler.latch2.await(1, TimeUnit.SECONDS)); " exceptions when 1 was expected");
} finally { } finally {
if (serverChannel != null) { if (serverChannel != null) {
serverChannel.close().syncUninterruptibly(); serverChannel.close().syncUninterruptibly();

View File

@ -29,7 +29,8 @@ import io.netty.channel.FileRegion;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import org.hamcrest.CoreMatchers; import org.hamcrest.CoreMatchers;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -41,7 +42,8 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class SocketFileRegionTest extends AbstractSocketTest { public class SocketFileRegionTest extends AbstractSocketTest {
@ -52,33 +54,63 @@ public class SocketFileRegionTest extends AbstractSocketTest {
} }
@Test @Test
public void testFileRegion() throws Throwable { public void testFileRegion(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testFileRegion(serverBootstrap, bootstrap);
}
});
} }
@Test @Test
public void testCustomFileRegion() throws Throwable { public void testCustomFileRegion(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testCustomFileRegion(serverBootstrap, bootstrap);
}
});
} }
@Test @Test
public void testFileRegionNotAutoRead() throws Throwable { public void testFileRegionNotAutoRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testFileRegionNotAutoRead(serverBootstrap, bootstrap);
}
});
} }
@Test @Test
public void testFileRegionVoidPromise() throws Throwable { public void testFileRegionVoidPromise(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testFileRegionVoidPromise(serverBootstrap, bootstrap);
}
});
} }
@Test @Test
public void testFileRegionVoidPromiseNotAutoRead() throws Throwable { public void testFileRegionVoidPromiseNotAutoRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testFileRegionVoidPromiseNotAutoRead(serverBootstrap, bootstrap);
}
});
} }
@Test @Test
public void testFileRegionCountLargerThenFile() throws Throwable { public void testFileRegionCountLargerThenFile(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testFileRegionCountLargerThenFile(serverBootstrap, bootstrap);
}
});
} }
public void testFileRegion(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testFileRegion(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -25,13 +25,14 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.FixedLengthFrameDecoder; import io.netty.handler.codec.FixedLengthFrameDecoder;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
public class SocketFixedLengthEchoTest extends AbstractSocketTest { public class SocketFixedLengthEchoTest extends AbstractSocketTest {
@ -43,13 +44,23 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest {
} }
@Test @Test
public void testFixedLengthEcho() throws Throwable { public void testFixedLengthEcho(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testFixedLengthEcho(serverBootstrap, bootstrap);
}
});
} }
@Test @Test
public void testFixedLengthEchoNotAutoRead() throws Throwable { public void testFixedLengthEchoNotAutoRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testFixedLengthEchoNotAutoRead(serverBootstrap, bootstrap);
}
});
} }
public void testFixedLengthEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testFixedLengthEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -29,25 +29,24 @@ import io.netty.testsuite.util.TestUtils;
import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.rules.Timeout; import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static io.netty.buffer.Unpooled.compositeBuffer; import static io.netty.buffer.Unpooled.compositeBuffer;
import static io.netty.buffer.Unpooled.wrappedBuffer; import static io.netty.buffer.Unpooled.wrappedBuffer;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketGatheringWriteTest extends AbstractSocketTest { public class SocketGatheringWriteTest extends AbstractSocketTest {
private static final long TIMEOUT = 120000;
@Rule
public final Timeout globalTimeout = new Timeout(120000);
private static final Random random = new Random(); private static final Random random = new Random();
static final byte[] data = new byte[1048576]; static final byte[] data = new byte[1048576];
@ -56,14 +55,20 @@ public class SocketGatheringWriteTest extends AbstractSocketTest {
random.nextBytes(data); random.nextBytes(data);
} }
@AfterClass @AfterAll
public static void compressHeapDumps() throws Exception { public static void compressHeapDumps() throws Exception {
TestUtils.compressHeapDumps(); TestUtils.compressHeapDumps();
} }
@Test @Test
public void testGatheringWrite() throws Throwable { @Timeout(value = TIMEOUT, unit = TimeUnit.MILLISECONDS)
run(); public void testGatheringWrite(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testGatheringWrite(serverBootstrap, bootstrap);
}
});
} }
public void testGatheringWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testGatheringWrite(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -71,8 +76,14 @@ public class SocketGatheringWriteTest extends AbstractSocketTest {
} }
@Test @Test
public void testGatheringWriteNotAutoRead() throws Throwable { @Timeout(value = TIMEOUT, unit = TimeUnit.MILLISECONDS)
run(); public void testGatheringWriteNotAutoRead(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testGatheringWriteNotAutoRead(serverBootstrap, bootstrap);
}
});
} }
public void testGatheringWriteNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testGatheringWriteNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -80,27 +91,45 @@ public class SocketGatheringWriteTest extends AbstractSocketTest {
} }
@Test @Test
public void testGatheringWriteWithComposite() throws Throwable { @Timeout(value = TIMEOUT, unit = TimeUnit.MILLISECONDS)
run(); public void testGatheringWriteWithComposite(TestInfo testInfo) throws Throwable {
} run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void testGatheringWriteWithCompositeNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testGatheringWrite0(sb, cb, data, true, false); testGatheringWriteWithComposite(serverBootstrap, bootstrap);
} }
});
@Test
public void testGatheringWriteWithCompositeNotAutoRead() throws Throwable {
run();
} }
public void testGatheringWriteWithComposite(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testGatheringWriteWithComposite(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testGatheringWrite0(sb, cb, data, true, true); testGatheringWrite0(sb, cb, data, true, true);
} }
@Test
@Timeout(value = TIMEOUT, unit = TimeUnit.MILLISECONDS)
public void testGatheringWriteWithCompositeNotAutoRead(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testGatheringWriteWithCompositeNotAutoRead(serverBootstrap, bootstrap);
}
});
}
public void testGatheringWriteWithCompositeNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testGatheringWrite0(sb, cb, data, true, false);
}
// Test for https://github.com/netty/netty/issues/2647 // Test for https://github.com/netty/netty/issues/2647
@Test @Test
public void testGatheringWriteBig() throws Throwable { @Timeout(value = TIMEOUT, unit = TimeUnit.MILLISECONDS)
run(); public void testGatheringWriteBig(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testGatheringWriteBig(serverBootstrap, bootstrap);
}
});
} }
public void testGatheringWriteBig(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testGatheringWriteBig(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -35,8 +35,9 @@ import io.netty.channel.socket.ChannelOutputShutdownEvent;
import io.netty.channel.socket.DuplexChannel; import io.netty.channel.socket.DuplexChannel;
import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.UncheckedBooleanSupplier;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import org.junit.Assume; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -44,14 +45,21 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
public class SocketHalfClosedTest extends AbstractSocketTest { public class SocketHalfClosedTest extends AbstractSocketTest {
@Test(timeout = 10000) @Test
public void testHalfClosureOnlyOneEventWhenAutoRead() throws Throwable { @Timeout(value = 10000, unit = MILLISECONDS)
run(); public void testHalfClosureOnlyOneEventWhenAutoRead(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testHalfClosureOnlyOneEventWhenAutoRead(serverBootstrap, bootstrap);
}
});
} }
public void testHalfClosureOnlyOneEventWhenAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testHalfClosureOnlyOneEventWhenAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -120,8 +128,13 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
} }
@Test @Test
public void testAllDataReadAfterHalfClosure() throws Throwable { public void testAllDataReadAfterHalfClosure(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAllDataReadAfterHalfClosure(serverBootstrap, bootstrap);
}
});
} }
public void testAllDataReadAfterHalfClosure(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAllDataReadAfterHalfClosure(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -217,8 +230,8 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
serverInitializedLatch.await(); serverInitializedLatch.await();
clientReadAllDataLatch.await(); clientReadAllDataLatch.await();
clientHalfClosedLatch.await(); clientHalfClosedLatch.await();
assertTrue("too many read complete events: " + clientReadCompletes.get(), assertTrue(totalServerBytesWritten / numReadsPerReadLoop + 10 > clientReadCompletes.get(),
totalServerBytesWritten / numReadsPerReadLoop + 10 > clientReadCompletes.get()); "too many read complete events: " + clientReadCompletes.get());
} finally { } finally {
if (clientChannel != null) { if (clientChannel != null) {
clientChannel.close().sync(); clientChannel.close().sync();
@ -230,10 +243,15 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
} }
@Test @Test
public void testAutoCloseFalseDoesShutdownOutput() throws Throwable { public void testAutoCloseFalseDoesShutdownOutput(TestInfo testInfo) throws Throwable {
// This test only works on Linux / BSD / MacOS as we assume some semantics that are not true for Windows. // This test only works on Linux / BSD / MacOS as we assume some semantics that are not true for Windows.
Assume.assumeFalse(PlatformDependent.isWindows()); assumeFalse(PlatformDependent.isWindows());
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAutoCloseFalseDoesShutdownOutput(serverBootstrap, bootstrap);
}
});
} }
public void testAutoCloseFalseDoesShutdownOutput(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAutoCloseFalseDoesShutdownOutput(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -436,8 +454,13 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
} }
@Test @Test
public void testAllDataReadClosure() throws Throwable { public void testAllDataReadClosure(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAllDataReadClosure(serverBootstrap, bootstrap);
}
});
} }
public void testAllDataReadClosure(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAllDataReadClosure(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -537,8 +560,8 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
serverInitializedLatch.await(); serverInitializedLatch.await();
clientReadAllDataLatch.await(); clientReadAllDataLatch.await();
clientHalfClosedLatch.await(); clientHalfClosedLatch.await();
assertTrue("too many read complete events: " + clientReadCompletes.get(), assertTrue(totalServerBytesWritten / numReadsPerReadLoop + 10 > clientReadCompletes.get(),
totalServerBytesWritten / numReadsPerReadLoop + 10 > clientReadCompletes.get()); "too many read complete events: " + clientReadCompletes.get());
} finally { } finally {
if (clientChannel != null) { if (clientChannel != null) {
clientChannel.close().sync(); clientChannel.close().sync();

View File

@ -23,19 +23,28 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.nio.channels.AlreadyConnectedException; import java.nio.channels.AlreadyConnectedException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketMultipleConnectTest extends AbstractSocketTest { public class SocketMultipleConnectTest extends AbstractSocketTest {
@Test(timeout = 30000) @Test
public void testMultipleConnect() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testMultipleConnect(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testMultipleConnect(serverBootstrap, bootstrap);
}
});
} }
public void testMultipleConnect(ServerBootstrap sb, Bootstrap cb) throws Exception { public void testMultipleConnect(ServerBootstrap sb, Bootstrap cb) throws Exception {

View File

@ -25,13 +25,14 @@ import io.netty.channel.ChannelOption;
import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder; import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder; import io.netty.handler.codec.serialization.ObjectEncoder;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
public class SocketObjectEchoTest extends AbstractSocketTest { public class SocketObjectEchoTest extends AbstractSocketTest {
@ -51,8 +52,13 @@ public class SocketObjectEchoTest extends AbstractSocketTest {
} }
@Test @Test
public void testObjectEcho() throws Throwable { public void testObjectEcho(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testObjectEcho(serverBootstrap, bootstrap);
}
});
} }
public void testObjectEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testObjectEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -60,8 +66,13 @@ public class SocketObjectEchoTest extends AbstractSocketTest {
} }
@Test @Test
public void testObjectEchoNotAutoRead() throws Throwable { public void testObjectEchoNotAutoRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testObjectEchoNotAutoRead(serverBootstrap, bootstrap);
}
});
} }
public void testObjectEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testObjectEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -29,20 +29,28 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.RecvByteBufAllocator; import io.netty.channel.RecvByteBufAllocator;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.UncheckedBooleanSupplier;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketReadPendingTest extends AbstractSocketTest { public class SocketReadPendingTest extends AbstractSocketTest {
@Test(timeout = 60000) @Test
public void testReadPendingIsResetAfterEachRead() throws Throwable { @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS)
run(); public void testReadPendingIsResetAfterEachRead(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testReadPendingIsResetAfterEachRead(serverBootstrap, bootstrap);
}
});
} }
public void testReadPendingIsResetAfterEachRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testReadPendingIsResetAfterEachRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -22,27 +22,36 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SocketRstTest extends AbstractSocketTest { public class SocketRstTest extends AbstractSocketTest {
protected void assertRstOnCloseException(IOException cause, Channel clientChannel) { protected void assertRstOnCloseException(IOException cause, Channel clientChannel) {
if (Locale.getDefault() == Locale.US || Locale.getDefault() == Locale.UK) { if (Locale.getDefault() == Locale.US || Locale.getDefault() == Locale.UK) {
assertTrue("actual message: " + cause.getMessage(), assertTrue(cause.getMessage().contains("reset") || cause.getMessage().contains("closed"),
cause.getMessage().contains("reset") || cause.getMessage().contains("closed")); "actual message: " + cause.getMessage());
} }
} }
@Test(timeout = 3000) @Test
public void testSoLingerZeroCausesOnlyRstOnClose() throws Throwable { @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
run(); public void testSoLingerZeroCausesOnlyRstOnClose(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSoLingerZeroCausesOnlyRstOnClose(serverBootstrap, bootstrap);
}
});
} }
public void testSoLingerZeroCausesOnlyRstOnClose(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSoLingerZeroCausesOnlyRstOnClose(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -89,15 +98,21 @@ public class SocketRstTest extends AbstractSocketTest {
// Verify the client received a RST. // Verify the client received a RST.
Throwable cause = throwableRef.get(); Throwable cause = throwableRef.get();
assertTrue("actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]", assertTrue(cause instanceof IOException,
cause instanceof IOException); "actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]");
assertRstOnCloseException((IOException) cause, cc); assertRstOnCloseException((IOException) cause, cc);
} }
@Test(timeout = 3000) @Test
public void testNoRstIfSoLingerOnClose() throws Throwable { @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
run(); public void testNoRstIfSoLingerOnClose(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testNoRstIfSoLingerOnClose(serverBootstrap, bootstrap);
}
});
} }
public void testNoRstIfSoLingerOnClose(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testNoRstIfSoLingerOnClose(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -26,8 +26,10 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.WriteBufferWaterMark; import io.netty.channel.WriteBufferWaterMark;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.oio.OioSocketChannel; import io.netty.channel.socket.oio.OioSocketChannel;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
@ -39,18 +41,24 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.Assume.assumeFalse; import static org.junit.jupiter.api.Assumptions.assumeFalse;
public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest { public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
@Test(timeout = 30000) @Test
public void testShutdownOutput() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testShutdownOutput(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testShutdownOutput(bootstrap);
}
});
} }
public void testShutdownOutput(Bootstrap cb) throws Throwable { public void testShutdownOutput(Bootstrap cb) throws Throwable {
@ -96,9 +104,15 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
} }
} }
@Test(timeout = 30000) @Test
public void testShutdownOutputAfterClosed() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testShutdownOutputAfterClosed(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testShutdownOutputAfterClosed(bootstrap);
}
});
} }
public void testShutdownOutputAfterClosed(Bootstrap cb) throws Throwable { public void testShutdownOutputAfterClosed(Bootstrap cb) throws Throwable {
@ -132,10 +146,16 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
} }
} }
@Ignore @Disabled
@Test(timeout = 30000) @Test
public void testWriteAfterShutdownOutputNoWritabilityChange() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testWriteAfterShutdownOutputNoWritabilityChange(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testWriteAfterShutdownOutputNoWritabilityChange(bootstrap);
}
});
} }
public void testWriteAfterShutdownOutputNoWritabilityChange(Bootstrap cb) throws Throwable { public void testWriteAfterShutdownOutputNoWritabilityChange(Bootstrap cb) throws Throwable {
@ -196,18 +216,30 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
} }
} }
@Test(timeout = 30000) @Test
public void testShutdownOutputSoLingerNoAssertError() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testShutdownOutputSoLingerNoAssertError(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testShutdownOutputSoLingerNoAssertError(bootstrap);
}
});
} }
public void testShutdownOutputSoLingerNoAssertError(Bootstrap cb) throws Throwable { public void testShutdownOutputSoLingerNoAssertError(Bootstrap cb) throws Throwable {
testShutdownSoLingerNoAssertError0(cb, true); testShutdownSoLingerNoAssertError0(cb, true);
} }
@Test(timeout = 30000) @Test
public void testShutdownSoLingerNoAssertError() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testShutdownSoLingerNoAssertError(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testShutdownSoLingerNoAssertError(bootstrap);
}
});
} }
public void testShutdownSoLingerNoAssertError(Bootstrap cb) throws Throwable { public void testShutdownSoLingerNoAssertError(Bootstrap cb) throws Throwable {

View File

@ -28,10 +28,13 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.spdy.SpdyFrameCodec; import io.netty.handler.codec.spdy.SpdyFrameCodec;
import io.netty.handler.codec.spdy.SpdyVersion; import io.netty.handler.codec.spdy.SpdyVersion;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -143,9 +146,15 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
return frames; return frames;
} }
@Test(timeout = 15000) @Test
public void testSpdyEcho() throws Throwable { @Timeout(value = 15000, unit = TimeUnit.MILLISECONDS)
run(); public void testSpdyEcho(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSpdyEcho(serverBootstrap, bootstrap);
}
});
} }
public void testSpdyEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSpdyEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -153,9 +162,15 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
testSpdyEcho(sb, cb, SpdyVersion.SPDY_3_1, true); testSpdyEcho(sb, cb, SpdyVersion.SPDY_3_1, true);
} }
@Test(timeout = 15000) @Test
public void testSpdyEchoNotAutoRead() throws Throwable { @Timeout(value = 15000, unit = TimeUnit.MILLISECONDS)
run(); public void testSpdyEchoNotAutoRead(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSpdyEchoNotAutoRead(serverBootstrap, bootstrap);
}
});
} }
public void testSpdyEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSpdyEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -35,11 +35,11 @@ import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Assume; import org.junit.jupiter.api.TestInfo;
import org.junit.Test; import org.junit.jupiter.api.Timeout;
import org.junit.runner.RunWith; import org.junit.jupiter.api.condition.DisabledIf;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runners.Parameterized.Parameters; import org.junit.jupiter.params.provider.MethodSource;
import java.io.File; import java.io.File;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
@ -50,17 +50,18 @@ import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@RunWith(Parameterized.class)
public class SocketSslClientRenegotiateTest extends AbstractSocketTest { public class SocketSslClientRenegotiateTest extends AbstractSocketTest {
private static final InternalLogger logger = InternalLoggerFactory.getInstance( private static final InternalLogger logger = InternalLoggerFactory.getInstance(
SocketSslClientRenegotiateTest.class); SocketSslClientRenegotiateTest.class);
private static final File CERT_FILE; private static final File CERT_FILE;
@ -77,7 +78,10 @@ public class SocketSslClientRenegotiateTest extends AbstractSocketTest {
KEY_FILE = ssc.privateKey(); KEY_FILE = ssc.privateKey();
} }
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}, delegate = {2}") private static boolean openSslNotAvailable() {
return !OpenSsl.isAvailable();
}
public static Collection<Object[]> data() throws Exception { public static Collection<Object[]> data() throws Exception {
List<SslContext> serverContexts = new ArrayList<SslContext>(); List<SslContext> serverContexts = new ArrayList<SslContext>();
List<SslContext> clientContexts = new ArrayList<SslContext>(); List<SslContext> clientContexts = new ArrayList<SslContext>();
@ -104,10 +108,6 @@ public class SocketSslClientRenegotiateTest extends AbstractSocketTest {
return params; return params;
} }
private final SslContext serverCtx;
private final SslContext clientCtx;
private final boolean delegate;
private final AtomicReference<Throwable> clientException = new AtomicReference<Throwable>(); private final AtomicReference<Throwable> clientException = new AtomicReference<Throwable>();
private final AtomicReference<Throwable> serverException = new AtomicReference<Throwable>(); private final AtomicReference<Throwable> serverException = new AtomicReference<Throwable>();
@ -121,19 +121,21 @@ public class SocketSslClientRenegotiateTest extends AbstractSocketTest {
private final TestHandler serverHandler = new TestHandler(serverException); private final TestHandler serverHandler = new TestHandler(serverException);
public SocketSslClientRenegotiateTest( @DisabledIf("openSslNotAvailable")
SslContext serverCtx, SslContext clientCtx, boolean delegate) { @ParameterizedTest(name = "{index}: serverEngine = {0}, clientEngine = {1}, delegate = {2}")
this.serverCtx = serverCtx; @MethodSource("data")
this.clientCtx = clientCtx; @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
this.delegate = delegate; public void testSslRenegotiationRejected(final SslContext serverCtx, final SslContext clientCtx,
} final boolean delegate, TestInfo testInfo) throws Throwable {
@Test(timeout = 30000)
public void testSslRenegotiationRejected() throws Throwable {
// BoringSSL does not support renegotiation intentionally. // BoringSSL does not support renegotiation intentionally.
Assume.assumeFalse("BoringSSL".equals(OpenSsl.versionString())); assumeFalse("BoringSSL".equals(OpenSsl.versionString()));
Assume.assumeTrue(OpenSsl.isAvailable()); assumeTrue(OpenSsl.isAvailable());
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSslRenegotiationRejected(sb, cb, serverCtx, clientCtx, delegate);
}
});
} }
private static SslHandler newSslHandler(SslContext sslCtx, ByteBufAllocator allocator, Executor executor) { private static SslHandler newSslHandler(SslContext sslCtx, ByteBufAllocator allocator, Executor executor) {
@ -144,7 +146,8 @@ public class SocketSslClientRenegotiateTest extends AbstractSocketTest {
} }
} }
public void testSslRenegotiationRejected(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSslRenegotiationRejected(ServerBootstrap sb, Bootstrap cb, final SslContext serverCtx,
final SslContext clientCtx, boolean delegate) throws Throwable {
reset(); reset();
final ExecutorService executorService = delegate ? Executors.newCachedThreadPool() : null; final ExecutorService executorService = delegate ? Executors.newCachedThreadPool() : null;

View File

@ -40,11 +40,11 @@ import io.netty.testsuite.util.TestUtils;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Timeout;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runners.Parameterized.Parameters; import org.junit.jupiter.params.provider.MethodSource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -56,6 +56,7 @@ import java.util.Random;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -66,10 +67,9 @@ import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
@RunWith(Parameterized.class)
public class SocketSslEchoTest extends AbstractSocketTest { public class SocketSslEchoTest extends AbstractSocketTest {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketSslEchoTest.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketSslEchoTest.class);
@ -120,10 +120,6 @@ public class SocketSslEchoTest extends AbstractSocketTest {
} }
} }
@Parameters(name =
"{index}: serverEngine = {0}, clientEngine = {1}, renegotiation = {2}, " +
"serverUsesDelegatedTaskExecutor = {3}, clientUsesDelegatedTaskExecutor = {4}, " +
"autoRead = {5}, useChunkedWriteHandler = {6}, useCompositeByteBuf = {7}")
public static Collection<Object[]> data() throws Exception { public static Collection<Object[]> data() throws Exception {
List<SslContext> serverContexts = new ArrayList<SslContext>(); List<SslContext> serverContexts = new ArrayList<SslContext>();
serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE) serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE)
@ -194,18 +190,8 @@ public class SocketSslEchoTest extends AbstractSocketTest {
return params; return params;
} }
private final SslContext serverCtx;
private final SslContext clientCtx;
private final Renegotiation renegotiation;
private final boolean serverUsesDelegatedTaskExecutor;
private final boolean clientUsesDelegatedTaskExecutor;
private final boolean autoRead;
private final boolean useChunkedWriteHandler;
private final boolean useCompositeByteBuf;
private final AtomicReference<Throwable> clientException = new AtomicReference<Throwable>(); private final AtomicReference<Throwable> clientException = new AtomicReference<Throwable>();
private final AtomicReference<Throwable> serverException = new AtomicReference<Throwable>(); private final AtomicReference<Throwable> serverException = new AtomicReference<Throwable>();
private final AtomicInteger clientSendCounter = new AtomicInteger(); private final AtomicInteger clientSendCounter = new AtomicInteger();
private final AtomicInteger clientRecvCounter = new AtomicInteger(); private final AtomicInteger clientRecvCounter = new AtomicInteger();
private final AtomicInteger serverRecvCounter = new AtomicInteger(); private final AtomicInteger serverRecvCounter = new AtomicInteger();
@ -225,10 +211,31 @@ public class SocketSslEchoTest extends AbstractSocketTest {
private final EchoServerHandler serverHandler = private final EchoServerHandler serverHandler =
new EchoServerHandler(serverRecvCounter, serverNegoCounter, serverException); new EchoServerHandler(serverRecvCounter, serverNegoCounter, serverException);
public SocketSslEchoTest( private SslContext serverCtx;
private SslContext clientCtx;
private Renegotiation renegotiation;
private boolean serverUsesDelegatedTaskExecutor;
private boolean clientUsesDelegatedTaskExecutor;
private boolean autoRead;
private boolean useChunkedWriteHandler;
private boolean useCompositeByteBuf;
@AfterAll
public static void compressHeapDumps() throws Exception {
TestUtils.compressHeapDumps();
}
@ParameterizedTest(name =
"{index}: serverEngine = {0}, clientEngine = {1}, renegotiation = {2}, " +
"serverUsesDelegatedTaskExecutor = {3}, clientUsesDelegatedTaskExecutor = {4}, " +
"autoRead = {5}, useChunkedWriteHandler = {6}, useCompositeByteBuf = {7}")
@MethodSource("data")
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void testSslEcho(
SslContext serverCtx, SslContext clientCtx, Renegotiation renegotiation, SslContext serverCtx, SslContext clientCtx, Renegotiation renegotiation,
boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor, boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor,
boolean autoRead, boolean useChunkedWriteHandler, boolean useCompositeByteBuf) { boolean autoRead, boolean useChunkedWriteHandler, boolean useCompositeByteBuf,
TestInfo testInfo) throws Throwable {
this.serverCtx = serverCtx; this.serverCtx = serverCtx;
this.clientCtx = clientCtx; this.clientCtx = clientCtx;
this.serverUsesDelegatedTaskExecutor = serverUsesDelegatedTaskExecutor; this.serverUsesDelegatedTaskExecutor = serverUsesDelegatedTaskExecutor;
@ -237,16 +244,12 @@ public class SocketSslEchoTest extends AbstractSocketTest {
this.autoRead = autoRead; this.autoRead = autoRead;
this.useChunkedWriteHandler = useChunkedWriteHandler; this.useChunkedWriteHandler = useChunkedWriteHandler;
this.useCompositeByteBuf = useCompositeByteBuf; this.useCompositeByteBuf = useCompositeByteBuf;
} run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
@Test(timeout = 30000) public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
public void testSslEcho() throws Throwable { testSslEcho(serverBootstrap, bootstrap);
run(); }
} });
@AfterClass
public static void compressHeapDumps() throws Exception {
TestUtils.compressHeapDumps();
} }
public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -36,10 +36,10 @@ import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Timeout;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runners.Parameterized.Parameters; import org.junit.jupiter.params.provider.MethodSource;
import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
@ -53,13 +53,13 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
@RunWith(Parameterized.class)
public class SocketSslGreetingTest extends AbstractSocketTest { public class SocketSslGreetingTest extends AbstractSocketTest {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketSslGreetingTest.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketSslGreetingTest.class);
@ -79,7 +79,6 @@ public class SocketSslGreetingTest extends AbstractSocketTest {
KEY_FILE = ssc.privateKey(); KEY_FILE = ssc.privateKey();
} }
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}, delegate = {2}")
public static Collection<Object[]> data() throws Exception { public static Collection<Object[]> data() throws Exception {
List<SslContext> serverContexts = new ArrayList<SslContext>(); List<SslContext> serverContexts = new ArrayList<SslContext>();
serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.JDK).build()); serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.JDK).build());
@ -107,16 +106,6 @@ public class SocketSslGreetingTest extends AbstractSocketTest {
return params; return params;
} }
private final SslContext serverCtx;
private final SslContext clientCtx;
private final boolean delegate;
public SocketSslGreetingTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
this.serverCtx = serverCtx;
this.clientCtx = clientCtx;
this.delegate = delegate;
}
private static SslHandler newSslHandler(SslContext sslCtx, ByteBufAllocator allocator, Executor executor) { private static SslHandler newSslHandler(SslContext sslCtx, ByteBufAllocator allocator, Executor executor) {
if (executor == null) { if (executor == null) {
return sslCtx.newHandler(allocator); return sslCtx.newHandler(allocator);
@ -126,12 +115,21 @@ public class SocketSslGreetingTest extends AbstractSocketTest {
} }
// Test for https://github.com/netty/netty/pull/2437 // Test for https://github.com/netty/netty/pull/2437
@Test(timeout = 30000) @ParameterizedTest(name = "{index}: serverEngine = {0}, clientEngine = {1}, delegate = {2}")
public void testSslGreeting() throws Throwable { @MethodSource("data")
run(); @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void testSslGreeting(final SslContext serverCtx, final SslContext clientCtx, final boolean delegate,
TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSslGreeting(sb, cb, serverCtx, clientCtx, delegate);
}
});
} }
public void testSslGreeting(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSslGreeting(ServerBootstrap sb, Bootstrap cb, final SslContext serverCtx,
final SslContext clientCtx, boolean delegate) throws Throwable {
final ServerHandler sh = new ServerHandler(); final ServerHandler sh = new ServerHandler();
final ClientHandler ch = new ClientHandler(); final ClientHandler ch = new ClientHandler();

View File

@ -34,10 +34,10 @@ import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Timeout;
import org.junit.runners.Parameterized; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runners.Parameterized.Parameters; import org.junit.jupiter.params.provider.MethodSource;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSessionContext; import javax.net.ssl.SSLSessionContext;
@ -51,11 +51,11 @@ import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
@RunWith(Parameterized.class)
public class SocketSslSessionReuseTest extends AbstractSocketTest { public class SocketSslSessionReuseTest extends AbstractSocketTest {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketSslSessionReuseTest.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketSslSessionReuseTest.class);
@ -74,7 +74,6 @@ public class SocketSslSessionReuseTest extends AbstractSocketTest {
KEY_FILE = ssc.privateKey(); KEY_FILE = ssc.privateKey();
} }
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception { public static Collection<Object[]> data() throws Exception {
return Collections.singletonList(new Object[] { return Collections.singletonList(new Object[] {
new JdkSslServerContext(CERT_FILE, KEY_FILE), new JdkSslServerContext(CERT_FILE, KEY_FILE),
@ -82,20 +81,21 @@ public class SocketSslSessionReuseTest extends AbstractSocketTest {
}); });
} }
private final SslContext serverCtx; @ParameterizedTest(name = "{index}: serverEngine = {0}, clientEngine = {1}")
private final SslContext clientCtx; @MethodSource("data")
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public SocketSslSessionReuseTest(SslContext serverCtx, SslContext clientCtx) { public void testSslSessionReuse(final SslContext serverCtx, final SslContext clientCtx, TestInfo testInfo)
this.serverCtx = serverCtx; throws Throwable {
this.clientCtx = clientCtx; run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSslSessionReuse(sb, cb, serverCtx, clientCtx);
}
});
} }
@Test(timeout = 30000) public void testSslSessionReuse(ServerBootstrap sb, Bootstrap cb,
public void testSslSessionReuse() throws Throwable { final SslContext serverCtx, final SslContext clientCtx) throws Throwable {
run();
}
public void testSslSessionReuse(ServerBootstrap sb, Bootstrap cb) throws Throwable {
final ReadAndDiscardHandler sh = new ReadAndDiscardHandler(true, true); final ReadAndDiscardHandler sh = new ReadAndDiscardHandler(true, true);
final ReadAndDiscardHandler ch = new ReadAndDiscardHandler(false, true); final ReadAndDiscardHandler ch = new ReadAndDiscardHandler(false, true);
final String[] protocols = { "TLSv1", "TLSv1.1", "TLSv1.2" }; final String[] protocols = { "TLSv1", "TLSv1.1", "TLSv1.2" };
@ -139,7 +139,7 @@ public class SocketSslSessionReuseTest extends AbstractSocketTest {
cc = cb.connect(sc.localAddress()).sync().channel(); cc = cb.connect(sc.localAddress()).sync().channel();
cc.writeAndFlush(msg).sync(); cc.writeAndFlush(msg).sync();
cc.closeFuture().sync(); cc.closeFuture().sync();
assertEquals("Expected no new sessions", sessions, sessionIdSet(clientSessionCtx.getIds())); assertEquals(sessions, sessionIdSet(clientSessionCtx.getIds()), "Expected no new sessions");
rethrowHandlerExceptions(sh, ch); rethrowHandlerExceptions(sh, ch);
} finally { } finally {
sc.close().awaitUninterruptibly(); sc.close().awaitUninterruptibly();

View File

@ -40,12 +40,13 @@ import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Test; import org.junit.jupiter.api.BeforeAll;
import org.junit.runner.RunWith; import org.junit.jupiter.api.TestInfo;
import org.junit.runners.Parameterized; import org.junit.jupiter.api.Timeout;
import org.junit.runners.Parameterized.Parameters; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import java.io.File; import java.io.File;
@ -54,12 +55,15 @@ import java.security.cert.CertificateException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
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.assertTrue;
@RunWith(Parameterized.class)
public class SocketStartTlsTest extends AbstractSocketTest { public class SocketStartTlsTest extends AbstractSocketTest {
private static final String PARAMETERIZED_NAME = "{index}: serverEngine = {0}, clientEngine = {1}";
private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketStartTlsTest.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(SocketStartTlsTest.class);
@ -79,7 +83,6 @@ public class SocketStartTlsTest extends AbstractSocketTest {
KEY_FILE = ssc.privateKey(); KEY_FILE = ssc.privateKey();
} }
@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception { public static Collection<Object[]> data() throws Exception {
List<SslContext> serverContexts = new ArrayList<SslContext>(); List<SslContext> serverContexts = new ArrayList<SslContext>();
serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.JDK).build()); serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.JDK).build());
@ -106,43 +109,54 @@ public class SocketStartTlsTest extends AbstractSocketTest {
return params; return params;
} }
@BeforeClass @BeforeAll
public static void createExecutor() { public static void createExecutor() {
executor = new DefaultEventExecutorGroup(2); executor = new DefaultEventExecutorGroup(2);
} }
@AfterClass @AfterAll
public static void shutdownExecutor() throws Exception { public static void shutdownExecutor() throws Exception {
executor.shutdownGracefully().sync(); executor.shutdownGracefully().sync();
} }
private final SslContext serverCtx; @ParameterizedTest(name = PARAMETERIZED_NAME)
private final SslContext clientCtx; @MethodSource("data")
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public SocketStartTlsTest(SslContext serverCtx, SslContext clientCtx) { public void testStartTls(final SslContext serverCtx, final SslContext clientCtx, TestInfo testInfo)
this.serverCtx = serverCtx; throws Throwable {
this.clientCtx = clientCtx; run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testStartTls(sb, cb, serverCtx, clientCtx);
}
});
} }
@Test(timeout = 30000) public void testStartTls(ServerBootstrap sb, Bootstrap cb,
public void testStartTls() throws Throwable { SslContext serverCtx, SslContext clientCtx) throws Throwable {
run(); testStartTls(sb, cb, serverCtx, clientCtx, true);
} }
public void testStartTls(ServerBootstrap sb, Bootstrap cb) throws Throwable { @ParameterizedTest(name = PARAMETERIZED_NAME)
testStartTls(sb, cb, true); @MethodSource("data")
@Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
public void testStartTlsNotAutoRead(final SslContext serverCtx, final SslContext clientCtx,
TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testStartTlsNotAutoRead(sb, cb, serverCtx, clientCtx);
}
});
} }
@Test(timeout = 30000) public void testStartTlsNotAutoRead(ServerBootstrap sb, Bootstrap cb,
public void testStartTlsNotAutoRead() throws Throwable { SslContext serverCtx, SslContext clientCtx) throws Throwable {
run(); testStartTls(sb, cb, serverCtx, clientCtx, false);
} }
public void testStartTlsNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { private void testStartTls(ServerBootstrap sb, Bootstrap cb,
testStartTls(sb, cb, false); SslContext serverCtx, SslContext clientCtx, boolean autoRead) throws Throwable {
}
private void testStartTls(ServerBootstrap sb, Bootstrap cb, boolean autoRead) throws Throwable {
sb.childOption(ChannelOption.AUTO_READ, autoRead); sb.childOption(ChannelOption.AUTO_READ, autoRead);
cb.option(ChannelOption.AUTO_READ, autoRead); cb.option(ChannelOption.AUTO_READ, autoRead);

View File

@ -29,10 +29,13 @@ import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
public class SocketStringEchoTest extends AbstractSocketTest { public class SocketStringEchoTest extends AbstractSocketTest {
@ -52,18 +55,30 @@ public class SocketStringEchoTest extends AbstractSocketTest {
} }
} }
@Test(timeout = 60000) @Test
public void testStringEcho() throws Throwable { @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS)
run(); public void testStringEcho(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testStringEcho(serverBootstrap, bootstrap);
}
});
} }
public void testStringEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testStringEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
testStringEcho(sb, cb, true); testStringEcho(sb, cb, true);
} }
@Test(timeout = 60000) @Test
public void testStringEchoNotAutoRead() throws Throwable { @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS)
run(); public void testStringEchoNotAutoRead(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testStringEchoNotAutoRead(serverBootstrap, bootstrap);
}
});
} }
public void testStringEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testStringEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -30,9 +30,11 @@ import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -42,7 +44,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertTrue;
public class TrafficShapingHandlerTest extends AbstractSocketTest { public class TrafficShapingHandlerTest extends AbstractSocketTest {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(TrafficShapingHandlerTest.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(TrafficShapingHandlerTest.class);
@ -70,7 +72,7 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
random.nextBytes(data); random.nextBytes(data);
} }
@BeforeClass @BeforeAll
public static void createGroup() { public static void createGroup() {
logger.info("Bandwidth: " + minfactor + " <= " + bandwidthFactor + " <= " + maxfactor + logger.info("Bandwidth: " + minfactor + " <= " + bandwidthFactor + " <= " + maxfactor +
" StepMs: " + stepms + " MinMs: " + minimalms + " CheckMs: " + check); " StepMs: " + stepms + " MinMs: " + minimalms + " CheckMs: " + check);
@ -78,7 +80,7 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
groupForGlobal = new DefaultEventExecutorGroup(8); groupForGlobal = new DefaultEventExecutorGroup(8);
} }
@AfterClass @AfterAll
public static void destroyGroup() throws Exception { public static void destroyGroup() throws Exception {
group.shutdownGracefully().sync(); group.shutdownGracefully().sync();
groupForGlobal.shutdownGracefully().sync(); groupForGlobal.shutdownGracefully().sync();
@ -127,11 +129,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
return minimalWaitBetween; return minimalWaitBetween;
} }
@Test(timeout = 10000) @Test
public void testNoTrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testNoTrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST NO TRAFFIC"; currentTestName = "TEST NO TRAFFIC";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testNoTrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testNoTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testNoTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -141,11 +149,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, false, false, false, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, false, false, false, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testWriteTrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testWriteTrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST WRITE"; currentTestName = "TEST WRITE";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testWriteTrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testWriteTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testWriteTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -155,11 +169,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, false, true, false, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, false, true, false, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testReadTrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testReadTrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST READ"; currentTestName = "TEST READ";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testReadTrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testReadTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testReadTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -169,11 +189,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, true, false, false, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, true, false, false, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testWrite1TrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testWrite1TrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST WRITE"; currentTestName = "TEST WRITE";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testWrite1TrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testWrite1TrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testWrite1TrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -183,11 +209,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, false, true, false, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, false, true, false, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testRead1TrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testRead1TrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST READ"; currentTestName = "TEST READ";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testRead1TrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testRead1TrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testRead1TrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -197,11 +229,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, true, false, false, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, true, false, false, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testWriteGlobalTrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testWriteGlobalTrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST GLOBAL WRITE"; currentTestName = "TEST GLOBAL WRITE";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testWriteGlobalTrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testWriteGlobalTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testWriteGlobalTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -211,11 +249,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, false, true, true, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, false, true, true, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testReadGlobalTrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testReadGlobalTrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST GLOBAL READ"; currentTestName = "TEST GLOBAL READ";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testReadGlobalTrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testReadGlobalTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testReadGlobalTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -225,11 +269,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, true, false, true, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, true, false, true, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testAutoReadTrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testAutoReadTrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST AUTO READ"; currentTestName = "TEST AUTO READ";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAutoReadTrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testAutoReadTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAutoReadTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -240,11 +290,17 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
testTrafficShapping0(sb, cb, false, true, false, false, autoRead, minimalWaitBetween, multipleMessage); testTrafficShapping0(sb, cb, false, true, false, false, autoRead, minimalWaitBetween, multipleMessage);
} }
@Test(timeout = 10000) @Test
public void testAutoReadGlobalTrafficShapping() throws Throwable { @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testAutoReadGlobalTrafficShapping(TestInfo testInfo) throws Throwable {
currentTestName = "TEST AUTO READ GLOBAL"; currentTestName = "TEST AUTO READ GLOBAL";
currentTestRun = 0; currentTestRun = 0;
run(); run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testAutoReadGlobalTrafficShapping(serverBootstrap, bootstrap);
}
});
} }
public void testAutoReadGlobalTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testAutoReadGlobalTrafficShapping(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -339,7 +395,7 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
promise.await(); promise.await();
Long stop = TrafficCounter.milliSecondFromNano(); Long stop = TrafficCounter.milliSecondFromNano();
assertTrue("Error during execution of TrafficShapping: " + promise.cause(), promise.isSuccess()); assertTrue(promise.isSuccess(), "Error during execution of TrafficShapping: " + promise.cause());
float average = (totalNb * messageSize) / (float) (stop - start); float average = (totalNb * messageSize) / (float) (stop - start);
logger.info("TEST: " + currentTestName + " RUN: " + currentTestRun + logger.info("TEST: " + currentTestName + " RUN: " + currentTestRun +
@ -353,14 +409,14 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
} }
if (autoRead == null && minimalWaitBetween != null) { if (autoRead == null && minimalWaitBetween != null) {
assertTrue("Overall Traffic not ok since > " + maxfactor + ": " + average, assertTrue(average <= maxfactor,
average <= maxfactor); "Overall Traffic not ok since > " + maxfactor + ": " + average);
if (additionalExecutor) { if (additionalExecutor) {
// Oio is not as good when using additionalExecutor // Oio is not as good when using additionalExecutor
assertTrue("Overall Traffic not ok since < 0.25: " + average, average >= 0.25); assertTrue(average >= 0.25, "Overall Traffic not ok since < 0.25: " + average);
} else { } else {
assertTrue("Overall Traffic not ok since < " + minfactor + ": " + average, assertTrue(average >= minfactor,
average >= minfactor); "Overall Traffic not ok since < " + minfactor + ": " + average);
} }
} }
if (handler != null && globalLimit) { if (handler != null && globalLimit) {
@ -426,8 +482,8 @@ public class TrafficShapingHandlerTest extends AbstractSocketTest {
} }
loggerClient.info("Step: " + step + " Interval: " + (lastTimestamp - currentLastTime) + " compareTo " loggerClient.info("Step: " + step + " Interval: " + (lastTimestamp - currentLastTime) + " compareTo "
+ minimalWait + " (" + ar + ')'); + minimalWait + " (" + ar + ')');
assertTrue("The interval of time is incorrect:" + (lastTimestamp - currentLastTime) + " not> " assertTrue(lastTimestamp - currentLastTime >= minimalWait,
+ minimalWait, lastTimestamp - currentLastTime >= minimalWait); "The interval of time is incorrect:" + (lastTimestamp - currentLastTime) + " not> " + minimalWait);
currentLastTime = lastTimestamp; currentLastTime = lastTimestamp;
step++; step++;
if (multipleMessage.length > step) { if (multipleMessage.length > step) {

View File

@ -20,13 +20,23 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.TimeUnit;
public class WriteBeforeRegisteredTest extends AbstractClientSocketTest { public class WriteBeforeRegisteredTest extends AbstractClientSocketTest {
@Test(timeout = 30000) @Test
public void testWriteBeforeConnect() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testWriteBeforeConnect(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<Bootstrap>() {
@Override
public void run(Bootstrap bootstrap) throws Throwable {
testWriteBeforeConnect(bootstrap);
}
});
} }
public void testWriteBeforeConnect(Bootstrap cb) throws Throwable { public void testWriteBeforeConnect(Bootstrap cb) throws Throwable {

View File

@ -36,16 +36,18 @@ import io.netty.util.NetUtil;
import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import org.junit.Assume; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
/** /**
* Verify UDT connect/disconnect life cycle. * Verify UDT connect/disconnect life cycle.
@ -336,10 +338,10 @@ public class UDTClientServerConnectionTest {
static final int WAIT_COUNT = 50; static final int WAIT_COUNT = 50;
static final int WAIT_SLEEP = 100; static final int WAIT_SLEEP = 100;
@BeforeClass @BeforeAll
public static void assumeUdt() { public static void assumeUdt() {
Assume.assumeTrue("com.barchart.udt.SocketUDT can not be loaded and initialized", canLoadAndInit()); assumeTrue(canLoadAndInit(), "com.barchart.udt.SocketUDT can not be loaded and initialized");
Assume.assumeFalse("Not supported on J9 JVM", PlatformDependent.isJ9Jvm()); assumeFalse(PlatformDependent.isJ9Jvm(), "Not supported on J9 JVM");
} }
private static boolean canLoadAndInit() { private static boolean canLoadAndInit() {
@ -377,7 +379,7 @@ public class UDTClientServerConnectionTest {
server.waitForActive(true); server.waitForActive(true);
log.info("Verify connection is active."); log.info("Verify connection is active.");
assertEquals("group must have one", 1, server.group.size()); assertEquals(1, server.group.size(), "group must have one");
log.info("Stopping client."); log.info("Stopping client.");
client.shutdown(); client.shutdown();
@ -389,7 +391,7 @@ public class UDTClientServerConnectionTest {
server.waitForActive(false); server.waitForActive(false);
log.info("Verify connection is inactive."); log.info("Verify connection is inactive.");
assertEquals("group must be empty", 0, server.group.size()); assertEquals(0, server.group.size(), "group must be empty");
log.info("Stopping server."); log.info("Stopping server.");
server.shutdown(); server.shutdown();

View File

@ -17,8 +17,10 @@ package io.netty.testsuite.util;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.jupiter.api.TestInfo;
import org.junit.rules.TestName; import org.junit.rules.TestName;
import org.tukaani.xz.LZMA2Options; import org.tukaani.xz.LZMA2Options;
import org.tukaani.xz.XZOutputStream; import org.tukaani.xz.XZOutputStream;
@ -38,6 +40,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import javax.management.MBeanServer; import javax.management.MBeanServer;
public final class TestUtils { public final class TestUtils {
@ -100,6 +103,23 @@ public final class TestUtils {
return false; return false;
} }
/**
* Returns the method name of the current test.
*/
@SuppressJava6Requirement(reason = "Test only")
public static String testMethodName(TestInfo testInfo) {
String testMethodName = testInfo.getTestMethod().map(new Function<Method, String>() {
@Override
public String apply(Method method) {
return method.getName();
}
}).orElse("[unknown method]");
if (testMethodName.contains("[")) {
testMethodName = testMethodName.substring(0, testMethodName.indexOf('['));
}
return testMethodName;
}
/** /**
* Returns the method name of the current test. * Returns the method name of the current test.
*/ */

View File

@ -16,9 +16,10 @@
package io.netty.channel.epoll; package io.netty.channel.epoll;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import org.junit.Test;
import static org.junit.Assert.fail; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class EpollChannelConfigTest { public class EpollChannelConfigTest {

View File

@ -15,9 +15,10 @@
*/ */
package io.netty.channel.epoll; package io.netty.channel.epoll;
import org.junit.Test;
import static org.junit.Assert.assertTrue; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollDatagramChannelConfigTest { public class EpollDatagramChannelConfigTest {

View File

@ -22,23 +22,23 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.InternetProtocolFamily; import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.channel.unix.Socket; import io.netty.channel.unix.Socket;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import static io.netty.util.NetUtil.LOCALHOST; import static io.netty.util.NetUtil.LOCALHOST;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollDatagramChannelTest { public class EpollDatagramChannelTest {
@Before @BeforeEach
public void setUp() { public void setUp() {
Epoll.ensureAvailability(); Epoll.ensureAvailability();
} }

View File

@ -26,9 +26,9 @@ import io.netty.channel.socket.DatagramPacket;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.AbstractDatagramTest; import io.netty.testsuite.transport.socket.AbstractDatagramTest;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import org.junit.Assume; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
@ -38,16 +38,17 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class EpollDatagramScatteringReadTest extends AbstractDatagramTest { public class EpollDatagramScatteringReadTest extends AbstractDatagramTest {
@BeforeClass @BeforeAll
public static void assumeRecvmmsgSupported() { public static void assumeRecvmmsgSupported() {
Assume.assumeTrue(Native.IS_SUPPORTING_RECVMMSG); assumeTrue(Native.IS_SUPPORTING_RECVMMSG);
} }
@Override @Override
@ -56,8 +57,13 @@ public class EpollDatagramScatteringReadTest extends AbstractDatagramTest {
} }
@Test @Test
public void testScatteringReadPartial() throws Throwable { public void testScatteringReadPartial(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testScatteringReadPartial(bootstrap, bootstrap2);
}
});
} }
public void testScatteringReadPartial(Bootstrap sb, Bootstrap cb) throws Throwable { public void testScatteringReadPartial(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -65,8 +71,13 @@ public class EpollDatagramScatteringReadTest extends AbstractDatagramTest {
} }
@Test @Test
public void testScatteringRead() throws Throwable { public void testScatteringRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testScatteringRead(bootstrap, bootstrap2);
}
});
} }
public void testScatteringRead(Bootstrap sb, Bootstrap cb) throws Throwable { public void testScatteringRead(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -74,8 +85,13 @@ public class EpollDatagramScatteringReadTest extends AbstractDatagramTest {
} }
@Test @Test
public void testScatteringReadConnectedPartial() throws Throwable { public void testScatteringReadConnectedPartial(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testScatteringReadConnectedPartial(bootstrap, bootstrap2);
}
});
} }
public void testScatteringReadConnectedPartial(Bootstrap sb, Bootstrap cb) throws Throwable { public void testScatteringReadConnectedPartial(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -83,8 +99,13 @@ public class EpollDatagramScatteringReadTest extends AbstractDatagramTest {
} }
@Test @Test
public void testScatteringConnectedRead() throws Throwable { public void testScatteringConnectedRead(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testScatteringConnectedRead(bootstrap, bootstrap2);
}
});
} }
public void testScatteringConnectedRead(Bootstrap sb, Bootstrap cb) throws Throwable { public void testScatteringConnectedRead(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -186,8 +207,13 @@ public class EpollDatagramScatteringReadTest extends AbstractDatagramTest {
} }
@Test @Test
public void testScatteringReadWithSmallBuffer() throws Throwable { public void testScatteringReadWithSmallBuffer(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testScatteringReadWithSmallBuffer(bootstrap, bootstrap2);
}
});
} }
public void testScatteringReadWithSmallBuffer(Bootstrap sb, Bootstrap cb) throws Throwable { public void testScatteringReadWithSmallBuffer(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -195,8 +221,13 @@ public class EpollDatagramScatteringReadTest extends AbstractDatagramTest {
} }
@Test @Test
public void testScatteringConnectedReadWithSmallBuffer() throws Throwable { public void testScatteringConnectedReadWithSmallBuffer(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testScatteringConnectedReadWithSmallBuffer(bootstrap, bootstrap2);
}
});
} }
public void testScatteringConnectedReadWithSmallBuffer(Bootstrap sb, Bootstrap cb) throws Throwable { public void testScatteringConnectedReadWithSmallBuffer(Bootstrap sb, Bootstrap cb) throws Throwable {

View File

@ -28,8 +28,8 @@ import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.InternetProtocolFamily; import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.DatagramUnicastTest; import io.netty.testsuite.transport.socket.DatagramUnicastTest;
import org.junit.Assume; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
@ -37,8 +37,9 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class EpollDatagramUnicastTest extends DatagramUnicastTest { public class EpollDatagramUnicastTest extends DatagramUnicastTest {
@Override @Override
@ -54,8 +55,13 @@ public class EpollDatagramUnicastTest extends DatagramUnicastTest {
} }
@Test @Test
public void testSendSegmentedDatagramPacket() throws Throwable { public void testSendSegmentedDatagramPacket(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSendSegmentedDatagramPacket(bootstrap, bootstrap2);
}
});
} }
public void testSendSegmentedDatagramPacket(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSendSegmentedDatagramPacket(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -63,8 +69,13 @@ public class EpollDatagramUnicastTest extends DatagramUnicastTest {
} }
@Test @Test
public void testSendSegmentedDatagramPacketComposite() throws Throwable { public void testSendSegmentedDatagramPacketComposite(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSendSegmentedDatagramPacketComposite(bootstrap, bootstrap2);
}
});
} }
public void testSendSegmentedDatagramPacketComposite(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSendSegmentedDatagramPacketComposite(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -72,8 +83,13 @@ public class EpollDatagramUnicastTest extends DatagramUnicastTest {
} }
@Test @Test
public void testSendAndReceiveSegmentedDatagramPacket() throws Throwable { public void testSendAndReceiveSegmentedDatagramPacket(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSendAndReceiveSegmentedDatagramPacket(bootstrap, bootstrap2);
}
});
} }
public void testSendAndReceiveSegmentedDatagramPacket(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSendAndReceiveSegmentedDatagramPacket(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -81,8 +97,13 @@ public class EpollDatagramUnicastTest extends DatagramUnicastTest {
} }
@Test @Test
public void testSendAndReceiveSegmentedDatagramPacketComposite() throws Throwable { public void testSendAndReceiveSegmentedDatagramPacketComposite(TestInfo testInfo) throws Throwable {
run(); run(testInfo, new Runner<Bootstrap, Bootstrap>() {
@Override
public void run(Bootstrap bootstrap, Bootstrap bootstrap2) throws Throwable {
testSendAndReceiveSegmentedDatagramPacketComposite(bootstrap, bootstrap2);
}
});
} }
public void testSendAndReceiveSegmentedDatagramPacketComposite(Bootstrap sb, Bootstrap cb) throws Throwable { public void testSendAndReceiveSegmentedDatagramPacketComposite(Bootstrap sb, Bootstrap cb) throws Throwable {
@ -99,7 +120,7 @@ public class EpollDatagramUnicastTest extends DatagramUnicastTest {
// Only supported for the native epoll transport. // Only supported for the native epoll transport.
return; return;
} }
Assume.assumeTrue(EpollDatagramChannel.isSegmentedDatagramPacketSupported()); assumeTrue(EpollDatagramChannel.isSegmentedDatagramPacketSupported());
Channel sc = null; Channel sc = null;
Channel cc = null; Channel cc = null;

View File

@ -26,14 +26,19 @@ import io.netty.channel.unix.DomainSocketReadMode;
import io.netty.channel.unix.FileDescriptor; import io.netty.channel.unix.FileDescriptor;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.AbstractSocketTest; import io.netty.testsuite.transport.socket.AbstractSocketTest;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.List; import java.util.List;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollDomainSocketFdTest extends AbstractSocketTest { public class EpollDomainSocketFdTest extends AbstractSocketTest {
@Override @Override
@ -46,9 +51,15 @@ public class EpollDomainSocketFdTest extends AbstractSocketTest {
return EpollSocketTestPermutation.INSTANCE.domainSocket(); return EpollSocketTestPermutation.INSTANCE.domainSocket();
} }
@Test(timeout = 30000) @Test
public void testSendRecvFd() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testSendRecvFd(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSendRecvFd(serverBootstrap, bootstrap);
}
});
} }
public void testSendRecvFd(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSendRecvFd(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -94,10 +105,10 @@ public class EpollDomainSocketFdTest extends AbstractSocketTest {
if (received instanceof FileDescriptor) { if (received instanceof FileDescriptor) {
FileDescriptor fd = (FileDescriptor) received; FileDescriptor fd = (FileDescriptor) received;
Assert.assertTrue(fd.isOpen()); assertTrue(fd.isOpen());
fd.close(); fd.close();
Assert.assertFalse(fd.isOpen()); assertFalse(fd.isOpen());
Assert.assertNull(queue.poll()); assertNull(queue.poll());
} else { } else {
throw (Throwable) received; throw (Throwable) received;
} }

View File

@ -17,7 +17,6 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest; import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest;
@ -25,11 +24,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public class EpollDomainSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest { public class EpollDomainSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest {
public EpollDomainSocketSslClientRenegotiateTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return EpollSocketTestPermutation.INSTANCE.domainSocket(); return EpollSocketTestPermutation.INSTANCE.domainSocket();

View File

@ -17,7 +17,6 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslEchoTest; import io.netty.testsuite.transport.socket.SocketSslEchoTest;
@ -25,16 +24,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public class EpollDomainSocketSslEchoTest extends SocketSslEchoTest { public class EpollDomainSocketSslEchoTest extends SocketSslEchoTest {
public EpollDomainSocketSslEchoTest(
SslContext serverCtx, SslContext clientCtx, Renegotiation renegotiation,
boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor,
boolean autoRead, boolean useChunkedWriteHandler, boolean useCompositeByteBuf) {
super(serverCtx, clientCtx, renegotiation,
serverUsesDelegatedTaskExecutor, clientUsesDelegatedTaskExecutor,
autoRead, useChunkedWriteHandler, useCompositeByteBuf);
}
@Override @Override
protected SocketAddress newSocketAddress() { protected SocketAddress newSocketAddress() {
return EpollSocketTestPermutation.newSocketAddress(); return EpollSocketTestPermutation.newSocketAddress();

View File

@ -17,7 +17,6 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslGreetingTest; import io.netty.testsuite.transport.socket.SocketSslGreetingTest;
@ -25,11 +24,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public class EpollDomainSocketSslGreetingTest extends SocketSslGreetingTest { public class EpollDomainSocketSslGreetingTest extends SocketSslGreetingTest {
public EpollDomainSocketSslGreetingTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected SocketAddress newSocketAddress() { protected SocketAddress newSocketAddress() {
return EpollSocketTestPermutation.newSocketAddress(); return EpollSocketTestPermutation.newSocketAddress();

View File

@ -17,7 +17,6 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketStartTlsTest; import io.netty.testsuite.transport.socket.SocketStartTlsTest;
@ -25,11 +24,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public class EpollDomainSocketStartTlsTest extends SocketStartTlsTest { public class EpollDomainSocketStartTlsTest extends SocketStartTlsTest {
public EpollDomainSocketStartTlsTest(SslContext serverCtx, SslContext clientCtx) {
super(serverCtx, clientCtx);
}
@Override @Override
protected SocketAddress newSocketAddress() { protected SocketAddress newSocketAddress() {
return EpollSocketTestPermutation.newSocketAddress(); return EpollSocketTestPermutation.newSocketAddress();

View File

@ -26,17 +26,17 @@ import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.RejectedExecutionHandlers; import io.netty.util.concurrent.RejectedExecutionHandlers;
import io.netty.util.concurrent.ThreadPerTaskExecutor; import io.netty.util.concurrent.ThreadPerTaskExecutor;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollEventLoopTest extends AbstractSingleThreadEventLoopTest { public class EpollEventLoopTest extends AbstractSingleThreadEventLoopTest {

View File

@ -16,12 +16,11 @@
package io.netty.channel.epoll; package io.netty.channel.epoll;
import io.netty.channel.unix.tests.IovArrayTest; import io.netty.channel.unix.tests.IovArrayTest;
import org.junit.Assume; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass;
public class EpollKQueueIovArrayTest extends IovArrayTest { public class EpollKQueueIovArrayTest extends IovArrayTest {
@BeforeClass @BeforeAll
public static void loadNative() { public static void loadNative() {
Epoll.ensureAvailability(); Epoll.ensureAvailability();
} }

View File

@ -31,10 +31,9 @@ import io.netty.util.ResourceLeakDetector;
import io.netty.util.internal.logging.InternalLogLevel; import io.netty.util.internal.logging.InternalLogLevel;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Assert; import org.junit.jupiter.api.Disabled;
import org.junit.Assume; import org.junit.jupiter.api.Test;
import org.junit.Ignore; import org.junit.jupiter.api.Timeout;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramPacket; import java.net.DatagramPacket;
@ -44,8 +43,14 @@ import java.net.Socket;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class EpollReuseAddrTest { public class EpollReuseAddrTest {
private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(EpollReuseAddrTest.class); private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(EpollReuseAddrTest.class);
@ -86,13 +91,13 @@ public class EpollReuseAddrTest {
@Test @Test
public void testMultipleBindSocketChannelWithoutReusePortFails() { public void testMultipleBindSocketChannelWithoutReusePortFails() {
Assume.assumeTrue(versionEqOrGt(3, 9, 0)); assumeTrue(versionEqOrGt(3, 9, 0));
testMultipleBindDatagramChannelWithoutReusePortFails0(createServerBootstrap()); testMultipleBindDatagramChannelWithoutReusePortFails0(createServerBootstrap());
} }
@Test @Test
public void testMultipleBindDatagramChannelWithoutReusePortFails() { public void testMultipleBindDatagramChannelWithoutReusePortFails() {
Assume.assumeTrue(versionEqOrGt(3, 9, 0)); assumeTrue(versionEqOrGt(3, 9, 0));
testMultipleBindDatagramChannelWithoutReusePortFails0(createBootstrap()); testMultipleBindDatagramChannelWithoutReusePortFails0(createBootstrap());
} }
@ -101,16 +106,17 @@ public class EpollReuseAddrTest {
ChannelFuture future = bootstrap.bind().syncUninterruptibly(); ChannelFuture future = bootstrap.bind().syncUninterruptibly();
try { try {
bootstrap.bind(future.channel().localAddress()).syncUninterruptibly(); bootstrap.bind(future.channel().localAddress()).syncUninterruptibly();
Assert.fail(); fail();
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(e instanceof IOException); assertTrue(e instanceof IOException);
} }
future.channel().close().syncUninterruptibly(); future.channel().close().syncUninterruptibly();
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testMultipleBindSocketChannel() throws Exception { public void testMultipleBindSocketChannel() throws Exception {
Assume.assumeTrue(versionEqOrGt(3, 9, 0)); assumeTrue(versionEqOrGt(3, 9, 0));
ServerBootstrap bootstrap = createServerBootstrap(); ServerBootstrap bootstrap = createServerBootstrap();
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true); bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
final AtomicBoolean accepted1 = new AtomicBoolean(); final AtomicBoolean accepted1 = new AtomicBoolean();
@ -123,7 +129,7 @@ public class EpollReuseAddrTest {
ChannelFuture future2 = bootstrap.bind(address1).syncUninterruptibly(); ChannelFuture future2 = bootstrap.bind(address1).syncUninterruptibly();
InetSocketAddress address2 = (InetSocketAddress) future2.channel().localAddress(); InetSocketAddress address2 = (InetSocketAddress) future2.channel().localAddress();
Assert.assertEquals(address1, address2); assertEquals(address1, address2);
while (!accepted1.get() || !accepted2.get()) { while (!accepted1.get() || !accepted2.get()) {
Socket socket = new Socket(address1.getAddress(), address1.getPort()); Socket socket = new Socket(address1.getAddress(), address1.getPort());
socket.setReuseAddress(true); socket.setReuseAddress(true);
@ -133,11 +139,12 @@ public class EpollReuseAddrTest {
future2.channel().close().syncUninterruptibly(); future2.channel().close().syncUninterruptibly();
} }
@Test(timeout = 10000) @Test
@Ignore // TODO: Unignore after making it pass on centos6-1 and debian7-1 @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
@Disabled // TODO: Unignore after making it pass on centos6-1 and debian7-1
public void testMultipleBindDatagramChannel() throws Exception { public void testMultipleBindDatagramChannel() throws Exception {
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED); ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED);
Assume.assumeTrue(versionEqOrGt(3, 9, 0)); assumeTrue(versionEqOrGt(3, 9, 0));
Bootstrap bootstrap = createBootstrap(); Bootstrap bootstrap = createBootstrap();
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true); bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
final AtomicBoolean received1 = new AtomicBoolean(); final AtomicBoolean received1 = new AtomicBoolean();
@ -150,7 +157,7 @@ public class EpollReuseAddrTest {
ChannelFuture future2 = bootstrap.bind(address1).syncUninterruptibly(); ChannelFuture future2 = bootstrap.bind(address1).syncUninterruptibly();
final InetSocketAddress address2 = (InetSocketAddress) future2.channel().localAddress(); final InetSocketAddress address2 = (InetSocketAddress) future2.channel().localAddress();
Assert.assertEquals(address1, address2); assertEquals(address1, address2);
final byte[] bytes = "data".getBytes(); final byte[] bytes = "data".getBytes();
// fire up 16 Threads and send DatagramPackets to make sure we stress it enough to see DatagramPackets received // fire up 16 Threads and send DatagramPackets to make sure we stress it enough to see DatagramPackets received
@ -182,8 +189,8 @@ public class EpollReuseAddrTest {
executor.shutdown(); executor.shutdown();
future.channel().close().syncUninterruptibly(); future.channel().close().syncUninterruptibly();
future2.channel().close().syncUninterruptibly(); future2.channel().close().syncUninterruptibly();
Assert.assertTrue(received1.get()); assertTrue(received1.get());
Assert.assertTrue(received2.get()); assertTrue(received2.get());
} }
private static ServerBootstrap createServerBootstrap() { private static ServerBootstrap createServerBootstrap() {

View File

@ -19,21 +19,24 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Test; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Map; import java.util.Map;
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 EpollServerSocketChannelConfigTest { public class EpollServerSocketChannelConfigTest {
private static EventLoopGroup group; private static EventLoopGroup group;
private static EpollServerSocketChannel ch; private static EpollServerSocketChannel ch;
@BeforeClass @BeforeAll
public static void before() { public static void before() {
group = new EpollEventLoopGroup(1); group = new EpollEventLoopGroup(1);
ServerBootstrap bootstrap = new ServerBootstrap(); ServerBootstrap bootstrap = new ServerBootstrap();
@ -43,7 +46,7 @@ public class EpollServerSocketChannelConfigTest {
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel(); .bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
} }
@AfterClass @AfterAll
public static void after() { public static void after() {
try { try {
ch.close().syncUninterruptibly(); ch.close().syncUninterruptibly();

View File

@ -15,24 +15,27 @@
*/ */
package io.netty.channel.epoll; package io.netty.channel.epoll;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opentest4j.TestAbortedException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import org.junit.After; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.AfterClass; import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.Before; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.BeforeClass; import static org.junit.jupiter.api.Assertions.fail;
import org.junit.Test;
public class EpollSocketChannelConfigTest { public class EpollSocketChannelConfigTest {
@ -40,18 +43,18 @@ public class EpollSocketChannelConfigTest {
private static EpollSocketChannel ch; private static EpollSocketChannel ch;
private static Random rand; private static Random rand;
@BeforeClass @BeforeAll
public static void beforeClass() { public static void beforeClass() {
rand = new Random(); rand = new Random();
group = new EpollEventLoopGroup(1); group = new EpollEventLoopGroup(1);
} }
@AfterClass @AfterAll
public static void afterClass() { public static void afterClass() {
group.shutdownGracefully(); group.shutdownGracefully();
} }
@Before @BeforeEach
public void setup() { public void setup() {
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
ch = (EpollSocketChannel) bootstrap.group(group) ch = (EpollSocketChannel) bootstrap.group(group)
@ -60,7 +63,7 @@ public class EpollSocketChannelConfigTest {
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel(); .bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
} }
@After @AfterEach
public void teardown() { public void teardown() {
ch.close().syncUninterruptibly(); ch.close().syncUninterruptibly();
} }
@ -86,8 +89,7 @@ public class EpollSocketChannelConfigTest {
ch.config().setTcpNotSentLowAt(expected); ch.config().setTcpNotSentLowAt(expected);
actual = ch.config().getTcpNotSentLowAt(); actual = ch.config().getTcpNotSentLowAt();
} catch (RuntimeException e) { } catch (RuntimeException e) {
assumeNoException(e); throw new TestAbortedException("assumeNoException", e);
return; // Needed to prevent compile error for final variables to be used below
} }
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@ -100,7 +102,7 @@ public class EpollSocketChannelConfigTest {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return; return;
} catch (RuntimeException e) { } catch (RuntimeException e) {
assumeNoException(e); throw new TestAbortedException("assumeNoException", e);
} }
fail(); fail();
} }
@ -113,7 +115,7 @@ public class EpollSocketChannelConfigTest {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return; return;
} catch (RuntimeException e) { } catch (RuntimeException e) {
assumeNoException(e); throw new TestAbortedException("assumeNoException", e);
} }
fail(); fail();
} }

View File

@ -19,11 +19,14 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import org.junit.Assert;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollSocketChannelTest { public class EpollSocketChannelTest {
@Test @Test
@ -64,40 +67,40 @@ public class EpollSocketChannelTest {
} }
private static void assertTcpInfo0(EpollTcpInfo info) throws Exception { private static void assertTcpInfo0(EpollTcpInfo info) throws Exception {
Assert.assertNotNull(info); assertNotNull(info);
Assert.assertTrue(info.state() >= 0); assertTrue(info.state() >= 0);
Assert.assertTrue(info.caState() >= 0); assertTrue(info.caState() >= 0);
Assert.assertTrue(info.retransmits() >= 0); assertTrue(info.retransmits() >= 0);
Assert.assertTrue(info.probes() >= 0); assertTrue(info.probes() >= 0);
Assert.assertTrue(info.backoff() >= 0); assertTrue(info.backoff() >= 0);
Assert.assertTrue(info.options() >= 0); assertTrue(info.options() >= 0);
Assert.assertTrue(info.sndWscale() >= 0); assertTrue(info.sndWscale() >= 0);
Assert.assertTrue(info.rcvWscale() >= 0); assertTrue(info.rcvWscale() >= 0);
Assert.assertTrue(info.rto() >= 0); assertTrue(info.rto() >= 0);
Assert.assertTrue(info.ato() >= 0); assertTrue(info.ato() >= 0);
Assert.assertTrue(info.sndMss() >= 0); assertTrue(info.sndMss() >= 0);
Assert.assertTrue(info.rcvMss() >= 0); assertTrue(info.rcvMss() >= 0);
Assert.assertTrue(info.unacked() >= 0); assertTrue(info.unacked() >= 0);
Assert.assertTrue(info.sacked() >= 0); assertTrue(info.sacked() >= 0);
Assert.assertTrue(info.lost() >= 0); assertTrue(info.lost() >= 0);
Assert.assertTrue(info.retrans() >= 0); assertTrue(info.retrans() >= 0);
Assert.assertTrue(info.fackets() >= 0); assertTrue(info.fackets() >= 0);
Assert.assertTrue(info.lastDataSent() >= 0); assertTrue(info.lastDataSent() >= 0);
Assert.assertTrue(info.lastAckSent() >= 0); assertTrue(info.lastAckSent() >= 0);
Assert.assertTrue(info.lastDataRecv() >= 0); assertTrue(info.lastDataRecv() >= 0);
Assert.assertTrue(info.lastAckRecv() >= 0); assertTrue(info.lastAckRecv() >= 0);
Assert.assertTrue(info.pmtu() >= 0); assertTrue(info.pmtu() >= 0);
Assert.assertTrue(info.rcvSsthresh() >= 0); assertTrue(info.rcvSsthresh() >= 0);
Assert.assertTrue(info.rtt() >= 0); assertTrue(info.rtt() >= 0);
Assert.assertTrue(info.rttvar() >= 0); assertTrue(info.rttvar() >= 0);
Assert.assertTrue(info.sndSsthresh() >= 0); assertTrue(info.sndSsthresh() >= 0);
Assert.assertTrue(info.sndCwnd() >= 0); assertTrue(info.sndCwnd() >= 0);
Assert.assertTrue(info.advmss() >= 0); assertTrue(info.advmss() >= 0);
Assert.assertTrue(info.reordering() >= 0); assertTrue(info.reordering() >= 0);
Assert.assertTrue(info.rcvRtt() >= 0); assertTrue(info.rcvRtt() >= 0);
Assert.assertTrue(info.rcvSpace() >= 0); assertTrue(info.rcvSpace() >= 0);
Assert.assertTrue(info.totalRetrans() >= 0); assertTrue(info.totalRetrans() >= 0);
} }
// See https://github.com/netty/netty/issues/7159 // See https://github.com/netty/netty/issues/7159

View File

@ -26,8 +26,8 @@ import io.netty.testsuite.transport.socket.SocketRstTest;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollSocketRstTest extends SocketRstTest { public class EpollSocketRstTest extends SocketRstTest {
@Override @Override
@ -42,8 +42,8 @@ public class EpollSocketRstTest extends SocketRstTest {
return; return;
} }
assertTrue("actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]", assertTrue(cause instanceof NativeIoException,
cause instanceof NativeIoException); "actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]");
assertEquals(Errors.ERRNO_ECONNRESET_NEGATIVE, ((NativeIoException) cause).expectedErr()); assertEquals(Errors.ERRNO_ECONNRESET_NEGATIVE, ((NativeIoException) cause).expectedErr());
} }
} }

View File

@ -17,18 +17,12 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest; import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest;
import java.util.List; import java.util.List;
public class EpollSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest { public class EpollSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest {
public EpollSocketSslClientRenegotiateTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen(); return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen();

View File

@ -17,23 +17,12 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslEchoTest; import io.netty.testsuite.transport.socket.SocketSslEchoTest;
import java.util.List; import java.util.List;
public class EpollSocketSslEchoTest extends SocketSslEchoTest { public class EpollSocketSslEchoTest extends SocketSslEchoTest {
public EpollSocketSslEchoTest(
SslContext serverCtx, SslContext clientCtx, Renegotiation renegotiation,
boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor,
boolean autoRead, boolean useChunkedWriteHandler, boolean useCompositeByteBuf) {
super(serverCtx, clientCtx, renegotiation,
serverUsesDelegatedTaskExecutor, clientUsesDelegatedTaskExecutor,
autoRead, useChunkedWriteHandler, useCompositeByteBuf);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen(); return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen();

View File

@ -17,18 +17,12 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslGreetingTest; import io.netty.testsuite.transport.socket.SocketSslGreetingTest;
import java.util.List; import java.util.List;
public class EpollSocketSslGreetingTest extends SocketSslGreetingTest { public class EpollSocketSslGreetingTest extends SocketSslGreetingTest {
public EpollSocketSslGreetingTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen(); return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen();

View File

@ -17,18 +17,12 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslSessionReuseTest; import io.netty.testsuite.transport.socket.SocketSslSessionReuseTest;
import java.util.List; import java.util.List;
public class EpollSocketSslSessionReuseTest extends SocketSslSessionReuseTest { public class EpollSocketSslSessionReuseTest extends SocketSslSessionReuseTest {
public EpollSocketSslSessionReuseTest(SslContext serverCtx, SslContext clientCtx) {
super(serverCtx, clientCtx);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen(); return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen();

View File

@ -17,18 +17,12 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketStartTlsTest; import io.netty.testsuite.transport.socket.SocketStartTlsTest;
import java.util.List; import java.util.List;
public class EpollSocketStartTlsTest extends SocketStartTlsTest { public class EpollSocketStartTlsTest extends SocketStartTlsTest {
public EpollSocketStartTlsTest(SslContext serverCtx, SslContext clientCtx) {
super(serverCtx, clientCtx);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen(); return EpollSocketTestPermutation.INSTANCE.socketWithFastOpen();

View File

@ -15,12 +15,6 @@
*/ */
package io.netty.channel.epoll; package io.netty.channel.epoll;
import java.util.ArrayList;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
@ -32,12 +26,17 @@ import io.netty.testsuite.transport.TestsuitePermutation.BootstrapFactory;
import io.netty.testsuite.transport.socket.SocketStringEchoTest; import io.netty.testsuite.transport.socket.SocketStringEchoTest;
import io.netty.util.IntSupplier; import io.netty.util.IntSupplier;
import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.DefaultThreadFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import java.util.ArrayList;
import java.util.List;
public class EpollSocketStringEchoBusyWaitTest extends SocketStringEchoTest { public class EpollSocketStringEchoBusyWaitTest extends SocketStringEchoTest {
private static EventLoopGroup EPOLL_LOOP; private static EventLoopGroup EPOLL_LOOP;
@BeforeClass @BeforeAll
public static void setup() throws Exception { public static void setup() throws Exception {
EPOLL_LOOP = new EpollEventLoopGroup(2, new DefaultThreadFactory("testsuite-epoll-busy-wait", true), EPOLL_LOOP = new EpollEventLoopGroup(2, new DefaultThreadFactory("testsuite-epoll-busy-wait", true),
new SelectStrategyFactory() { new SelectStrategyFactory() {
@ -53,7 +52,7 @@ public class EpollSocketStringEchoBusyWaitTest extends SocketStringEchoTest {
}); });
} }
@AfterClass @AfterAll
public static void teardown() throws Exception { public static void teardown() throws Exception {
if (EPOLL_LOOP != null) { if (EPOLL_LOOP != null) {
EPOLL_LOOP.shutdownGracefully(); EPOLL_LOOP.shutdownGracefully();

View File

@ -21,17 +21,20 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.ConnectTimeoutException; import io.netty.channel.ConnectTimeoutException;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Collections; import java.util.Collections;
import io.netty.util.NetUtil; import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.After; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class EpollSocketTcpMd5Test { public class EpollSocketTcpMd5Test {
private static final byte[] SERVER_KEY = "abc".getBytes(CharsetUtil.US_ASCII); private static final byte[] SERVER_KEY = "abc".getBytes(CharsetUtil.US_ASCII);
@ -39,17 +42,17 @@ public class EpollSocketTcpMd5Test {
private static EventLoopGroup GROUP; private static EventLoopGroup GROUP;
private EpollServerSocketChannel server; private EpollServerSocketChannel server;
@BeforeClass @BeforeAll
public static void beforeClass() { public static void beforeClass() {
GROUP = new EpollEventLoopGroup(1); GROUP = new EpollEventLoopGroup(1);
} }
@AfterClass @AfterAll
public static void afterClass() { public static void afterClass() {
GROUP.shutdownGracefully(); GROUP.shutdownGracefully();
} }
@Before @BeforeEach
public void setup() { public void setup() {
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
server = (EpollServerSocketChannel) bootstrap.group(GROUP) server = (EpollServerSocketChannel) bootstrap.group(GROUP)
@ -58,7 +61,7 @@ public class EpollSocketTcpMd5Test {
.bind(new InetSocketAddress(NetUtil.LOCALHOST4, 0)).syncUninterruptibly().channel(); .bind(new InetSocketAddress(NetUtil.LOCALHOST4, 0)).syncUninterruptibly().channel();
} }
@After @AfterEach
public void teardown() { public void teardown() {
server.close().syncUninterruptibly(); server.close().syncUninterruptibly();
} }
@ -85,19 +88,24 @@ public class EpollSocketTcpMd5Test {
ch.close().syncUninterruptibly(); ch.close().syncUninterruptibly();
} }
@Test(expected = ConnectTimeoutException.class) @Test
public void testKeyMismatch() throws Exception { public void testKeyMismatch() throws Exception {
server.config().setOption(EpollChannelOption.TCP_MD5SIG, server.config().setOption(EpollChannelOption.TCP_MD5SIG,
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, SERVER_KEY)); Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, SERVER_KEY));
EpollSocketChannel client = (EpollSocketChannel) new Bootstrap().group(GROUP) assertThrows(ConnectTimeoutException.class, new Executable() {
.channel(EpollSocketChannel.class) @Override
.handler(new ChannelInboundHandlerAdapter()) public void execute() throws Throwable {
.option(EpollChannelOption.TCP_MD5SIG, EpollSocketChannel client = (EpollSocketChannel) new Bootstrap().group(GROUP)
Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, BAD_KEY)) .channel(EpollSocketChannel.class)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000) .handler(new ChannelInboundHandlerAdapter())
.connect(server.localAddress()).syncUninterruptibly().channel(); .option(EpollChannelOption.TCP_MD5SIG,
client.close().syncUninterruptibly(); Collections.<InetAddress, byte[]>singletonMap(NetUtil.LOCALHOST4, BAD_KEY))
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
.connect(server.localAddress()).syncUninterruptibly().channel();
client.close().syncUninterruptibly();
}
});
} }
@Test @Test

View File

@ -19,17 +19,17 @@ import io.netty.channel.unix.DomainSocketAddress;
import io.netty.channel.unix.PeerCredentials; import io.netty.channel.unix.PeerCredentials;
import io.netty.channel.unix.tests.SocketTest; import io.netty.channel.unix.tests.SocketTest;
import io.netty.channel.unix.tests.UnixTestUtils; import io.netty.channel.unix.tests.UnixTestUtils;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollSocketTest extends SocketTest<LinuxSocket> { public class EpollSocketTest extends SocketTest<LinuxSocket> {
@BeforeClass @BeforeAll
public static void loadJNI() { public static void loadJNI() {
Epoll.ensureAvailability(); Epoll.ensureAvailability();
} }

View File

@ -16,13 +16,15 @@
package io.netty.channel.epoll; package io.netty.channel.epoll;
import io.netty.channel.unix.FileDescriptor; import io.netty.channel.unix.FileDescriptor;
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.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class EpollTest { public class EpollTest {
@ -32,7 +34,8 @@ public class EpollTest {
} }
// Testcase for https://github.com/netty/netty/issues/8444 // Testcase for https://github.com/netty/netty/issues/8444
@Test(timeout = 5000) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testEpollWaitWithTimeOutMinusOne() throws Exception { public void testEpollWaitWithTimeOutMinusOne() throws Exception {
final EpollEventArray eventArray = new EpollEventArray(8); final EpollEventArray eventArray = new EpollEventArray(8);
try { try {

View File

@ -15,36 +15,52 @@
*/ */
package io.netty.channel.epoll; package io.netty.channel.epoll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class LinuxSocketTest { public class LinuxSocketTest {
@BeforeClass @BeforeAll
public static void loadJNI() { public static void loadJNI() {
Epoll.ensureAvailability(); Epoll.ensureAvailability();
} }
@Test(expected = IOException.class) @Test
public void testBindNonIpv6SocketToInet6AddressThrows() throws Exception { public void testBindNonIpv6SocketToInet6AddressThrows() throws Exception {
LinuxSocket socket = LinuxSocket.newSocketStream(false); final LinuxSocket socket = LinuxSocket.newSocketStream(false);
try { try {
socket.bind(new InetSocketAddress(InetAddress.getByAddress( assertThrows(IOException.class, new Executable() {
new byte[]{'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'}), 0)); @Override
public void execute() throws Throwable {
socket.bind(new InetSocketAddress(InetAddress.getByAddress(
new byte[]{'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'}),
0));
}
});
} finally { } finally {
socket.close(); socket.close();
} }
} }
@Test(expected = IOException.class) @Test
public void testConnectNonIpv6SocketToInet6AddressThrows() throws Exception { public void testConnectNonIpv6SocketToInet6AddressThrows() throws Exception {
LinuxSocket socket = LinuxSocket.newSocketStream(false); final LinuxSocket socket = LinuxSocket.newSocketStream(false);
try { try {
socket.connect(new InetSocketAddress(InetAddress.getByAddress( assertThrows(IOException.class,
new byte[]{'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'}), 1234)); new Executable() {
@Override
public void execute() throws Throwable {
socket.connect(new InetSocketAddress(InetAddress.getByAddress(new byte[]{
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'}),
1234));
}
});
} finally { } finally {
socket.close(); socket.close();
} }

View File

@ -16,14 +16,14 @@
package io.netty.channel.epoll; package io.netty.channel.epoll;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import static io.netty.channel.unix.NativeInetAddress.address; import static io.netty.channel.unix.NativeInetAddress.address;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class NativeTest { public class NativeTest {
@ -34,7 +34,7 @@ public class NativeTest {
ByteBuffer buffer = ByteBuffer.wrap(bytes); ByteBuffer buffer = ByteBuffer.wrap(bytes);
buffer.put(inetAddress.getAddress().getAddress()); buffer.put(inetAddress.getAddress().getAddress());
buffer.putInt(inetAddress.getPort()); buffer.putInt(inetAddress.getPort());
Assert.assertEquals(inetAddress, address(buffer.array(), 0, bytes.length)); assertEquals(inetAddress, address(buffer.array(), 0, bytes.length));
} }
@Test @Test
@ -46,6 +46,6 @@ public class NativeTest {
buffer.put(address.getAddress()); buffer.put(address.getAddress());
buffer.putInt(address.getScopeId()); buffer.putInt(address.getScopeId());
buffer.putInt(inetAddress.getPort()); buffer.putInt(inetAddress.getPort());
Assert.assertEquals(inetAddress, address(buffer.array(), 0, bytes.length)); assertEquals(inetAddress, address(buffer.array(), 0, bytes.length));
} }
} }

View File

@ -20,15 +20,16 @@ import io.netty.channel.ChannelException;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import org.junit.Before;
import org.junit.Test; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class KQueueChannelConfigTest { public class KQueueChannelConfigTest {
@Before @BeforeEach
public void before() { public void before() {
KQueue.ensureAvailability(); KQueue.ensureAvailability();
} }

View File

@ -26,13 +26,19 @@ import io.netty.channel.unix.DomainSocketReadMode;
import io.netty.channel.unix.FileDescriptor; import io.netty.channel.unix.FileDescriptor;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.AbstractSocketTest; import io.netty.testsuite.transport.socket.AbstractSocketTest;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.List; import java.util.List;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class KQueueDomainSocketFdTest extends AbstractSocketTest { public class KQueueDomainSocketFdTest extends AbstractSocketTest {
@Override @Override
@ -45,9 +51,15 @@ public class KQueueDomainSocketFdTest extends AbstractSocketTest {
return KQueueSocketTestPermutation.INSTANCE.domainSocket(); return KQueueSocketTestPermutation.INSTANCE.domainSocket();
} }
@Test(timeout = 30000) @Test
public void testSendRecvFd() throws Throwable { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
run(); public void testSendRecvFd(TestInfo testInfo) throws Throwable {
run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
@Override
public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
testSendRecvFd(serverBootstrap, bootstrap);
}
});
} }
public void testSendRecvFd(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSendRecvFd(ServerBootstrap sb, Bootstrap cb) throws Throwable {
@ -93,10 +105,10 @@ public class KQueueDomainSocketFdTest extends AbstractSocketTest {
if (received instanceof FileDescriptor) { if (received instanceof FileDescriptor) {
FileDescriptor fd = (FileDescriptor) received; FileDescriptor fd = (FileDescriptor) received;
Assert.assertTrue(fd.isOpen()); assertTrue(fd.isOpen());
fd.close(); fd.close();
Assert.assertFalse(fd.isOpen()); assertFalse(fd.isOpen());
Assert.assertNull(queue.poll()); assertNull(queue.poll());
} else { } else {
throw (Throwable) received; throw (Throwable) received;
} }

View File

@ -17,7 +17,6 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest; import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest;
@ -25,11 +24,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public class KQueueDomainSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest { public class KQueueDomainSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest {
public KQueueDomainSocketSslClientRenegotiateTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return KQueueSocketTestPermutation.INSTANCE.domainSocket(); return KQueueSocketTestPermutation.INSTANCE.domainSocket();

View File

@ -17,7 +17,6 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslEchoTest; import io.netty.testsuite.transport.socket.SocketSslEchoTest;
@ -25,16 +24,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public class KQueueDomainSocketSslEchoTest extends SocketSslEchoTest { public class KQueueDomainSocketSslEchoTest extends SocketSslEchoTest {
public KQueueDomainSocketSslEchoTest(
SslContext serverCtx, SslContext clientCtx, Renegotiation renegotiation,
boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor,
boolean autoRead, boolean useChunkedWriteHandler, boolean useCompositeByteBuf) {
super(serverCtx, clientCtx, renegotiation,
serverUsesDelegatedTaskExecutor, clientUsesDelegatedTaskExecutor,
autoRead, useChunkedWriteHandler, useCompositeByteBuf);
}
@Override @Override
protected SocketAddress newSocketAddress() { protected SocketAddress newSocketAddress() {
return KQueueSocketTestPermutation.newSocketAddress(); return KQueueSocketTestPermutation.newSocketAddress();

View File

@ -17,7 +17,6 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslGreetingTest; import io.netty.testsuite.transport.socket.SocketSslGreetingTest;
@ -25,11 +24,6 @@ import java.net.SocketAddress;
import java.util.List; import java.util.List;
public class KQueueDomainSocketSslGreetingTest extends SocketSslGreetingTest { public class KQueueDomainSocketSslGreetingTest extends SocketSslGreetingTest {
public KQueueDomainSocketSslGreetingTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected SocketAddress newSocketAddress() { protected SocketAddress newSocketAddress() {
return KQueueSocketTestPermutation.newSocketAddress(); return KQueueSocketTestPermutation.newSocketAddress();

View File

@ -26,10 +26,6 @@ import java.util.List;
public class KQueueDomainSocketStartTlsTest extends SocketStartTlsTest { public class KQueueDomainSocketStartTlsTest extends SocketStartTlsTest {
public KQueueDomainSocketStartTlsTest(SslContext serverCtx, SslContext clientCtx) {
super(serverCtx, clientCtx);
}
@Override @Override
protected SocketAddress newSocketAddress() { protected SocketAddress newSocketAddress() {
return KQueueSocketTestPermutation.newSocketAddress(); return KQueueSocketTestPermutation.newSocketAddress();

View File

@ -21,12 +21,12 @@ import io.netty.channel.ServerChannel;
import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.ServerSocketChannel;
import io.netty.testsuite.transport.AbstractSingleThreadEventLoopTest; import io.netty.testsuite.transport.AbstractSingleThreadEventLoopTest;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class KQueueEventLoopTest extends AbstractSingleThreadEventLoopTest { public class KQueueEventLoopTest extends AbstractSingleThreadEventLoopTest {

View File

@ -16,11 +16,11 @@
package io.netty.channel.kqueue; package io.netty.channel.kqueue;
import io.netty.channel.unix.tests.IovArrayTest; import io.netty.channel.unix.tests.IovArrayTest;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
public class KQueueIovArrayTest extends IovArrayTest { public class KQueueIovArrayTest extends IovArrayTest {
@BeforeClass @BeforeAll
public static void loadNative() { public static void loadNative() {
KQueue.ensureAvailability(); KQueue.ensureAvailability();
} }

View File

@ -18,19 +18,8 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.handler.ssl.SslContext;
public class KQueueRcvAllocatorOverrideSocketSslEchoTest extends KQueueSocketSslEchoTest { public class KQueueRcvAllocatorOverrideSocketSslEchoTest extends KQueueSocketSslEchoTest {
public KQueueRcvAllocatorOverrideSocketSslEchoTest(
SslContext serverCtx, SslContext clientCtx, Renegotiation renegotiation,
boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor,
boolean autoRead, boolean useChunkedWriteHandler, boolean useCompositeByteBuf) {
super(serverCtx, clientCtx, renegotiation,
serverUsesDelegatedTaskExecutor, clientUsesDelegatedTaskExecutor,
autoRead, useChunkedWriteHandler, useCompositeByteBuf);
}
@Override @Override
protected void configure(ServerBootstrap bootstrap, Bootstrap bootstrap2, ByteBufAllocator allocator) { protected void configure(ServerBootstrap bootstrap, Bootstrap bootstrap2, ByteBufAllocator allocator) {
super.configure(bootstrap, bootstrap2, allocator); super.configure(bootstrap, bootstrap2, allocator);

View File

@ -18,24 +18,24 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Test; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.Assume.assumeThat;
public class KQueueServerSocketChannelConfigTest { public class KQueueServerSocketChannelConfigTest {
private static EventLoopGroup group; private static EventLoopGroup group;
private static KQueueServerSocketChannel ch; private static KQueueServerSocketChannel ch;
@BeforeClass @BeforeAll
public static void before() { public static void before() {
group = new KQueueEventLoopGroup(1); group = new KQueueEventLoopGroup(1);
ServerBootstrap bootstrap = new ServerBootstrap(); ServerBootstrap bootstrap = new ServerBootstrap();
@ -45,7 +45,7 @@ public class KQueueServerSocketChannelConfigTest {
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel(); .bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
} }
@AfterClass @AfterAll
public static void after() { public static void after() {
try { try {
ch.close().syncUninterruptibly(); ch.close().syncUninterruptibly();
@ -66,7 +66,7 @@ public class KQueueServerSocketChannelConfigTest {
public void testAcceptFilter() { public void testAcceptFilter() {
AcceptFilter currentFilter = ch.config().getAcceptFilter(); AcceptFilter currentFilter = ch.config().getAcceptFilter();
// Not all platforms support this option (e.g. MacOS doesn't) so test if we support the option first. // Not all platforms support this option (e.g. MacOS doesn't) so test if we support the option first.
assumeThat(currentFilter, not(AcceptFilter.PLATFORM_UNSUPPORTED)); assumeTrue(currentFilter != AcceptFilter.PLATFORM_UNSUPPORTED);
AcceptFilter af = new AcceptFilter("test", "foo"); AcceptFilter af = new AcceptFilter("test", "foo");
ch.config().setAcceptFilter(af); ch.config().setAcceptFilter(af);

View File

@ -19,22 +19,23 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import org.junit.After;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Before; import org.junit.jupiter.api.AfterEach;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opentest4j.TestAbortedException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.util.Random; import java.util.Random;
import static io.netty.channel.kqueue.BsdSocket.BSD_SND_LOW_AT_MAX; import static io.netty.channel.kqueue.BsdSocket.BSD_SND_LOW_AT_MAX;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.Assume.assumeNoException;
public class KQueueSocketChannelConfigTest { public class KQueueSocketChannelConfigTest {
@ -42,18 +43,18 @@ public class KQueueSocketChannelConfigTest {
private static KQueueSocketChannel ch; private static KQueueSocketChannel ch;
private static Random rand; private static Random rand;
@BeforeClass @BeforeAll
public static void beforeClass() { public static void beforeClass() {
rand = new Random(); rand = new Random();
group = new KQueueEventLoopGroup(1); group = new KQueueEventLoopGroup(1);
} }
@AfterClass @AfterAll
public static void afterClass() { public static void afterClass() {
group.shutdownGracefully(); group.shutdownGracefully();
} }
@Before @BeforeEach
public void setup() { public void setup() {
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
ch = (KQueueSocketChannel) bootstrap.group(group) ch = (KQueueSocketChannel) bootstrap.group(group)
@ -62,7 +63,7 @@ public class KQueueSocketChannelConfigTest {
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel(); .bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
} }
@After @AfterEach
public void teardown() { public void teardown() {
ch.close().syncUninterruptibly(); ch.close().syncUninterruptibly();
} }
@ -75,8 +76,7 @@ public class KQueueSocketChannelConfigTest {
ch.config().setSndLowAt(expected); ch.config().setSndLowAt(expected);
actual = ch.config().getSndLowAt(); actual = ch.config().getSndLowAt();
} catch (RuntimeException e) { } catch (RuntimeException e) {
assumeNoException(e); throw new TestAbortedException("assumeNoException", e);
return; // Needed to prevent compile error for final variables to be used below
} }
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@ -88,7 +88,7 @@ public class KQueueSocketChannelConfigTest {
} catch (ChannelException e) { } catch (ChannelException e) {
return; return;
} catch (RuntimeException e) { } catch (RuntimeException e) {
assumeNoException(e); throw new TestAbortedException("assumeNoException", e);
} }
fail(); fail();
} }

View File

@ -26,8 +26,8 @@ import io.netty.testsuite.transport.socket.SocketRstTest;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class KQueueSocketRstTest extends SocketRstTest { public class KQueueSocketRstTest extends SocketRstTest {
@Override @Override
@ -42,8 +42,8 @@ public class KQueueSocketRstTest extends SocketRstTest {
return; return;
} }
assertTrue("actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]", assertTrue(cause instanceof NativeIoException,
cause instanceof NativeIoException); "actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]");
assertEquals(Errors.ERRNO_ECONNRESET_NEGATIVE, ((NativeIoException) cause).expectedErr()); assertEquals(Errors.ERRNO_ECONNRESET_NEGATIVE, ((NativeIoException) cause).expectedErr());
} }
} }

View File

@ -17,18 +17,12 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest; import io.netty.testsuite.transport.socket.SocketSslClientRenegotiateTest;
import java.util.List; import java.util.List;
public class KQueueSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest { public class KQueueSocketSslClientRenegotiateTest extends SocketSslClientRenegotiateTest {
public KQueueSocketSslClientRenegotiateTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return KQueueSocketTestPermutation.INSTANCE.socket(); return KQueueSocketTestPermutation.INSTANCE.socket();

View File

@ -17,23 +17,12 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslEchoTest; import io.netty.testsuite.transport.socket.SocketSslEchoTest;
import java.util.List; import java.util.List;
public class KQueueSocketSslEchoTest extends SocketSslEchoTest { public class KQueueSocketSslEchoTest extends SocketSslEchoTest {
public KQueueSocketSslEchoTest(
SslContext serverCtx, SslContext clientCtx, Renegotiation renegotiation,
boolean serverUsesDelegatedTaskExecutor, boolean clientUsesDelegatedTaskExecutor,
boolean autoRead, boolean useChunkedWriteHandler, boolean useCompositeByteBuf) {
super(serverCtx, clientCtx, renegotiation,
serverUsesDelegatedTaskExecutor, clientUsesDelegatedTaskExecutor,
autoRead, useChunkedWriteHandler, useCompositeByteBuf);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return KQueueSocketTestPermutation.INSTANCE.socket(); return KQueueSocketTestPermutation.INSTANCE.socket();

View File

@ -17,18 +17,12 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketSslGreetingTest; import io.netty.testsuite.transport.socket.SocketSslGreetingTest;
import java.util.List; import java.util.List;
public class KQueueSocketSslGreetingTest extends SocketSslGreetingTest { public class KQueueSocketSslGreetingTest extends SocketSslGreetingTest {
public KQueueSocketSslGreetingTest(SslContext serverCtx, SslContext clientCtx, boolean delegate) {
super(serverCtx, clientCtx, delegate);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return KQueueSocketTestPermutation.INSTANCE.socket(); return KQueueSocketTestPermutation.INSTANCE.socket();

View File

@ -24,11 +24,6 @@ import io.netty.testsuite.transport.socket.SocketSslSessionReuseTest;
import java.util.List; import java.util.List;
public class KQueueSocketSslSessionReuseTest extends SocketSslSessionReuseTest { public class KQueueSocketSslSessionReuseTest extends SocketSslSessionReuseTest {
public KQueueSocketSslSessionReuseTest(SslContext serverCtx, SslContext clientCtx) {
super(serverCtx, clientCtx);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return KQueueSocketTestPermutation.INSTANCE.socket(); return KQueueSocketTestPermutation.INSTANCE.socket();

View File

@ -17,7 +17,6 @@ package io.netty.channel.kqueue;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.handler.ssl.SslContext;
import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketStartTlsTest; import io.netty.testsuite.transport.socket.SocketStartTlsTest;
@ -25,10 +24,6 @@ import java.util.List;
public class KQueueSocketStartTlsTest extends SocketStartTlsTest { public class KQueueSocketStartTlsTest extends SocketStartTlsTest {
public KQueueSocketStartTlsTest(SslContext serverCtx, SslContext clientCtx) {
super(serverCtx, clientCtx);
}
@Override @Override
protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() {
return KQueueSocketTestPermutation.INSTANCE.socket(); return KQueueSocketTestPermutation.INSTANCE.socket();

View File

@ -19,15 +19,17 @@ import io.netty.channel.unix.DomainSocketAddress;
import io.netty.channel.unix.PeerCredentials; import io.netty.channel.unix.PeerCredentials;
import io.netty.channel.unix.tests.SocketTest; import io.netty.channel.unix.tests.SocketTest;
import io.netty.channel.unix.tests.UnixTestUtils; import io.netty.channel.unix.tests.UnixTestUtils;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class KQueueSocketTest extends SocketTest<BsdSocket> { public class KQueueSocketTest extends SocketTest<BsdSocket> {
@BeforeClass @BeforeAll
public static void loadJNI() { public static void loadJNI() {
KQueue.ensureAvailability(); KQueue.ensureAvailability();
} }

View File

@ -28,25 +28,29 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.FixedRecvByteBufAllocator; import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public abstract class DetectPeerCloseWithoutReadTest { public abstract class DetectPeerCloseWithoutReadTest {
protected abstract EventLoopGroup newGroup(); protected abstract EventLoopGroup newGroup();
protected abstract Class<? extends ServerChannel> serverChannel(); protected abstract Class<? extends ServerChannel> serverChannel();
protected abstract Class<? extends Channel> clientChannel(); protected abstract Class<? extends Channel> clientChannel();
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void clientCloseWithoutServerReadIsDetectedNoExtraReadRequested() throws InterruptedException { public void clientCloseWithoutServerReadIsDetectedNoExtraReadRequested() throws InterruptedException {
clientCloseWithoutServerReadIsDetected0(false); clientCloseWithoutServerReadIsDetected0(false);
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void clientCloseWithoutServerReadIsDetectedExtraReadRequested() throws InterruptedException { public void clientCloseWithoutServerReadIsDetectedExtraReadRequested() throws InterruptedException {
clientCloseWithoutServerReadIsDetected0(true); clientCloseWithoutServerReadIsDetected0(true);
} }
@ -103,12 +107,14 @@ public abstract class DetectPeerCloseWithoutReadTest {
} }
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void serverCloseWithoutClientReadIsDetectedNoExtraReadRequested() throws InterruptedException { public void serverCloseWithoutClientReadIsDetectedNoExtraReadRequested() throws InterruptedException {
serverCloseWithoutClientReadIsDetected0(false); serverCloseWithoutClientReadIsDetected0(false);
} }
@Test(timeout = 10000) @Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void serverCloseWithoutClientReadIsDetectedExtraReadRequested() throws InterruptedException { public void serverCloseWithoutClientReadIsDetectedExtraReadRequested() throws InterruptedException {
serverCloseWithoutClientReadIsDetected0(true); serverCloseWithoutClientReadIsDetected0(true);
} }

View File

@ -20,11 +20,11 @@ import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator; import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.buffer.UnpooledDirectByteBuf; import io.netty.buffer.UnpooledDirectByteBuf;
import io.netty.channel.unix.IovArray; import io.netty.channel.unix.IovArray;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public abstract class IovArrayTest { public abstract class IovArrayTest {

View File

@ -16,27 +16,27 @@
package io.netty.channel.unix.tests; package io.netty.channel.unix.tests;
import io.netty.channel.unix.Socket; import io.netty.channel.unix.Socket;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public abstract class SocketTest<T extends Socket> { public abstract class SocketTest<T extends Socket> {
protected T socket; protected T socket;
protected abstract T newSocket(); protected abstract T newSocket();
@Before @BeforeEach
public void setup() { public void setup() {
socket = newSocket(); socket = newSocket();
} }
@After @AfterEach
public void tearDown() throws IOException { public void tearDown() throws IOException {
socket.close(); socket.close();
} }