You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2025/04/14 07:12:24 UTC
(shardingsphere) branch master updated: Optimize properties data export in ClusterExportMetaDataGenerator (#35194)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 70b9915adff Optimize properties data export in ClusterExportMetaDataGenerator (#35194)
70b9915adff is described below
commit 70b9915adff009b6d5ec9c8ad737a8d565f13e7a
Author: jiangML <10...@qq.com>
AuthorDate: Mon Apr 14 15:12:18 2025 +0800
Optimize properties data export in ClusterExportMetaDataGenerator (#35194)
* Optimize properties data export in ClusterExportMetaDataGenerator
* Fix test error
---
.../util/ClusterExportMetaDataGenerator.java | 12 +-------
.../export/ExportMetaDataExecutorTest.java | 33 +++++++++++++++++++++-
2 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java
index 3a5ddb3c29e..2f029ed61a9 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ClusterExportMetaDataGenerator.java
@@ -77,17 +77,7 @@ public final class ClusterExportMetaDataGenerator {
}
private String generatePropsData(final Properties props) {
- if (props.isEmpty()) {
- return "";
- }
- StringBuilder result = new StringBuilder();
- result.append("props:").append(System.lineSeparator());
- for (Entry<Object, Object> entry : props.entrySet()) {
- if (null != entry.getValue() && !"".equals(entry.getValue().toString())) {
- result.append(" ").append(entry.getKey()).append(": ").append(entry.getValue()).append(System.lineSeparator());
- }
- }
- return result.toString();
+ return props.isEmpty() ? "" : YamlEngine.marshal(Collections.singletonMap("props", props));
}
@SuppressWarnings({"rawtypes", "unchecked"})
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java
index 8d2b0e93fae..81f38a41d90 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/export/ExportMetaDataExecutorTest.java
@@ -26,6 +26,8 @@ import org.apache.shardingsphere.globalclock.rule.builder.DefaultGlobalClockRule
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties;
+import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator;
import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
@@ -65,6 +67,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -230,11 +233,39 @@ class ExportMetaDataExecutorTest {
return;
}
assertThat(actual.size(), is(expected.size()));
+ ConfigurationProperties actualConfigProperties = new ConfigurationProperties(actual);
+ ConfigurationProperties expectedConfigProperties = new ConfigurationProperties(expected);
+ TemporaryConfigurationProperties actualTemporaryConfigProperties = new TemporaryConfigurationProperties(actual);
+ TemporaryConfigurationProperties expectedTemporaryConfigProperties = new TemporaryConfigurationProperties(expected);
for (Entry<Object, Object> entry : expected.entrySet()) {
- assertThat(actual.get(entry.getKey()), is(entry.getValue()));
+ Object actualValue = findConfigurationPropertyKey(String.valueOf(entry.getKey()))
+ .map(actualConfigProperties::getValue)
+ .orElseGet(() -> findTemporaryConfigurationPropertyKey(String.valueOf(entry.getKey())).map(actualTemporaryConfigProperties::getValue).orElse(null));
+ Object expectedValue = findConfigurationPropertyKey(String.valueOf(entry.getKey()))
+ .map(expectedConfigProperties::getValue)
+ .orElseGet(() -> findTemporaryConfigurationPropertyKey(String.valueOf(entry.getKey())).map(expectedTemporaryConfigProperties::getValue).orElse(null));
+ assertThat(actualValue, is(expectedValue));
}
}
+ private Optional<ConfigurationPropertyKey> findConfigurationPropertyKey(final String key) {
+ for (ConfigurationPropertyKey each : ConfigurationPropertyKey.values()) {
+ if (each.getKey().equalsIgnoreCase(key)) {
+ return Optional.of(each);
+ }
+ }
+ return Optional.empty();
+ }
+
+ private Optional<TemporaryConfigurationPropertyKey> findTemporaryConfigurationPropertyKey(final String key) {
+ for (TemporaryConfigurationPropertyKey each : TemporaryConfigurationPropertyKey.values()) {
+ if (each.getKey().equalsIgnoreCase(key)) {
+ return Optional.of(each);
+ }
+ }
+ return Optional.empty();
+ }
+
private void assertDatabaseConfig(final Map<String, String> actual, final Map<String, String> expected) {
assertThat(actual.size(), is(expected.size()));
for (Entry<String, String> entry : expected.entrySet()) {