This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 24c7c897252 Refactor RepositoryTupleSwapper (#31080)
24c7c897252 is described below
commit 24c7c897252fa0193c3c3e1e4c3eddfc390bc354
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Apr 30 20:17:51 2024 +0800
Refactor RepositoryTupleSwapper (#31080)
---
...astRuleConfigurationRepositoryTupleSwapper.java | 6 +--
...uleConfigurationRepositoryTupleSwapperTest.java | 6 ---
...yptRuleConfigurationRepositoryTupleSwapper.java | 12 ++---
...uleConfigurationRepositoryTupleSwapperTest.java | 6 ---
...askRuleConfigurationRepositoryTupleSwapper.java | 13 +++---
...uleConfigurationRepositoryTupleSwapperTest.java | 7 ---
...ingRuleConfigurationRepositoryTupleSwapper.java | 14 +++---
...uleConfigurationRepositoryTupleSwapperTest.java | 6 ---
...dowRuleConfigurationRepositoryTupleSwapper.java | 20 ++++----
...uleConfigurationRepositoryTupleSwapperTest.java | 6 ---
...ingRuleConfigurationRepositoryTupleSwapper.java | 53 +++++++++++-----------
...uleConfigurationRepositoryTupleSwapperTest.java | 5 --
.../config/RepositoryTupleSwapperEngine.java | 3 ++
...gleRuleConfigurationRepositoryTupleSwapper.java | 6 +--
14 files changed, 63 insertions(+), 100 deletions(-)
diff --git
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
index 06be262750c..a4bcb42e9a4 100644
---
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
+++
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
*/
public final class BroadcastRuleConfigurationRepositoryTupleSwapper implements
RepositoryTupleSwapper<BroadcastRuleConfiguration,
YamlBroadcastRuleConfiguration> {
- private final RuleNodePath broadcastRuleNodePath = new
BroadcastRuleNodePathProvider().getRuleNodePath();
+ private final RuleNodePath ruleNodePath = new
BroadcastRuleNodePathProvider().getRuleNodePath();
@Override
public Collection<RepositoryTuple> swapToRepositoryTuples(final
YamlBroadcastRuleConfiguration yamlRuleConfig) {
@@ -48,9 +48,9 @@ public final class
BroadcastRuleConfigurationRepositoryTupleSwapper implements R
@Override
public Optional<YamlBroadcastRuleConfiguration> swapToObject(final
Collection<RepositoryTuple> repositoryTuples) {
- List<RepositoryTuple> validTuples =
repositoryTuples.stream().filter(each ->
broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ List<RepositoryTuple> validTuples =
repositoryTuples.stream().filter(each ->
ruleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
for (RepositoryTuple each : validTuples) {
- if
(broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())) {
+ if (ruleNodePath.getRoot().isValidatedPath(each.getKey())) {
return Optional.of(YamlEngine.unmarshal(each.getValue(),
YamlBroadcastRuleConfiguration.class));
}
}
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
index 4afdbc39dc7..c39063b6a26 100644
---
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
@@ -31,7 +31,6 @@ import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class BroadcastRuleConfigurationRepositoryTupleSwapperTest {
@@ -52,11 +51,6 @@ class BroadcastRuleConfigurationRepositoryTupleSwapperTest {
assertThat(iterator.next().getKey(), is("tables"));
}
- @Test
- void assertSwapToObjectWithEmptyTuple() {
- assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
- }
-
@Test
void assertSwapToObject() {
RepositoryTuple repositoryTuple = new
RepositoryTuple("/metadata/foo_db/rules/broadcast/tables", "tables:\n-
foo_table\n- foo_table2\n");
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
index a6ac19c395f..4bbcbfe23e6 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
@@ -42,23 +42,23 @@ import java.util.stream.Collectors;
*/
public final class EncryptRuleConfigurationRepositoryTupleSwapper implements
RepositoryTupleSwapper<EncryptRuleConfiguration, YamlEncryptRuleConfiguration> {
- private final RuleNodePath encryptRuleNodePath = new
EncryptRuleNodePathProvider().getRuleNodePath();
+ private final RuleNodePath ruleNodePath = new
EncryptRuleNodePathProvider().getRuleNodePath();
@Override
public Collection<RepositoryTuple> swapToRepositoryTuples(final
YamlEncryptRuleConfiguration yamlRuleConfig) {
Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, YamlAlgorithmConfiguration> entry :
yamlRuleConfig.getEncryptors().entrySet()) {
- result.add(new
RepositoryTuple(encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
}
for (YamlEncryptTableRuleConfiguration each :
yamlRuleConfig.getTables().values()) {
- result.add(new
RepositoryTuple(encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getPath(each.getName()),
YamlEngine.marshal(each)));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getPath(each.getName()),
YamlEngine.marshal(each)));
}
return result;
}
@Override
public Optional<YamlEncryptRuleConfiguration> swapToObject(final
Collection<RepositoryTuple> repositoryTuples) {
- List<RepositoryTuple> validTuples =
repositoryTuples.stream().filter(each ->
encryptRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ List<RepositoryTuple> validTuples =
repositoryTuples.stream().filter(each ->
ruleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
if (validTuples.isEmpty()) {
return Optional.empty();
}
@@ -66,9 +66,9 @@ public final class
EncryptRuleConfigurationRepositoryTupleSwapper implements Rep
Map<String, YamlEncryptTableRuleConfiguration> tables = new
LinkedHashMap<>();
Map<String, YamlAlgorithmConfiguration> encryptors = new
LinkedHashMap<>();
for (RepositoryTuple each : validTuples) {
-
encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getName(each.getKey())
+
ruleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getName(each.getKey())
.ifPresent(optional -> tables.put(optional,
YamlEngine.unmarshal(each.getValue(),
YamlEncryptTableRuleConfiguration.class)));
-
encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getName(each.getKey())
+
ruleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getName(each.getKey())
.ifPresent(optional -> encryptors.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
}
yamlRuleConfig.setTables(tables);
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
index 8a0537d7c62..bdaba845b3a 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
@@ -36,7 +36,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class EncryptRuleConfigurationRepositoryTupleSwapperTest {
@@ -64,11 +63,6 @@ class EncryptRuleConfigurationRepositoryTupleSwapperTest {
return new EncryptRuleConfiguration(tables,
Collections.singletonMap("FOO", new AlgorithmConfiguration("FOO", new
Properties())));
}
- @Test
- void assertSwapToObjectWithEmptyTuple() {
- assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
- }
-
@Test
void assertSwapToObject() {
Collection<RepositoryTuple> repositoryTuples = Arrays.asList(new
RepositoryTuple("/metadata/foo_db/rules/encrypt/tables/foo/versions/0",
"columns:\n"
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
index cc7e811bec8..715683e0e37 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
@@ -31,7 +31,6 @@ import
org.apache.shardingsphere.mode.spi.RepositoryTupleSwapper;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
@@ -42,23 +41,23 @@ import java.util.stream.Collectors;
*/
public final class MaskRuleConfigurationRepositoryTupleSwapper implements
RepositoryTupleSwapper<MaskRuleConfiguration, YamlMaskRuleConfiguration> {
- private final RuleNodePath maskRuleNodePath = new
MaskRuleNodePathProvider().getRuleNodePath();
+ private final RuleNodePath ruleNodePath = new
MaskRuleNodePathProvider().getRuleNodePath();
@Override
public Collection<RepositoryTuple> swapToRepositoryTuples(final
YamlMaskRuleConfiguration yamlRuleConfig) {
Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, YamlAlgorithmConfiguration> entry :
yamlRuleConfig.getMaskAlgorithms().entrySet()) {
- result.add(new
RepositoryTuple(maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
}
for (YamlMaskTableRuleConfiguration each :
yamlRuleConfig.getTables().values()) {
- result.add(new
RepositoryTuple(maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getPath(each.getName()),
YamlEngine.marshal(each)));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getPath(each.getName()),
YamlEngine.marshal(each)));
}
return result;
}
@Override
public Optional<YamlMaskRuleConfiguration> swapToObject(final
Collection<RepositoryTuple> repositoryTuples) {
- List<RepositoryTuple> validTuples =
repositoryTuples.stream().filter(each ->
maskRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ Collection<RepositoryTuple> validTuples =
repositoryTuples.stream().filter(each ->
ruleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
if (validTuples.isEmpty()) {
return Optional.empty();
}
@@ -66,9 +65,9 @@ public final class
MaskRuleConfigurationRepositoryTupleSwapper implements Reposi
Map<String, YamlMaskTableRuleConfiguration> tables = new
LinkedHashMap<>();
Map<String, YamlAlgorithmConfiguration> maskAlgorithms = new
LinkedHashMap<>();
for (RepositoryTuple each : validTuples) {
-
maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getName(each.getKey())
+
ruleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getName(each.getKey())
.ifPresent(optional -> tables.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlMaskTableRuleConfiguration.class)));
-
maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getName(each.getKey())
+
ruleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getName(each.getKey())
.ifPresent(optional -> maskAlgorithms.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
}
yamlRuleConfig.setTables(tables);
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
index 17854bfb05a..c2454026034 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
@@ -30,13 +30,11 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class MaskRuleConfigurationRepositoryTupleSwapperTest {
@@ -62,11 +60,6 @@ class MaskRuleConfigurationRepositoryTupleSwapperTest {
return new MaskRuleConfiguration(tables,
Collections.singletonMap("FIXTURE", new AlgorithmConfiguration("FIXTURE", new
Properties())));
}
- @Test
- void assertSwapToObjectWithEmptyTuple() {
- assertFalse(new
MaskRuleConfigurationRepositoryTupleSwapper().swapToObject(new
LinkedList<>()).isPresent());
- }
-
@Test
void assertSwapToObject() {
Collection<RepositoryTuple> repositoryTuples = Arrays.asList(new
RepositoryTuple("/metadata/foo_db/rules/mask/tables/foo/versions/0",
"columns:\n"
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
index 7835e9c0f9a..50a1e72df56 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
@@ -42,25 +42,23 @@ import java.util.stream.Collectors;
*/
public final class ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper
implements RepositoryTupleSwapper<ReadwriteSplittingRuleConfiguration,
YamlReadwriteSplittingRuleConfiguration> {
- private final RuleNodePath readwriteSplittingRuleNodePath = new
ReadwriteSplittingRuleNodePathProvider().getRuleNodePath();
+ private final RuleNodePath ruleNodePath = new
ReadwriteSplittingRuleNodePathProvider().getRuleNodePath();
@Override
public Collection<RepositoryTuple> swapToRepositoryTuples(final
YamlReadwriteSplittingRuleConfiguration yamlRuleConfig) {
Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, YamlAlgorithmConfiguration> entry :
yamlRuleConfig.getLoadBalancers().entrySet()) {
- result.add(new
RepositoryTuple(readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getPath(entry.getKey()),
- YamlEngine.marshal(entry.getValue())));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
}
for (Entry<String,
YamlReadwriteSplittingDataSourceGroupRuleConfiguration> entry :
yamlRuleConfig.getDataSourceGroups().entrySet()) {
- result.add(new RepositoryTuple(
-
readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
}
return result;
}
@Override
public Optional<YamlReadwriteSplittingRuleConfiguration>
swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
- List<RepositoryTuple> validRepositoryTuples =
repositoryTuples.stream().filter(each ->
readwriteSplittingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ List<RepositoryTuple> validRepositoryTuples =
repositoryTuples.stream().filter(each ->
ruleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
if (validRepositoryTuples.isEmpty()) {
return Optional.empty();
}
@@ -68,9 +66,9 @@ public final class
ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper imp
Map<String, YamlReadwriteSplittingDataSourceGroupRuleConfiguration>
dataSourceGroups = new LinkedHashMap<>();
Map<String, YamlAlgorithmConfiguration> loadBalancers = new
LinkedHashMap<>();
for (RepositoryTuple each : validRepositoryTuples) {
-
readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
+
ruleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
.ifPresent(optional -> dataSourceGroups.put(optional,
YamlEngine.unmarshal(each.getValue(),
YamlReadwriteSplittingDataSourceGroupRuleConfiguration.class)));
-
readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getName(each.getKey())
+
ruleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getName(each.getKey())
.ifPresent(optional -> loadBalancers.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
}
yamlRuleConfig.setDataSourceGroups(dataSourceGroups);
diff --git
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
index 9f993aa118f..614080ab60d 100644
---
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
+++
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
@@ -36,7 +36,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest {
@@ -64,11 +63,6 @@ class
ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest {
assertThat(iterator.next().getKey(), is("data_sources/foo_group"));
}
- @Test
- void assertSwapToObjectWithEmptyTuple() {
- assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
- }
-
@Test
void assertSwapToObject() {
Collection<RepositoryTuple> repositoryTuples = Arrays.asList(new
RepositoryTuple("/metadata/foo_db/rules/readwrite_splitting/data_sources/foo_group/versions/0",
"loadBalancerName: random\n"
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
index ac963c9fe9d..5f223ea1217 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
@@ -44,29 +44,29 @@ import java.util.stream.Collectors;
*/
public final class ShadowRuleConfigurationRepositoryTupleSwapper implements
RepositoryTupleSwapper<ShadowRuleConfiguration, YamlShadowRuleConfiguration> {
- private final RuleNodePath shadowRuleNodePath = new
ShadowRuleNodePathProvider().getRuleNodePath();
+ private final RuleNodePath ruleNodePath = new
ShadowRuleNodePathProvider().getRuleNodePath();
@Override
public Collection<RepositoryTuple> swapToRepositoryTuples(final
YamlShadowRuleConfiguration yamlRuleConfig) {
Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, YamlAlgorithmConfiguration> entry :
yamlRuleConfig.getShadowAlgorithms().entrySet()) {
- result.add(new
RepositoryTuple(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.ALGORITHMS).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShadowRuleNodePathProvider.ALGORITHMS).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
}
if
(!Strings.isNullOrEmpty(yamlRuleConfig.getDefaultShadowAlgorithmName())) {
- result.add(new
RepositoryTuple(shadowRuleNodePath.getUniqueItem(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM).getPath(),
yamlRuleConfig.getDefaultShadowAlgorithmName()));
+ result.add(new
RepositoryTuple(ruleNodePath.getUniqueItem(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM).getPath(),
yamlRuleConfig.getDefaultShadowAlgorithmName()));
}
for (Entry<String, YamlShadowDataSourceConfiguration> entry :
yamlRuleConfig.getDataSources().entrySet()) {
- result.add(new
RepositoryTuple(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
}
for (Entry<String, YamlShadowTableConfiguration> entry :
yamlRuleConfig.getTables().entrySet()) {
- result.add(new
RepositoryTuple(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
+ result.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getPath(entry.getKey()),
YamlEngine.marshal(entry.getValue())));
}
return result;
}
@Override
public Optional<YamlShadowRuleConfiguration> swapToObject(final
Collection<RepositoryTuple> repositoryTuples) {
- List<RepositoryTuple> validRepositoryTuples =
repositoryTuples.stream().filter(each ->
shadowRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ List<RepositoryTuple> validRepositoryTuples =
repositoryTuples.stream().filter(each ->
ruleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
if (validRepositoryTuples.isEmpty()) {
return Optional.empty();
}
@@ -75,13 +75,13 @@ public final class
ShadowRuleConfigurationRepositoryTupleSwapper implements Repo
Map<String, YamlShadowTableConfiguration> tables = new
LinkedHashMap<>();
Map<String, YamlAlgorithmConfiguration> shadowAlgorithms = new
LinkedHashMap<>();
for (RepositoryTuple each : validRepositoryTuples) {
-
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
.ifPresent(optional -> dataSources.put(optional,
YamlEngine.unmarshal(each.getValue(),
YamlShadowDataSourceConfiguration.class)));
-
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getName(each.getKey())
.ifPresent(optional -> tables.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlShadowTableConfiguration.class)));
-
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.ALGORITHMS).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShadowRuleNodePathProvider.ALGORITHMS).getName(each.getKey())
.ifPresent(optional -> shadowAlgorithms.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
- if
(shadowRuleNodePath.getUniqueItem(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM).isValidatedPath(each.getKey()))
{
+ if
(ruleNodePath.getUniqueItem(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM).isValidatedPath(each.getKey()))
{
yamlRuleConfig.setDefaultShadowAlgorithmName(each.getValue());
}
}
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
index 067fdb28acb..85cea8a4e36 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
@@ -38,7 +38,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class ShadowRuleConfigurationRepositoryTupleSwapperTest {
@@ -77,11 +76,6 @@ class ShadowRuleConfigurationRepositoryTupleSwapperTest {
return result;
}
- @Test
- void assertSwapToObjectWithEmptyTuple() {
- assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
- }
-
@Test
void assertSwapToObject() {
Collection<RepositoryTuple> repositoryTuples = Arrays.asList(
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
index bbea7f4e98a..f307c0709cd 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
@@ -36,7 +36,6 @@ import
org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlShar
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
@@ -47,7 +46,7 @@ import java.util.stream.Collectors;
*/
public final class ShardingRuleConfigurationRepositoryTupleSwapper implements
RepositoryTupleSwapper<ShardingRuleConfiguration,
YamlShardingRuleConfiguration> {
- private final RuleNodePath shardingRuleNodePath = new
ShardingRuleNodePathProvider().getRuleNodePath();
+ private final RuleNodePath ruleNodePath = new
ShardingRuleNodePathProvider().getRuleNodePath();
@Override
public Collection<RepositoryTuple> swapToRepositoryTuples(final
YamlShardingRuleConfiguration yamlRuleConfig) {
@@ -55,10 +54,10 @@ public final class
ShardingRuleConfigurationRepositoryTupleSwapper implements Re
swapAlgorithms(yamlRuleConfig, result);
swapStrategies(yamlRuleConfig, result);
if (null != yamlRuleConfig.getDefaultShardingColumn()) {
- result.add(new
RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_SHARDING_COLUMN).getPath(),
yamlRuleConfig.getDefaultShardingColumn()));
+ result.add(new
RepositoryTuple(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_SHARDING_COLUMN).getPath(),
yamlRuleConfig.getDefaultShardingColumn()));
}
if (null != yamlRuleConfig.getShardingCache()) {
- result.add(new
RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.SHARDING_CACHE).getPath(),
YamlEngine.marshal(yamlRuleConfig.getShardingCache())));
+ result.add(new
RepositoryTuple(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.SHARDING_CACHE).getPath(),
YamlEngine.marshal(yamlRuleConfig.getShardingCache())));
}
swapTableRules(yamlRuleConfig, result);
return result;
@@ -66,44 +65,44 @@ public final class
ShardingRuleConfigurationRepositoryTupleSwapper implements Re
private void swapAlgorithms(final YamlShardingRuleConfiguration
yamlRuleConfig, final Collection<RepositoryTuple> repositoryTuples) {
for (Entry<String, YamlAlgorithmConfiguration> each :
yamlRuleConfig.getShardingAlgorithms().entrySet()) {
- repositoryTuples.add(new
RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.ALGORITHMS).getPath(each.getKey()),
YamlEngine.marshal(each.getValue())));
+ repositoryTuples.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.ALGORITHMS).getPath(each.getKey()),
YamlEngine.marshal(each.getValue())));
}
for (Entry<String, YamlAlgorithmConfiguration> each :
yamlRuleConfig.getKeyGenerators().entrySet()) {
- repositoryTuples.add(new
RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.KEY_GENERATORS).getPath(each.getKey()),
YamlEngine.marshal(each.getValue())));
+ repositoryTuples.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.KEY_GENERATORS).getPath(each.getKey()),
YamlEngine.marshal(each.getValue())));
}
for (Entry<String, YamlAlgorithmConfiguration> each :
yamlRuleConfig.getAuditors().entrySet()) {
- repositoryTuples.add(new
RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUDITORS).getPath(each.getKey()),
YamlEngine.marshal(each.getValue())));
+ repositoryTuples.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUDITORS).getPath(each.getKey()),
YamlEngine.marshal(each.getValue())));
}
}
private void swapStrategies(final YamlShardingRuleConfiguration
yamlRuleConfig, final Collection<RepositoryTuple> repositoryTuples) {
if (null != yamlRuleConfig.getDefaultDatabaseStrategy()) {
repositoryTuples.add(new RepositoryTuple(
-
shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultDatabaseStrategy())));
+
ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultDatabaseStrategy())));
}
if (null != yamlRuleConfig.getDefaultTableStrategy()) {
repositoryTuples.add(new RepositoryTuple(
-
shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultTableStrategy())));
+
ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultTableStrategy())));
}
if (null != yamlRuleConfig.getDefaultKeyGenerateStrategy()) {
repositoryTuples.add(new RepositoryTuple(
-
shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_KEY_GENERATE_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultKeyGenerateStrategy())));
+
ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_KEY_GENERATE_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultKeyGenerateStrategy())));
}
if (null != yamlRuleConfig.getDefaultAuditStrategy()) {
repositoryTuples.add(new RepositoryTuple(
-
shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_AUDIT_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultAuditStrategy())));
+
ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_AUDIT_STRATEGY).getPath(),
YamlEngine.marshal(yamlRuleConfig.getDefaultAuditStrategy())));
}
}
private void swapTableRules(final YamlShardingRuleConfiguration
yamlRuleConfig, final Collection<RepositoryTuple> repositoryTuples) {
for (YamlTableRuleConfiguration each :
yamlRuleConfig.getTables().values()) {
- repositoryTuples.add(new
RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getPath(each.getLogicTable()),
YamlEngine.marshal(each)));
+ repositoryTuples.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getPath(each.getLogicTable()),
YamlEngine.marshal(each)));
}
for (YamlShardingAutoTableRuleConfiguration each :
yamlRuleConfig.getAutoTables().values()) {
- repositoryTuples.add(new
RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getPath(each.getLogicTable()),
YamlEngine.marshal(each)));
+ repositoryTuples.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getPath(each.getLogicTable()),
YamlEngine.marshal(each)));
}
for (String each : yamlRuleConfig.getBindingTables()) {
- repositoryTuples.add(new
RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.BINDING_TABLES).getPath(getBindingGroupName(each)),
each));
+ repositoryTuples.add(new
RepositoryTuple(ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.BINDING_TABLES).getPath(getBindingGroupName(each)),
each));
}
}
@@ -113,7 +112,7 @@ public final class
ShardingRuleConfigurationRepositoryTupleSwapper implements Re
@Override
public Optional<YamlShardingRuleConfiguration> swapToObject(final
Collection<RepositoryTuple> repositoryTuples) {
- List<RepositoryTuple> validRepositoryTuples =
repositoryTuples.stream().filter(each ->
shardingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ Collection<RepositoryTuple> validRepositoryTuples =
repositoryTuples.stream().filter(each ->
ruleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
if (validRepositoryTuples.isEmpty()) {
return Optional.empty();
}
@@ -125,28 +124,28 @@ public final class
ShardingRuleConfigurationRepositoryTupleSwapper implements Re
Map<String, YamlAlgorithmConfiguration> keyGenerators = new
LinkedHashMap<>();
Map<String, YamlAlgorithmConfiguration> auditors = new
LinkedHashMap<>();
for (RepositoryTuple each : validRepositoryTuples) {
-
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getName(each.getKey())
.ifPresent(optional -> tables.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlTableRuleConfiguration.class)));
-
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getName(each.getKey())
.ifPresent(optional -> autoTables.put(optional,
YamlEngine.unmarshal(each.getValue(),
YamlShardingAutoTableRuleConfiguration.class)));
-
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.BINDING_TABLES).getName(each.getKey()).ifPresent(optional
-> bindingTables.add(each.getValue()));
-
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.ALGORITHMS).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.BINDING_TABLES).getName(each.getKey()).ifPresent(optional
-> bindingTables.add(each.getValue()));
+
ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.ALGORITHMS).getName(each.getKey())
.ifPresent(optional -> shardingAlgorithms.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
-
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.KEY_GENERATORS).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.KEY_GENERATORS).getName(each.getKey())
.ifPresent(optional -> keyGenerators.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
-
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUDITORS).getName(each.getKey())
+
ruleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUDITORS).getName(each.getKey())
.ifPresent(optional -> auditors.put(optional,
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
- if
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY).isValidatedPath(each.getKey()))
{
+ if
(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY).isValidatedPath(each.getKey()))
{
yamlRuleConfig.setDefaultDatabaseStrategy(YamlEngine.unmarshal(each.getValue(),
YamlShardingStrategyConfiguration.class));
- } else if
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY).isValidatedPath(each.getKey()))
{
+ } else if
(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY).isValidatedPath(each.getKey()))
{
yamlRuleConfig.setDefaultTableStrategy(YamlEngine.unmarshal(each.getValue(),
YamlShardingStrategyConfiguration.class));
- } else if
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_KEY_GENERATE_STRATEGY).isValidatedPath(each.getKey()))
{
+ } else if
(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_KEY_GENERATE_STRATEGY).isValidatedPath(each.getKey()))
{
yamlRuleConfig.setDefaultKeyGenerateStrategy(YamlEngine.unmarshal(each.getValue(),
YamlKeyGenerateStrategyConfiguration.class));
- } else if
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_AUDIT_STRATEGY).isValidatedPath(each.getKey()))
{
+ } else if
(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_AUDIT_STRATEGY).isValidatedPath(each.getKey()))
{
yamlRuleConfig.setDefaultAuditStrategy(YamlEngine.unmarshal(each.getValue(),
YamlShardingAuditStrategyConfiguration.class));
- } else if
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_SHARDING_COLUMN).isValidatedPath(each.getKey()))
{
+ } else if
(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_SHARDING_COLUMN).isValidatedPath(each.getKey()))
{
yamlRuleConfig.setDefaultShardingColumn(each.getValue());
- } else if
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.SHARDING_CACHE).isValidatedPath(each.getKey()))
{
+ } else if
(ruleNodePath.getUniqueItem(ShardingRuleNodePathProvider.SHARDING_CACHE).isValidatedPath(each.getKey()))
{
yamlRuleConfig.setShardingCache(YamlEngine.unmarshal(each.getValue(),
YamlShardingCacheConfiguration.class));
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
index ae83c35485b..d1f327fe607 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
@@ -113,11 +113,6 @@ class ShardingRuleConfigurationRepositoryTupleSwapperTest {
return result;
}
- @Test
- void assertSwapToObjectWithEmptyTuple() {
- assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
- }
-
@Test
void assertSwapToObject() {
Collection<RepositoryTuple> tuples = new LinkedList<>();
diff --git
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
index d4bf7cb58ea..399f24b805f 100644
---
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
+++
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
@@ -62,6 +62,9 @@ public final class RepositoryTupleSwapperEngine {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public Optional<RuleConfiguration> swapToRuleConfiguration(final String
ruleName, final Collection<RepositoryTuple> repositoryTuples) {
+ if (repositoryTuples.isEmpty()) {
+ return Optional.empty();
+ }
YamlRuleConfigurationSwapperEngine yamlSwapperEngine = new
YamlRuleConfigurationSwapperEngine();
for (RepositoryTupleSwapper each :
OrderedSPILoader.getServices(RepositoryTupleSwapper.class)) {
if (ruleName.equals(each.getRuleTagName().toLowerCase())) {
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
index 6cc5c46940c..b980235f0f0 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
*/
public final class SingleRuleConfigurationRepositoryTupleSwapper implements
RepositoryTupleSwapper<SingleRuleConfiguration, YamlSingleRuleConfiguration> {
- private final RuleNodePath singleRuleNodePath = new
SingleRuleNodePathProvider().getRuleNodePath();
+ private final RuleNodePath ruleNodePath = new
SingleRuleNodePathProvider().getRuleNodePath();
@Override
public Collection<RepositoryTuple> swapToRepositoryTuples(final
YamlSingleRuleConfiguration yamlRuleConfig) {
@@ -45,8 +45,8 @@ public final class
SingleRuleConfigurationRepositoryTupleSwapper implements Repo
@Override
public Optional<YamlSingleRuleConfiguration> swapToObject(final
Collection<RepositoryTuple> repositoryTuples) {
- for (RepositoryTuple each : repositoryTuples.stream().filter(each ->
singleRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList()))
{
- if
(singleRuleNodePath.getUniqueItem(SingleRuleNodePathProvider.TABLES).isValidatedPath(each.getKey()))
{
+ for (RepositoryTuple each : repositoryTuples.stream().filter(each ->
ruleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList()))
{
+ if
(ruleNodePath.getUniqueItem(SingleRuleNodePathProvider.TABLES).isValidatedPath(each.getKey()))
{
return Optional.of(YamlEngine.unmarshal(each.getValue(),
YamlSingleRuleConfiguration.class));
}
}