diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index a8fef0c576b..dbfcfbc29c1 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -37,8 +37,9 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7282](https://github.com/apache/incubator-seata/pull/7282)] optimize unexpected NullPointerException in lookup method in FileRegistryServiceImpl class
- [[#7310](https://github.com/seata/seata/pull/7310)] Optimize minor issues in the naming-server
- [[#7329](https://github.com/apache/incubator-seata/pull/7329)] upgrade tomcat to 9.0.100
-- [[#7344](https://github.com/apache/incubator-seata/pull/7344)] raft mode performs transaction size check in advance
- [[#7337](https://github.com/apache/incubator-seata/pull/7337)] Add ChannelEventListener support to prevent memory leaks
+- [[#7344](https://github.com/apache/incubator-seata/pull/7344)] raft mode performs transaction size check in advance
+- [[#7345](https://github.com/apache/incubator-seata/pull/7345)] add empty check and duplicate type check to RegistryFactory
- [[#7350](https://github.com/apache/incubator-seata/pull/7350)] optimize codecov.yml
- [[#7360](https://github.com/apache/incubator-seata/pull/7360)] Update resource cleanup logic for channel disconnection
@@ -70,6 +71,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7205](https://github.com/apache/incubator-seata/issues/7205)] add UT for namingserver module
- [[#7359](https://github.com/apache/incubator-seata/issues/7359)] merge submodule test reports
+
### refactor:
- [[#7315](https://github.com/apache/incubator-seata/pull/7315)] Refactor log testing to use ListAppender for more accurate and efficient log capture
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index dc139bd5be8..5e6c0d17ed0 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -35,8 +35,9 @@
- [[#7282](https://github.com/apache/incubator-seata/pull/7282)] 优化FileRegistryServiceImpl类lookup的NullPointerException问题
- [[#7310](https://github.com/seata/seata/pull/7310)] 优化naming-server中的一些小问题
- [[#7329](https://github.com/apache/incubator-seata/pull/7329)] 将 tomcat 升级到 9.0.100
-- [[#7344](https://github.com/apache/incubator-seata/pull/7344)] raft模式提前检查事务大小
- [[#7337](https://github.com/apache/incubator-seata/pull/7337)] 添加 ChannelEventListener 支持以防止内存泄漏
+- [[#7344](https://github.com/apache/incubator-seata/pull/7344)] raft模式提前检查事务大小
+- [[#7345](https://github.com/apache/incubator-seata/pull/7345)] 为 RegistryFactory 增加空校验与重复类型检查
- [[#7350](https://github.com/apache/incubator-seata/pull/7350)] 优化单测覆盖配置
- [[#7360](https://github.com/apache/incubator-seata/pull/7360)] 更新通道断开连接时的资源清理逻辑
diff --git a/discovery/seata-discovery-core/pom.xml b/discovery/seata-discovery-core/pom.xml
index 7aa7b77b37f..412be452fd6 100644
--- a/discovery/seata-discovery-core/pom.xml
+++ b/discovery/seata-discovery-core/pom.xml
@@ -35,5 +35,11 @@
seata-config-core${project.version}
+
+
+ ch.qos.logback
+ logback-classic
+ test
+
diff --git a/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/MultiRegistryFactory.java b/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/MultiRegistryFactory.java
index 3d2803f7a0b..34c15ab81ec 100644
--- a/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/MultiRegistryFactory.java
+++ b/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/MultiRegistryFactory.java
@@ -17,12 +17,14 @@
package org.apache.seata.discovery.registry;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
+import java.util.TreeSet;
import org.apache.seata.common.ConfigurationKeys;
import org.apache.seata.common.Constants;
-import org.apache.seata.common.exception.NotSupportYetException;
import org.apache.seata.common.loader.EnhancedServiceLoader;
import org.apache.seata.common.util.StringUtils;
import org.apache.seata.config.ConfigurationFactory;
@@ -31,7 +33,6 @@
/**
* The type multiple Registry factory.
- *
*/
public class MultiRegistryFactory {
@@ -48,25 +49,27 @@ public static List getInstances() {
private static List buildRegistryServices() {
List registryServices = new ArrayList<>();
- String registryTypeNamesStr =
- ConfigurationFactory.CURRENT_FILE_INSTANCE.getConfig(ConfigurationKeys.FILE_ROOT_REGISTRY
- + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR + ConfigurationKeys.FILE_ROOT_TYPE);
+
+ String registryTypeNamesStr = ConfigurationFactory.CURRENT_FILE_INSTANCE.getConfig(
+ ConfigurationKeys.FILE_ROOT_REGISTRY + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR + ConfigurationKeys.FILE_ROOT_TYPE);
+
+ // If blank, use default configuration
if (StringUtils.isBlank(registryTypeNamesStr)) {
registryTypeNamesStr = RegistryType.File.name();
}
- String[] registryTypeNames = registryTypeNamesStr.split(Constants.REGISTRY_TYPE_SPLIT_CHAR);
- if (registryTypeNames.length > 1) {
- LOGGER.info("use multi registry center type: {}", registryTypeNamesStr);
+
+ Set registryTypeNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+ registryTypeNames.addAll(Arrays.asList(registryTypeNamesStr.split(Constants.REGISTRY_TYPE_SPLIT_CHAR)));
+
+ if (registryTypeNames.size() > 1) {
+ LOGGER.info("use multi registry center type: {}", registryTypeNames);
}
+
for (String registryTypeName : registryTypeNames) {
- RegistryType registryType;
- try {
- registryType = RegistryType.getType(registryTypeName);
- } catch (Exception exx) {
- throw new NotSupportYetException("not support registry type: " + registryTypeName);
- }
+ RegistryType registryType = RegistryType.getType(registryTypeName);
+
RegistryService registryService = EnhancedServiceLoader
- .load(RegistryProvider.class, Objects.requireNonNull(registryType).name()).provide();
+ .load(RegistryProvider.class, Objects.requireNonNull(registryType).name()).provide();
registryServices.add(registryService);
}
return registryServices;
diff --git a/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryFactory.java b/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryFactory.java
index 501725c824b..45910382e48 100644
--- a/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryFactory.java
+++ b/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryFactory.java
@@ -18,8 +18,8 @@
import java.util.Objects;
-import org.apache.seata.common.exception.NotSupportYetException;
import org.apache.seata.common.loader.EnhancedServiceLoader;
+import org.apache.seata.common.util.StringUtils;
import org.apache.seata.config.ConfigurationFactory;
import org.apache.seata.config.ConfigurationKeys;
import org.slf4j.Logger;
@@ -27,7 +27,6 @@
/**
* The type Registry factory.
- *
*/
public class RegistryFactory {
@@ -43,16 +42,17 @@ public static RegistryService getInstance() {
}
private static RegistryService buildRegistryService() {
- RegistryType registryType;
String registryTypeName = ConfigurationFactory.CURRENT_FILE_INSTANCE.getConfig(
- ConfigurationKeys.FILE_ROOT_REGISTRY + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR
- + ConfigurationKeys.FILE_ROOT_TYPE);
- LOGGER.info("use registry center type: {}", registryTypeName);
- try {
- registryType = RegistryType.getType(registryTypeName);
- } catch (Exception exx) {
- throw new NotSupportYetException("not support registry type: " + registryTypeName);
+ ConfigurationKeys.FILE_ROOT_REGISTRY + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR + ConfigurationKeys.FILE_ROOT_TYPE);
+
+ // If blank, use default configuration
+ if (StringUtils.isBlank(registryTypeName)) {
+ registryTypeName = RegistryType.File.name();
}
+
+ LOGGER.info("use registry center type: {}", registryTypeName);
+
+ RegistryType registryType = RegistryType.getType(registryTypeName);
return EnhancedServiceLoader.load(RegistryProvider.class, Objects.requireNonNull(registryType).name()).provide();
}
diff --git a/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryType.java b/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryType.java
index cad816d42c5..4ae18a30489 100644
--- a/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryType.java
+++ b/discovery/seata-discovery-core/src/main/java/org/apache/seata/discovery/registry/RegistryType.java
@@ -16,6 +16,8 @@
*/
package org.apache.seata.discovery.registry;
+import org.apache.seata.common.exception.NotSupportYetException;
+
/**
* The enum Registry type.
*
@@ -78,6 +80,6 @@ public static RegistryType getType(String name) {
return registryType;
}
}
- throw new IllegalArgumentException("not support registry type: " + name);
+ throw new NotSupportYetException("not support registry type: " + name);
}
}
diff --git a/discovery/seata-discovery-core/src/test/java/org/apache/seata/discovery/registry/MockNacosRegistryProvider.java b/discovery/seata-discovery-core/src/test/java/org/apache/seata/discovery/registry/MockNacosRegistryProvider.java
new file mode 100644
index 00000000000..efd5529c19f
--- /dev/null
+++ b/discovery/seata-discovery-core/src/test/java/org/apache/seata/discovery/registry/MockNacosRegistryProvider.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.discovery.registry;
+
+import org.apache.seata.common.loader.LoadLevel;
+
+/**
+ * the mock nacos RegistryProvider
+ */
+@LoadLevel(name = "Nacos", order = 1)
+public class MockNacosRegistryProvider implements RegistryProvider {
+ @Override
+ public RegistryService provide() {
+ return new MockNacosRegistryService();
+ }
+}
\ No newline at end of file
diff --git a/discovery/seata-discovery-core/src/test/java/org/apache/seata/discovery/registry/MockNacosRegistryService.java b/discovery/seata-discovery-core/src/test/java/org/apache/seata/discovery/registry/MockNacosRegistryService.java
new file mode 100644
index 00000000000..834c6912316
--- /dev/null
+++ b/discovery/seata-discovery-core/src/test/java/org/apache/seata/discovery/registry/MockNacosRegistryService.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.discovery.registry;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * the mock nacos RegistryService
+ */
+public class MockNacosRegistryService implements RegistryService