From 6c354381e434a9be609f3a6419c5cdd846c17a17 Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Sat, 28 Oct 2023 17:46:17 -0400 Subject: [PATCH] Fix event loop thread leak --- .../pulsar/broker/service/PersistentTopicTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java index 71310fef8102a5..51d3ef4577f552 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java @@ -46,7 +46,8 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.DefaultEventLoop; +import io.netty.channel.DefaultEventLoopGroup; +import io.netty.channel.EventLoopGroup; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.InetAddress; @@ -164,6 +165,7 @@ public class PersistentTopicTest extends MockedBookKeeperTestCase { private BrokerService brokerService; + private EventLoopGroup eventLoopGroup; @BeforeMethod(alwaysRun = true) public void setup() throws Exception { @@ -202,7 +204,9 @@ public void setup() throws Exception { .when(serverCnx).getCommandSender(); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); Channel channel = mock(Channel.class); - doReturn(spy(DefaultEventLoop.class)).when(channel).eventLoop(); + + eventLoopGroup = new DefaultEventLoopGroup(); + doReturn(eventLoopGroup.next()).when(channel).eventLoop(); doReturn(channel).when(ctx).channel(); doReturn(ctx).when(serverCnx).ctx(); @@ -224,6 +228,10 @@ public void teardown() throws Exception { pulsarTestContext.close(); pulsarTestContext = null; } + if (eventLoopGroup != null) { + eventLoopGroup.shutdownNow(); + eventLoopGroup = null; + } } @Test