This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 1003190cca9 Optimize PropertiesConverter (#29065)
1003190cca9 is described below
commit 1003190cca96526727510915aeb66305de601dbd
Author: jiangML <[email protected]>
AuthorDate: Fri Nov 17 14:59:18 2023 +0800
Optimize PropertiesConverter (#29065)
---
.../encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java | 2 +-
.../mask/distsql/handler/query/ShowMaskRuleExecutorTest.java | 2 +-
.../shadow/distsql/query/ShowShadowRuleExecutorTest.java | 4 ++--
.../sharding/distsql/query/ShowShardingTableRuleExecutorTest.java | 2 +-
.../distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java | 2 +-
.../org/apache/shardingsphere/infra/props/PropertiesConverter.java | 6 +++++-
.../apache/shardingsphere/infra/props/PropertiesConverterTest.java | 2 +-
.../traffic/distsql/handler/query/ShowTrafficRuleExecutorTest.java | 6 +++---
8 files changed, 15 insertions(+), 11 deletions(-)
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
index a334774dc1d..02d4d7ff7e3 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
@@ -58,7 +58,7 @@ class ShowEncryptRuleExecutorTest {
assertThat(row.getCell(4), is("user_assisted"));
assertThat(row.getCell(5), is("user_like"));
assertThat(row.getCell(6), is("md5"));
- assertThat(row.getCell(7), is("{}"));
+ assertThat(row.getCell(7), is(""));
assertThat(row.getCell(8), is(""));
assertThat(row.getCell(9), is(""));
assertThat(row.getCell(10), is(""));
diff --git
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java
index 096704a189f..a6e59fc54e5 100644
---
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java
+++
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutorTest.java
@@ -55,7 +55,7 @@ class ShowMaskRuleExecutorTest {
assertThat(row.getCell(1), is("t_mask"));
assertThat(row.getCell(2), is("user_id"));
assertThat(row.getCell(3), is("md5"));
- assertThat(row.getCell(4), is("{}"));
+ assertThat(row.getCell(4), is(""));
}
@Test
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java
index 91270ddc484..593cabbd9f8 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowRuleExecutorTest.java
@@ -56,14 +56,14 @@ class ShowShadowRuleExecutorTest {
assertThat(row.getCell(3), is("source"));
assertThat(row.getCell(4), is("shadow"));
assertThat(row.getCell(5), is("REGEX_MATCH"));
- assertThat(row.getCell(6), is("{}"));
+ assertThat(row.getCell(6), is(""));
row = iterator.next();
assertThat(row.getCell(1), is("t_order_item"));
assertThat(row.getCell(2), is("shadow_rule"));
assertThat(row.getCell(3), is("source"));
assertThat(row.getCell(4), is("shadow"));
assertThat(row.getCell(5), is("REGEX_MATCH"));
- assertThat(row.getCell(6), is("{}"));
+ assertThat(row.getCell(6), is(""));
}
@Test
diff --git
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
index 63e737d7de8..353d56c86e9 100644
---
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
+++
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
@@ -69,7 +69,7 @@ class ShowShardingTableRuleExecutorTest {
assertThat(row.getCell(11),
is("{\"algorithm-expression\":\"t_order_${order_id % 2}\"}"));
assertThat(row.getCell(12), is("order_id"));
assertThat(row.getCell(13), is("SNOWFLAKE"));
- assertThat(row.getCell(14), is("{}"));
+ assertThat(row.getCell(14), is(""));
assertThat(row.getCell(15), is("DML_SHARDING_CONDITIONS"));
assertThat(row.getCell(16), is("true"));
}
diff --git
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java
index 40b33b7bce9..ea1b40a2c3a 100644
---
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java
+++
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingKeyGeneratorExecutorTest.java
@@ -53,7 +53,7 @@ class ShowUnusedShardingKeyGeneratorExecutorTest {
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("uuid_key_generator"));
assertThat(row.getCell(2), is("UUID"));
- assertThat(row.getCell(3), is("{}"));
+ assertThat(row.getCell(3), is(""));
}
@Test
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/props/PropertiesConverter.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/props/PropertiesConverter.java
index b795f478603..bc3fc0a88f5 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/props/PropertiesConverter.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/props/PropertiesConverter.java
@@ -21,6 +21,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.Properties;
/**
@@ -36,6 +38,8 @@ public final class PropertiesConverter {
* @return converted string content
*/
public static String convert(final Properties props) {
- return JsonUtils.toJsonString(props);
+ Map<Object, Object> sortedProps = new LinkedHashMap<>();
+ props.keySet().stream().map(Object::toString).sorted().forEach(each ->
sortedProps.put(each, props.get(each)));
+ return sortedProps.isEmpty() ? "" :
JsonUtils.toJsonString(sortedProps);
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/props/PropertiesConverterTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/props/PropertiesConverterTest.java
index 657899a3290..3b52f18f0d1 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/props/PropertiesConverterTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/props/PropertiesConverterTest.java
@@ -35,6 +35,6 @@ class PropertiesConverterTest {
@Test
void assertConvertEmptyProperties() {
- assertThat(PropertiesConverter.convert(new Properties()), is("{}"));
+ assertThat(PropertiesConverter.convert(new Properties()), is(""));
}
}
diff --git
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/ShowTrafficRuleExecutorTest.java
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/ShowTrafficRuleExecutorTest.java
index 95f8d5aff0e..0fc8570d3f4 100644
---
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/ShowTrafficRuleExecutorTest.java
+++
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/ShowTrafficRuleExecutorTest.java
@@ -58,14 +58,14 @@ class ShowTrafficRuleExecutorTest {
assertThat(row.getCell(3), is("SQL_MATCH"));
assertThat(row.getCell(4), is("{\"sql\":\"select * from t_order\"}"));
assertThat(row.getCell(5), is("RANDOM"));
- assertThat(row.getCell(6), is("{}"));
+ assertThat(row.getCell(6), is(""));
row = iterator.next();
assertThat(row.getCell(1), is("rule_name_2"));
assertThat(row.getCell(2), is("oltp"));
assertThat(row.getCell(3), is("SQL_HINT"));
- assertThat(row.getCell(4), is("{}"));
+ assertThat(row.getCell(4), is(""));
assertThat(row.getCell(5), is("ROBIN"));
- assertThat(row.getCell(6), is("{}"));
+ assertThat(row.getCell(6), is(""));
}
@Test