From ef70dd937a59b07316f8c8f323b7150508921cbf Mon Sep 17 00:00:00 2001 From: Pace2Car Date: Wed, 15 Nov 2023 19:37:12 +0800 Subject: [PATCH] Refactor parse of properties --- .../handler/query/ShowEncryptRuleExecutorTest.java | 2 +- .../distsql/handler/query/ShowMaskRuleExecutorTest.java | 2 +- .../query/ShowReadwriteSplittingRuleExecutorTest.java | 4 ++-- .../query/ShowDefaultShadowAlgorithmExecutorTest.java | 2 +- .../distsql/query/ShowShadowAlgorithmsExecutorTest.java | 2 +- .../shadow/distsql/query/ShowShadowRuleExecutorTest.java | 4 ++-- .../distsql/query/ShowShardingAlgorithmExecutorTest.java | 2 +- .../distsql/query/ShowShardingTableRuleExecutorTest.java | 6 +++--- .../query/ShowUnusedShardingAlgorithmsExecutorTest.java | 2 +- .../query/ShowUnusedShardingKeyGeneratorExecutorTest.java | 2 +- .../shardingsphere/infra/props/PropertiesConverter.java | 4 ++-- .../infra/props/PropertiesConverterTest.java | 4 ++-- .../handler/query/ShowTrafficRuleExecutorTest.java | 8 ++++---- .../handler/query/ShowTransactionRuleExecutorTest.java | 4 ++-- .../update/AlterTransactionRuleStatementUpdaterTest.java | 4 ++-- 15 files changed, 26 insertions(+), 26 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 02d4d7ff7e317..a334774dc1d99 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 @@ void assertGetRowData() { 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 a6e59fc54e54f..096704a189fdc 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 @@ void assertGetRowData() { 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/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java index f13e12bc5ea8b..9e7b0db50cf42 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java @@ -74,7 +74,7 @@ void assertGetRowData() { assertThat(row.getCell(3), is("ds_slave_0,ds_slave_1")); assertThat(row.getCell(4), is("DYNAMIC")); assertThat(row.getCell(5), is("random")); - assertThat(row.getCell(6), is("read_weight=2:1")); + assertThat(row.getCell(6), is("{\"read_weight\":\"2:1\"}")); } @Test @@ -94,7 +94,7 @@ void assertGetRowDataWithSpecifiedRuleName() { assertThat(row.getCell(3), is("ds_slave_0,ds_slave_1")); assertThat(row.getCell(4), is("DYNAMIC")); assertThat(row.getCell(5), is("random")); - assertThat(row.getCell(6), is("read_weight=2:1")); + assertThat(row.getCell(6), is("{\"read_weight\":\"2:1\"}")); } private Map createExportedData() { diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java index 6b3b9b7df3934..ca4687269746a 100644 --- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java +++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowDefaultShadowAlgorithmExecutorTest.java @@ -53,7 +53,7 @@ void assertGetRowData() { LocalDataQueryResultRow row = iterator.next(); assertThat(row.getCell(1), is("shadowAlgorithmName")); assertThat(row.getCell(2), is("sql_hint")); - assertThat(row.getCell(3), is("foo=bar")); + assertThat(row.getCell(3), is("{\"foo\":\"bar\"}")); } @Test diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java index b2a0bd7c7604b..de7c4e52302a5 100644 --- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java +++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmsExecutorTest.java @@ -53,7 +53,7 @@ void assertGetRowData() { LocalDataQueryResultRow row = iterator.next(); assertThat(row.getCell(1), is("shadowAlgorithmName")); assertThat(row.getCell(2), is("sql_hint")); - assertThat(row.getCell(3), is("foo=bar")); + assertThat(row.getCell(3), is("{\"foo\":\"bar\"}")); assertThat(row.getCell(4), is("false")); } 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 593cabbd9f8fe..91270ddc484db 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 @@ void assertGetRowData() { 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/ShowShardingAlgorithmExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAlgorithmExecutorTest.java index 936ce1a39fc9d..53281fbb36d46 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAlgorithmExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingAlgorithmExecutorTest.java @@ -52,7 +52,7 @@ void assertGetRowData() { LocalDataQueryResultRow row = iterator.next(); assertThat(row.getCell(1), is("database_inline")); assertThat(row.getCell(2), is("INLINE")); - assertThat(row.getCell(3), is("algorithm-expression=ds_${user_id % 2}")); + assertThat(row.getCell(3), is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}")); } private ShardingSphereDatabase mockDatabase() { 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 981bed6af9589..63e737d7de863 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 @@ -62,14 +62,14 @@ void assertGetRowData() { assertThat(row.getCell(4), is("STANDARD")); assertThat(row.getCell(5), is("user_id")); assertThat(row.getCell(6), is("INLINE")); - assertThat(row.getCell(7), is("algorithm-expression=ds_${user_id % 2}")); + assertThat(row.getCell(7), is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}")); assertThat(row.getCell(8), is("STANDARD")); assertThat(row.getCell(9), is("order_id")); assertThat(row.getCell(10), is("INLINE")); - assertThat(row.getCell(11), is("algorithm-expression=t_order_${order_id % 2}")); + 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/ShowUnusedShardingAlgorithmsExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAlgorithmsExecutorTest.java index ed8f3db4f026c..fc0b794094221 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAlgorithmsExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAlgorithmsExecutorTest.java @@ -54,7 +54,7 @@ void assertGetRowData() { LocalDataQueryResultRow row = iterator.next(); assertThat(row.getCell(1), is("database_inline")); assertThat(row.getCell(2), is("INLINE")); - assertThat(row.getCell(3), is("algorithm-expression=ds_${user_id % 2}")); + assertThat(row.getCell(3), is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}")); } @Test 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 ea1b40a2c3a3d..40b33b7bce985 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 @@ void assertGetRowData() { 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 8c5cc71be2929..b795f47860316 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 @@ -19,9 +19,9 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.infra.util.json.JsonUtils; import java.util.Properties; -import java.util.stream.Collectors; /** * Properties converter. @@ -36,6 +36,6 @@ public final class PropertiesConverter { * @return converted string content */ public static String convert(final Properties props) { - return props.entrySet().stream().map(entry -> String.join("=", entry.getKey().toString(), entry.getValue().toString())).sorted().collect(Collectors.joining(",")); + return JsonUtils.toJsonString(props); } } 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 ecfb88729471d..657899a3290bc 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 @@ -30,11 +30,11 @@ class PropertiesConverterTest { @Test void assertConvert() { - assertThat(PropertiesConverter.convert(PropertiesBuilder.build(new Property("foo", "foo_value"), new Property("bar", "bar_value"))), is("bar=bar_value,foo=foo_value")); + assertThat(PropertiesConverter.convert(PropertiesBuilder.build(new Property("foo", "foo_value"), new Property("bar", "bar_value"))), is("{\"bar\":\"bar_value\",\"foo\":\"foo_value\"}")); } @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 1cf1fa176bb63..95f8d5aff0e99 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 @@ -56,16 +56,16 @@ void assertExecute() { assertThat(row.getCell(1), is("rule_name_1")); assertThat(row.getCell(2), is("olap,order_by")); assertThat(row.getCell(3), is("SQL_MATCH")); - assertThat(row.getCell(4), is("sql=select * from t_order")); + 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 diff --git a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java index 03846b22f5f5e..3853f35528fe9 100644 --- a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java +++ b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/ShowTransactionRuleExecutorTest.java @@ -56,8 +56,8 @@ void assertExecuteWithXA() { assertThat(row.getCell(1), is(TransactionType.XA.name())); assertThat(row.getCell(2), is("Atomikos")); String props = (String) row.getCell(3); - assertTrue(props.contains("databaseName=jbossts")); - assertTrue(props.contains("host=127.0.0.1")); + assertTrue(props.contains("\"databaseName\":\"jbossts\"")); + assertTrue(props.contains("\"host\":\"127.0.0.1\"")); } @Test diff --git a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java index d2f84d8c14379..cbf543c2e5c99 100644 --- a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java +++ b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java @@ -54,8 +54,8 @@ void assertExecuteWithXA() { assertThat(actual.getProviderType(), is("Atomikos")); assertFalse(actual.getProps().isEmpty()); String props = PropertiesConverter.convert(actual.getProps()); - assertTrue(props.contains("host=127.0.0.1")); - assertTrue(props.contains("databaseName=jbossts")); + assertTrue(props.contains("\"host\":\"127.0.0.1\"")); + assertTrue(props.contains("\"databaseName\":\"jbossts\"")); } @Test