diff --git a/common/src/main/java/io/netty/util/internal/Hidden.java b/common/src/main/java/io/netty/util/internal/Hidden.java index c0e9bba538..52742f181c 100644 --- a/common/src/main/java/io/netty/util/internal/Hidden.java +++ b/common/src/main/java/io/netty/util/internal/Hidden.java @@ -62,6 +62,13 @@ class Hidden { "confirmShutdown" ); + builder.allowBlockingCallsInside("io.netty.util.concurrent.GlobalEventExecutor", + "takeTask"); + + builder.allowBlockingCallsInside( + "io.netty.util.concurrent.SingleThreadEventExecutor", + "takeTask"); + builder.allowBlockingCallsInside( "io.netty.handler.ssl.SslHandler", "handshake" diff --git a/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java b/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java index 489785fbd1..3dcd793a15 100644 --- a/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java +++ b/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java @@ -35,9 +35,13 @@ import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.handler.ssl.util.SelfSignedCertificate; import io.netty.util.ReferenceCountUtil; +import io.netty.util.concurrent.DefaultThreadFactory; +import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateExecutor; +import io.netty.util.concurrent.ScheduledFuture; +import io.netty.util.concurrent.SingleThreadEventExecutor; import io.netty.util.internal.Hidden.NettyBlockHoundIntegration; import org.hamcrest.Matchers; import org.junit.BeforeClass; @@ -48,6 +52,7 @@ import reactor.blockhound.integration.BlockHoundIntegration; import java.net.InetSocketAddress; import java.util.ServiceLoader; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; @@ -93,6 +98,35 @@ public class NettyBlockHoundIntegrationTest { } } + @Test(timeout = 5000L) + public void testGlobalEventExecutorTakeTask() throws InterruptedException { + testEventExecutorTakeTask(GlobalEventExecutor.INSTANCE); + } + + @Test(timeout = 5000L) + public void testSingleThreadEventExecutorTakeTask() throws InterruptedException { + SingleThreadEventExecutor executor = + new SingleThreadEventExecutor(new DefaultThreadFactory("test")) { + @Override + protected void run() { + while (!confirmShutdown()) { + Runnable task = takeTask(); + if (task != null) { + task.run(); + } + } + } + }; + testEventExecutorTakeTask(executor); + } + + private static void testEventExecutorTakeTask(EventExecutor eventExecutor) throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + ScheduledFuture f = eventExecutor.schedule(latch::countDown, 10, TimeUnit.MILLISECONDS); + f.sync(); + latch.await(); + } + // Tests copied from io.netty.handler.ssl.SslHandlerTest @Test public void testHandshakeWithExecutorThatExecuteDirectory() throws Exception {