This is an automated email from the ASF dual-hosted git repository.
jimin pushed a commit to branch 2.5.0
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.5.0 by this push:
new 33598d642c optimize: avoid using unstable API (#7514)
33598d642c is described below
commit 33598d642cf842472f5002b8a7d8c98632b80afd
Author: maple <[email protected]>
AuthorDate: Thu Jul 10 10:53:46 2025 +0800
optimize: avoid using unstable API (#7514)
---
.../netty/ChannelEventHandlerIntegrationTest.java | 42 ++++------------------
1 file changed, 6 insertions(+), 36 deletions(-)
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: [email protected]
For additional commands, e-mail: [email protected]