This is an automated email from the ASF dual-hosted git repository. jimin pushed a commit to branch 2.x in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push: new b711d7640a optimize: avoid using unstable API in ChannelEventHandlerIntegrationTest (#7518) b711d7640a is described below commit b711d7640a3ae8032a1e9573cbdbbcecb5af31a9 Author: maple <gsk525...@163.com> AuthorDate: Fri Jul 11 09:56:30 2025 +0800 optimize: avoid using unstable API in ChannelEventHandlerIntegrationTest (#7518) --- changes/en-us/2.x.md | 1 + changes/zh-cn/2.x.md | 1 + .../netty/ChannelEventHandlerIntegrationTest.java | 42 ++++------------------ 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index c2a5e50bef..3ec0853d6f 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -71,6 +71,7 @@ Add changes here for all PR submitted to the 2.x branch. - [[#7478](https://github.com/apache/incubator-seata/pull/7478)] metrics add retry status - [[#7483](https://github.com/apache/incubator-seata/pull/7483)] change the value of retryDeadThreshold to 70 seconds - [[#7488](https://github.com/apache/incubator-seata/pull/7488)] upgrade tomcat to 9.0.106 +- [[#7518](https://github.com/apache/incubator-seata/pull/7518)] avoid using unstable API in ChannelEventHandlerIntegrationTest ### security: diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index e4d7d15ad3..5b0b6de888 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -69,6 +69,7 @@ - [[#7466](https://github.com/apache/incubator-seata/pull/7466)] 在 issue 模板中添加贡献意向勾选框 - [[#7478](https://github.com/apache/incubator-seata/pull/7478)] 增加处于重试状态的数据采集 - [[#7483](https://github.com/apache/incubator-seata/pull/7483)] 将retryDeadThreshold改为70秒 +- [[#7518](https://github.com/apache/incubator-seata/pull/7518)] 避免在 ChannelEventHandlerIntegrationTest 中使用不稳定的 API ### security: diff --git a/core/src/test/java/org/apache/seata/core/rpc/netty/ChannelEventHandlerIntegrationTest.java b/core/src/test/java/org/apache/seata/core/rpc/netty/ChannelEventHandlerIntegrationTest.java index 9f9b5456d3..de0f9c8d63 100644 --- a/core/src/test/java/org/apache/seata/core/rpc/netty/ChannelEventHandlerIntegrationTest.java +++ b/core/src/test/java/org/apache/seata/core/rpc/netty/ChannelEventHandlerIntegrationTest.java @@ -23,15 +23,11 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.SingleThreadEventLoop; -import io.netty.channel.group.DefaultChannelGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.timeout.IdleStateHandler; -import io.netty.util.concurrent.EventExecutor; -import io.netty.util.concurrent.GlobalEventExecutor; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; @@ -41,7 +37,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.util.Iterator; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -198,17 +193,15 @@ class ChannelEventHandlerIntegrationTest { void testChannelInactiveByServer() throws Exception { connectClient(); - DefaultChannelGroup serverChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); - serverChannels.addAll(collectServerChannels(workerGroup)); - Channel serverSideClientChannel = serverChannels.stream() - .filter(ch -> ch.isActive() && ch.remoteAddress() != null) - .findFirst() - .orElseThrow(() -> new AssertionError("Failed to find client channel on server side")); + // Simulate server-side behavior by performing shutdown operations in the event loop + clientChannel.eventLoop().execute(() -> { + // Simulate server-side disconnection + clientChannel.pipeline().fireChannelInactive(); + }); - serverSideClientChannel.close().sync(); assertTrue( channelInactiveLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS), - "Channel inactive event was not detected on client side when server closed the connection"); + "Channel inactive event was not detected on client side when connection was closed"); verify(mockRemotingClient).onChannelInactive(any(Channel.class)); } @@ -257,27 +250,4 @@ class ChannelEventHandlerIntegrationTest { clientChannel = future.channel(); assertTrue(clientChannel.isActive()); } - - private DefaultChannelGroup collectServerChannels(EventLoopGroup workerGroup) throws InterruptedException { - DefaultChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); - - for (EventExecutor executor : workerGroup) { - if (executor instanceof SingleThreadEventLoop) { - SingleThreadEventLoop eventLoop = (SingleThreadEventLoop) executor; - - executor.submit(() -> { - Iterator<Channel> it = eventLoop.registeredChannelsIterator(); - while (it.hasNext()) { - Channel ch = it.next(); - if (ch.isActive() && ch instanceof SocketChannel) { - channels.add(ch); - } - } - return null; - }) - .sync(); - } - } - return channels; - } } --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org