Skip to content

Commit

Permalink
Optimize PropertiesConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangML committed Nov 17, 2023
1 parent 2bb667f commit 380e389
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
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 @@ -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 @@ -69,7 +69,7 @@ void assertGetRowData() {
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 @@ -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 @@ -21,6 +21,8 @@
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.util.json.JsonUtils;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ void assertConvert() {

@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 @@ -58,14 +58,14 @@ void assertExecute() {
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
Expand Down

0 comments on commit 380e389

Please sign in to comment.