This is an automated email from the ASF dual-hosted git repository.

jianbin 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 5164f9b364 test: fix namingserver ut error (#7436)
5164f9b364 is described below

commit 5164f9b364cc5a1b9a6192348a803c6124e54691
Author: funkye <jian...@apache.org>
AuthorDate: Fri Jun 13 21:19:37 2025 +0800

    test: fix namingserver ut error (#7436)
---
 changes/en-us/2.x.md                                               | 3 +++
 changes/zh-cn/2.x.md                                               | 2 ++
 .../java/org/apache/seata/namingserver/manager/NamingManager.java  | 7 +++++++
 .../test/java/org/apache/seata/server/store/SessionStoreTest.java  | 6 ++++++
 4 files changed, 18 insertions(+)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index f283ecea3a..66d6d9735c 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -89,6 +89,9 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7420](https://github.com/apache/incubator-seata/pull/7420)] add UT for 
RemotingFactoryBeanParser class
 - [[#7379](https://github.com/apache/incubator-seata/issues/7379)] add UT for 
TccAnnotationProcessor class
 - [[#7422](https://github.com/apache/incubator-seata/pull/7422)] add UT for 
seata-spring-boot-starter module
+- [[#7436](https://github.com/apache/incubator-seata/pull/7436)] fix 
namingserver ut error
+- [[#7435](https://github.com/apache/incubator-seata/pull/7435)] Add common 
test config for dynamic server port assignment in tests
+
 
 ### refactor:
 
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index ae68246b62..dfea746522 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -89,6 +89,8 @@
 - [[#7420](https://github.com/apache/incubator-seata/pull/7420)] 为 
RemotingFactoryBeanParser 类添加了单元测试
 - [[#7379](https://github.com/apache/incubator-seata/issues/7379)] 为 
TccAnnotationProcessor 添加了单元测试 
 - [[#7422](https://github.com/apache/incubator-seata/pull/7422)] 为 
seata-spring-boot-starter 添加了测试
+- [[#7436](https://github.com/apache/incubator-seata/pull/7436)]  
修复namingserver 单测错误
+- [[#7435](https://github.com/apache/incubator-seata/pull/7435)] 
为测试中的动态服务器端口分配添加通用测试配置
 - [[#7432](https://github.com/apache/incubator-seata/pull/7432)] 使用Maven 
Profile按条件引入Test模块
 
 
diff --git 
a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
 
b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
index a2f3328254..8c88b3f622 100644
--- 
a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
+++ 
b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
@@ -246,6 +246,9 @@ public class NamingManager {
     }
 
     public boolean registerInstance(NamingServerNode node, String namespace, 
String clusterName, String unitName) {
+        if (node == null) {
+            return false;
+        }
         try {
             Map<String, ClusterData> clusterDataHashMap =
                 namespaceClusterDataMap.computeIfAbsent(namespace, k -> new 
ConcurrentHashMap<>());
@@ -326,6 +329,10 @@ public class NamingManager {
 
     public List<Node> getInstances(String namespace, String clusterName, 
boolean readOnly) {
         Map<String, ClusterData> clusterDataHashMap = 
namespaceClusterDataMap.get(namespace);
+        if (clusterDataHashMap == null) {
+            LOGGER.warn("no clusters in namespace: {}", namespace);
+            return Collections.emptyList();
+        }
         ClusterData clusterData = clusterDataHashMap.get(clusterName);
         if (clusterData == null) {
             LOGGER.warn("no instances in {} : {}", namespace, clusterName);
diff --git 
a/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java 
b/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java
index 8bbcb90c09..f7e7fb7e8d 100644
--- a/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java
+++ b/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java
@@ -33,6 +33,7 @@ import org.apache.seata.server.session.BranchSession;
 import org.apache.seata.server.session.GlobalSession;
 import org.apache.seata.server.session.SessionHelper;
 import org.apache.seata.server.session.SessionHolder;
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
@@ -86,6 +87,11 @@ public class SessionStoreTest {
         lockManager.cleanAllLocks();
     }
 
+    @AfterEach
+    public void after() throws Exception {
+        clean();
+    }
+
     /**
      * Test restored from file.
      *


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to