Migrate transport-blockhound-tests tests to JUnit 5 (#11322)

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 07:00:30 -07:00 committed by Norman Maurer
parent 0ac8835e36
commit 496ba801d6

View File

@ -49,8 +49,9 @@ import io.netty.util.concurrent.ScheduledFuture;
import io.netty.util.concurrent.SingleThreadEventExecutor; import io.netty.util.concurrent.SingleThreadEventExecutor;
import io.netty.util.internal.Hidden.NettyBlockHoundIntegration; import io.netty.util.internal.Hidden.NettyBlockHoundIntegration;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
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.Timeout;
import reactor.blockhound.BlockHound; import reactor.blockhound.BlockHound;
import reactor.blockhound.BlockingOperationError; import reactor.blockhound.BlockingOperationError;
import reactor.blockhound.integration.BlockHoundIntegration; import reactor.blockhound.integration.BlockHoundIntegration;
@ -75,15 +76,15 @@ import java.util.concurrent.locks.ReentrantLock;
import static io.netty.buffer.Unpooled.wrappedBuffer; import static io.netty.buffer.Unpooled.wrappedBuffer;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
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.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class NettyBlockHoundIntegrationTest { public class NettyBlockHoundIntegrationTest {
@BeforeClass @BeforeAll
public static void setUpClass() { public static void setUpClass() {
BlockHound.install(); BlockHound.install();
} }
@ -115,12 +116,14 @@ public class NettyBlockHoundIntegrationTest {
} }
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testGlobalEventExecutorTakeTask() throws InterruptedException { public void testGlobalEventExecutorTakeTask() throws InterruptedException {
testEventExecutorTakeTask(GlobalEventExecutor.INSTANCE); testEventExecutorTakeTask(GlobalEventExecutor.INSTANCE);
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testSingleThreadEventExecutorTakeTask() throws InterruptedException { public void testSingleThreadEventExecutorTakeTask() throws InterruptedException {
SingleThreadEventExecutor executor = SingleThreadEventExecutor executor =
new SingleThreadEventExecutor(null, new DefaultThreadFactory("test"), true) { new SingleThreadEventExecutor(null, new DefaultThreadFactory("test"), true) {
@ -144,7 +147,8 @@ public class NettyBlockHoundIntegrationTest {
latch.await(); latch.await();
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testSingleThreadEventExecutorAddTask() throws Exception { public void testSingleThreadEventExecutorAddTask() throws Exception {
TestLinkedBlockingQueue<Runnable> taskQueue = new TestLinkedBlockingQueue<>(); TestLinkedBlockingQueue<Runnable> taskQueue = new TestLinkedBlockingQueue<>();
SingleThreadEventExecutor executor = SingleThreadEventExecutor executor =
@ -175,7 +179,8 @@ public class NettyBlockHoundIntegrationTest {
latch.await(); latch.await();
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testHashedWheelTimerStartStop() throws Exception { public void testHashedWheelTimerStartStop() throws Exception {
HashedWheelTimer timer = new HashedWheelTimer(); HashedWheelTimer timer = new HashedWheelTimer();
Future<?> futureStart = GlobalEventExecutor.INSTANCE.submit(timer::start); Future<?> futureStart = GlobalEventExecutor.INSTANCE.submit(timer::start);
@ -332,17 +337,20 @@ public class NettyBlockHoundIntegrationTest {
} }
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testUnixResolverDnsServerAddressStreamProvider_Parse() throws InterruptedException { public void testUnixResolverDnsServerAddressStreamProvider_Parse() throws InterruptedException {
doTestParseResolverFilesAllowsBlockingCalls(DnsServerAddressStreamProviders::unixDefault); doTestParseResolverFilesAllowsBlockingCalls(DnsServerAddressStreamProviders::unixDefault);
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testHostsFileParser_Parse() throws InterruptedException { public void testHostsFileParser_Parse() throws InterruptedException {
doTestParseResolverFilesAllowsBlockingCalls(DnsNameResolverBuilder::new); doTestParseResolverFilesAllowsBlockingCalls(DnsNameResolverBuilder::new);
} }
@Test(timeout = 5000L) @Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testUnixResolverDnsServerAddressStreamProvider_ParseEtcResolverSearchDomainsAndOptions() public void testUnixResolverDnsServerAddressStreamProvider_ParseEtcResolverSearchDomainsAndOptions()
throws InterruptedException { throws InterruptedException {
NioEventLoopGroup group = new NioEventLoopGroup(); NioEventLoopGroup group = new NioEventLoopGroup();