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 83c6f3a1e8..65887d39fb 100644 --- a/common/src/main/java/io/netty/util/internal/Hidden.java +++ b/common/src/main/java/io/netty/util/internal/Hidden.java @@ -75,6 +75,14 @@ class Hidden { "runAllDelegatedTasks" ); + builder.allowBlockingCallsInside( + "io.netty.util.concurrent.GlobalEventExecutor", + "takeTask"); + + builder.allowBlockingCallsInside( + "io.netty.util.concurrent.SingleThreadEventExecutor", + "takeTask"); + builder.nonBlockingThreadPredicate(new Function, Predicate>() { @Override public Predicate apply(final Predicate p) { 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 65b383dab3..817257b411 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; @@ -94,6 +99,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(null, new DefaultThreadFactory("test"), true) { + @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 {