Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor parse of properties #29043

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, Object> createExportedData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("{}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down