This is an automated email from the ASF dual-hosted git repository.
yx9o 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 d5f97de2bb1 Use PropertiesBuilder in shadow module (#23271)
d5f97de2bb1 is described below
commit d5f97de2bb151787b2d490dcad09444d0e4d7d62
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jan 3 00:25:41 2023 +0800
Use PropertiesBuilder in shadow module (#23271)
* Use PropertiesBuilder in readwrite-splitting module
* Use PropertiesBuilder in shadow module
* Use PropertiesBuilder in shadow module
---
features/shadow/core/pom.xml | 6 ++++
.../ColumnRegexMatchShadowAlgorithmTest.java | 16 ++++-----
.../ColumnValueMatchShadowAlgorithmTest.java | 16 ++++-----
.../shadow/hint/SimpleHintShadowAlgorithmTest.java | 12 +++----
.../ShadowRuleConfigurationCheckerTest.java | 16 +++------
.../ColumnShadowAlgorithmDeterminerTest.java | 13 +++----
.../HintShadowAlgorithmDeterminerTest.java | 14 +++-----
.../ShadowDeleteStatementRoutingEngineTest.java | 13 ++-----
.../ShadowInsertStatementRoutingEngineTest.java | 13 ++-----
.../ShadowSelectStatementRoutingEngineTest.java | 13 ++-----
.../ShadowNonDMLStatementRoutingEngineTest.java | 11 ++----
.../shardingsphere/shadow/rule/ShadowRuleTest.java | 28 +++++----------
features/shadow/distsql/handler/pom.xml | 7 ++++
.../ShadowRuleStatementConverterTest.java | 19 ++++------
.../query/ShadowAlgorithmResultSetTest.java | 9 +++--
.../query/ShadowTableRuleResultSetTest.java | 13 +++----
...DefaultShadowAlgorithmStatementUpdaterTest.java | 41 ++++++++++------------
.../AlterShadowRuleStatementUpdaterTest.java | 19 +++++-----
...DefaultShadowAlgorithmStatementUpdaterTest.java | 17 ++++-----
.../CreateShadowRuleStatementUpdaterTest.java | 19 ++++------
20 files changed, 118 insertions(+), 197 deletions(-)
diff --git a/features/shadow/core/pom.xml b/features/shadow/core/pom.xml
index 677c36498a2..4209d708059 100644
--- a/features/shadow/core/pom.xml
+++ b/features/shadow/core/pom.xml
@@ -56,5 +56,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
index f033e5cb149..38532684ce3 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
@@ -21,6 +21,8 @@ import
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.shadow.exception.data.UnsupportedShadowColumnTypeException;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Properties;
@@ -32,22 +34,16 @@ public final class ColumnRegexMatchShadowAlgorithmTest
extends AbstractColumnSha
@Test
public void assertIsShadow() {
- ColumnRegexMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("REGEX_MATCH", createProperties()),
ShadowAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("column",
SHADOW_COLUMN), new Property("operation", "insert"), new Property("regex",
"[1]"));
+ ColumnRegexMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("REGEX_MATCH", props), ShadowAlgorithm.class);
createPreciseColumnShadowValuesFalseCase().forEach(each ->
assertFalse(shadowAlgorithm.isShadow(each)));
createPreciseColumnShadowValuesTrueCase().forEach(each ->
assertTrue(shadowAlgorithm.isShadow(each)));
}
@Test(expected = UnsupportedShadowColumnTypeException.class)
public void assertExceptionCase() {
- ColumnRegexMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("REGEX_MATCH", createProperties()),
ShadowAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("column",
SHADOW_COLUMN), new Property("operation", "insert"), new Property("regex",
"[1]"));
+ ColumnRegexMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("REGEX_MATCH", props), ShadowAlgorithm.class);
createPreciseColumnShadowValuesExceptionCase().forEach(each ->
assertFalse(shadowAlgorithm.isShadow(each)));
}
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("column", SHADOW_COLUMN);
- result.setProperty("operation", "insert");
- result.setProperty("regex", "[1]");
- return result;
- }
}
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
index 0f59baffee0..9f86009200e 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
@@ -21,6 +21,8 @@ import
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.shadow.exception.data.UnsupportedShadowColumnTypeException;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Properties;
@@ -32,22 +34,16 @@ public final class ColumnValueMatchShadowAlgorithmTest
extends AbstractColumnSha
@Test
public void assertIsShadow() {
- ColumnValueMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("VALUE_MATCH", createProperties()),
ShadowAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("column",
SHADOW_COLUMN), new Property("operation", "insert"), new Property("value",
"1"));
+ ColumnValueMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("VALUE_MATCH", props), ShadowAlgorithm.class);
createPreciseColumnShadowValuesTrueCase().forEach(each ->
assertTrue(shadowAlgorithm.isShadow(each)));
createPreciseColumnShadowValuesFalseCase().forEach(each ->
assertFalse(shadowAlgorithm.isShadow(each)));
}
@Test(expected = UnsupportedShadowColumnTypeException.class)
public void assertExceptionCase() {
- ColumnValueMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("VALUE_MATCH", createProperties()),
ShadowAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("column",
SHADOW_COLUMN), new Property("operation", "insert"), new Property("value",
"1"));
+ ColumnValueMatchedShadowAlgorithm shadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("VALUE_MATCH", props), ShadowAlgorithm.class);
createPreciseColumnShadowValuesExceptionCase().forEach(each ->
assertFalse(shadowAlgorithm.isShadow(each)));
}
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("column", SHADOW_COLUMN);
- result.setProperty("operation", "insert");
- result.setProperty("value", "1");
- return result;
- }
}
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java
index d5a64769a37..fe7a0270267 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithmTest.java
@@ -22,11 +22,12 @@ import
org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.api.shadow.hint.PreciseHintShadowValue;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
-import java.util.Properties;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -37,13 +38,8 @@ public final class SimpleHintShadowAlgorithmTest {
@Before
public void init() {
- shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("SIMPLE_HINT", createProperties()),
ShadowAlgorithm.class);
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("shadow", Boolean.TRUE.toString());
- return result;
+ shadowAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SIMPLE_HINT",
PropertiesBuilder.build(new Property("shadow", Boolean.TRUE.toString()))),
ShadowAlgorithm.class);
}
@Test
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
index 99d037b67de..39bd627ee85 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
@@ -21,15 +21,16 @@ import
org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import javax.sql.DataSource;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
-import java.util.Properties;
-import java.util.Collections;
import static org.mockito.Mockito.mock;
@@ -62,15 +63,8 @@ public final class ShadowRuleConfigurationCheckerTest {
}
private AlgorithmConfiguration createAlgorithmConfiguration() {
- return new AlgorithmConfiguration("user-id-insert-match-algorithm",
createProperties());
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("column", "shadow");
- result.setProperty("operation", "insert");
- result.setProperty("regex", "[1]");
- return result;
+ return new AlgorithmConfiguration("user-id-insert-match-algorithm",
+ PropertiesBuilder.build(new Property("column", "shadow"), new
Property("operation", "insert"), new Property("regex", "[1]")));
}
private Map<String, ShadowTableConfiguration> createTables() {
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java
index 5d8fcd1d4fb..826d149b67c 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/ColumnShadowAlgorithmDeterminerTest.java
@@ -23,6 +23,8 @@ import
org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;
import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Collections;
@@ -34,16 +36,9 @@ public final class ColumnShadowAlgorithmDeterminerTest {
@Test
public void assertIsShadow() {
+ Properties props = PropertiesBuilder.build(new Property("column",
"user_id"), new Property("operation", "insert"), new Property("regex", "[1]"));
assertTrue(ColumnShadowAlgorithmDeterminer.isShadow(
- ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("REGEX_MATCH", createProperties()),
ShadowAlgorithm.class), createShadowDetermineCondition()));
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("column", "user_id");
- result.setProperty("operation", "insert");
- result.setProperty("regex", "[1]");
- return result;
+ ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("REGEX_MATCH", props), ShadowAlgorithm.class),
createShadowDetermineCondition()));
}
private ShadowDetermineCondition createShadowDetermineCondition() {
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java
index c9ed5b31532..9ff09ad8b7c 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/determiner/HintShadowAlgorithmDeterminerTest.java
@@ -27,12 +27,13 @@ import
org.apache.shardingsphere.shadow.api.shadow.hint.HintShadowAlgorithm;
import org.apache.shardingsphere.shadow.condition.ShadowDetermineCondition;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
-import java.util.Properties;
import static org.junit.Assert.assertTrue;
@@ -41,21 +42,16 @@ public final class HintShadowAlgorithmDeterminerTest {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertIsShadow() {
- HintShadowAlgorithm hintShadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(new
AlgorithmConfiguration("SIMPLE_HINT", createProperties()),
ShadowAlgorithm.class);
+ HintShadowAlgorithm hintShadowAlgorithm =
ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SIMPLE_HINT",
PropertiesBuilder.build(new Property("foo", "foo_value"))),
ShadowAlgorithm.class);
assertTrue(HintShadowAlgorithmDeterminer.isShadow(hintShadowAlgorithm,
createShadowDetermineCondition(), new
ShadowRule(createShadowRuleConfiguration())));
}
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("foo", "foo_value");
- return result;
- }
-
private ShadowRuleConfiguration createShadowRuleConfiguration() {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.setDataSources(createDataSources());
result.setTables(Collections.singletonMap("t_order", new
ShadowTableConfiguration(Collections.singletonList("shadow-data-source-0"),
Collections.singleton("simple-hint-algorithm"))));
-
result.setShadowAlgorithms(Collections.singletonMap("simple-hint-algorithm",
new AlgorithmConfiguration("SIMPLE_HINT", createProperties())));
+
result.setShadowAlgorithms(Collections.singletonMap("simple-hint-algorithm",
new AlgorithmConfiguration("SIMPLE_HINT", PropertiesBuilder.build(new
Property("foo", "foo_value")))));
return result;
}
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
index 1ae8c9dcad9..63f16b5fb65 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowDeleteStatementRoutingEngineTest.java
@@ -35,6 +35,8 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sim
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLDeleteStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +45,6 @@ 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;
@@ -100,15 +101,7 @@ public final class ShadowDeleteStatementRoutingEngineTest {
}
private AlgorithmConfiguration createShadowAlgorithm() {
- return new AlgorithmConfiguration("REGEX_MATCH", createProperties());
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("column", "user_id");
- result.setProperty("operation", "delete");
- result.setProperty("regex", "[1]");
- return result;
+ return new AlgorithmConfiguration("REGEX_MATCH",
PropertiesBuilder.build(new Property("column", "user_id"), new
Property("operation", "delete"), new Property("regex", "[1]")));
}
@Test
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
index 1f734975af1..bbb1266d026 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowInsertStatementRoutingEngineTest.java
@@ -34,6 +34,8 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sim
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +45,6 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -96,15 +97,7 @@ public final class ShadowInsertStatementRoutingEngineTest {
}
private AlgorithmConfiguration createShadowAlgorithm() {
- return new AlgorithmConfiguration("REGEX_MATCH", createProperties());
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("column", "user_id");
- result.setProperty("operation", "insert");
- result.setProperty("regex", "[1]");
- return result;
+ return new AlgorithmConfiguration("REGEX_MATCH",
PropertiesBuilder.build(new Property("column", "user_id"), new
Property("operation", "insert"), new Property("regex", "[1]")));
}
@Test
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
index 9e91c99439b..dd6b37efa74 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/dml/ShadowSelectStatementRoutingEngineTest.java
@@ -35,6 +35,8 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sim
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -42,7 +44,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -95,15 +96,7 @@ public final class ShadowSelectStatementRoutingEngineTest {
}
private AlgorithmConfiguration createShadowAlgorithm() {
- return new AlgorithmConfiguration("REGEX_MATCH", createProperties());
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("column", "user_id");
- result.setProperty("operation", "select");
- result.setProperty("regex", "[1]");
- return result;
+ return new AlgorithmConfiguration("REGEX_MATCH",
PropertiesBuilder.build(new Property("column", "user_id"), new
Property("operation", "select"), new Property("regex", "[1]")));
}
@Test
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/impl/ShadowNonDMLStatementRoutingEngineTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/impl/ShadowNonDMLStatementRoutingEngineTest.java
index cb47c6c04fc..f5b27794b8f 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/impl/ShadowNonDMLStatementRoutingEngineTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/engine/impl/ShadowNonDMLStatementRoutingEngineTest.java
@@ -29,13 +29,14 @@ import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguratio
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateTableStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -89,12 +90,6 @@ public final class ShadowNonDMLStatementRoutingEngineTest {
}
private Map<String, AlgorithmConfiguration> createShadowAlgorithms() {
- return Collections.singletonMap("simple-hint-algorithm", new
AlgorithmConfiguration("SIMPLE_HINT", createProperties()));
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("shadow", Boolean.TRUE.toString());
- return result;
+ return Collections.singletonMap("simple-hint-algorithm", new
AlgorithmConfiguration("SIMPLE_HINT", PropertiesBuilder.build(new
Property("shadow", Boolean.TRUE.toString()))));
}
}
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
index a55a4c7f1fc..3759eacc8c9 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
@@ -21,6 +21,8 @@ import
org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -31,7 +33,6 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -55,24 +56,13 @@ public final class ShadowRuleTest {
private Map<String, AlgorithmConfiguration> createShadowAlgorithms() {
Map<String, AlgorithmConfiguration> result = new LinkedHashMap<>();
- result.put("simple-hint-algorithm", new
AlgorithmConfiguration("SIMPLE_HINT", createHintProperties()));
- result.put("user-id-insert-regex-algorithm", new
AlgorithmConfiguration("REGEX_MATCH", createColumnProperties("user_id",
"insert")));
- result.put("user-id-update-regex-algorithm", new
AlgorithmConfiguration("REGEX_MATCH", createColumnProperties("user_id",
"update")));
- result.put("order-id-insert-regex-algorithm", new
AlgorithmConfiguration("REGEX_MATCH", createColumnProperties("order_id",
"insert")));
- return result;
- }
-
- private Properties createHintProperties() {
- Properties result = new Properties();
- result.setProperty("shadow", Boolean.TRUE.toString());
- return result;
- }
-
- private Properties createColumnProperties(final String column, final
String operation) {
- Properties result = new Properties();
- result.setProperty("column", column);
- result.setProperty("operation", operation);
- result.setProperty("regex", "[1]");
+ result.put("simple-hint-algorithm", new
AlgorithmConfiguration("SIMPLE_HINT", PropertiesBuilder.build(new
Property("shadow", Boolean.TRUE.toString()))));
+ result.put("user-id-insert-regex-algorithm", new
AlgorithmConfiguration("REGEX_MATCH",
+ PropertiesBuilder.build(new Property("column", "user_id"), new
Property("operation", "insert"), new Property("regex", "[1]"))));
+ result.put("user-id-update-regex-algorithm", new
AlgorithmConfiguration("REGEX_MATCH",
+ PropertiesBuilder.build(new Property("column", "user_id"), new
Property("operation", "update"), new Property("regex", "[1]"))));
+ result.put("order-id-insert-regex-algorithm", new
AlgorithmConfiguration("REGEX_MATCH",
+ PropertiesBuilder.build(new Property("column", "order_id"),
new Property("operation", "insert"), new Property("regex", "[1]"))));
return result;
}
diff --git a/features/shadow/distsql/handler/pom.xml
b/features/shadow/distsql/handler/pom.xml
index 480c7cae5a2..f134803bbd3 100644
--- a/features/shadow/distsql/handler/pom.xml
+++ b/features/shadow/distsql/handler/pom.xml
@@ -48,5 +48,12 @@
<artifactId>shardingsphere-shadow-distsql-parser</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/converter/ShadowRuleStatementConverterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/converter/ShadowRuleStatementConverterTest.java
index bc6a4bf7ed8..f458a455413 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/converter/ShadowRuleStatementConverterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/converter/ShadowRuleStatementConverterTest.java
@@ -23,10 +23,11 @@ import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceCo
import
org.apache.shardingsphere.shadow.distsql.handler.converter.ShadowRuleStatementConverter;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowRuleSegment;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Collections;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -36,22 +37,16 @@ public final class ShadowRuleStatementConverterTest {
@Test
public void assertConvert() {
ShadowRuleConfiguration config =
ShadowRuleStatementConverter.convert(Collections.singleton(createTableRuleSegment()));
- ShadowDataSourceConfiguration shadowDataSourceConfiguration =
config.getDataSources().iterator().next();
-
assertThat(shadowDataSourceConfiguration.getProductionDataSourceName(),
is("source"));
- assertThat(shadowDataSourceConfiguration.getShadowDataSourceName(),
is("shadow"));
+ ShadowDataSourceConfiguration shadowDataSourceConfig =
config.getDataSources().iterator().next();
+ assertThat(shadowDataSourceConfig.getProductionDataSourceName(),
is("source"));
+ assertThat(shadowDataSourceConfig.getShadowDataSourceName(),
is("shadow"));
assertThat(config.getTables().size(), is(1));
assertThat(config.getShadowAlgorithms().size(), is(1));
assertThat(config.getShadowAlgorithms().get("algorithmsName").getProps().getProperty("foo"),
is("bar"));
}
private ShadowRuleSegment createTableRuleSegment() {
- return new ShadowRuleSegment("ruleName", "source", "shadow",
- Collections.singletonMap("t_order", Collections.singleton(new
ShadowAlgorithmSegment("algorithmsName", new AlgorithmSegment("type",
createProperties())))));
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("foo", "bar");
- return result;
+ return new ShadowRuleSegment("ruleName", "source", "shadow",
Collections.singletonMap("t_order",
+ Collections.singleton(new
ShadowAlgorithmSegment("algorithmsName", new AlgorithmSegment("type",
PropertiesBuilder.build(new Property("foo", "bar")))))));
}
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmResultSetTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmResultSetTest.java
index c25d59e006c..c8cf5239a08 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmResultSetTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmResultSetTest.java
@@ -17,22 +17,23 @@
package org.apache.shardingsphere.shadow.distsql.query;
+import
org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import
org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import
org.apache.shardingsphere.shadow.distsql.handler.query.ShadowAlgorithmResultSet;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -64,10 +65,8 @@ public final class ShadowAlgorithmResultSetTest {
private RuleConfiguration createRuleConfiguration() {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
- Properties props = new Properties();
- props.setProperty("foo", "bar");
result.getTables().put("t_order", new
ShadowTableConfiguration(Collections.emptyList(),
Collections.singleton("shadowAlgorithmName")));
- result.getShadowAlgorithms().put("shadowAlgorithmName", new
AlgorithmConfiguration("simple_hint", props));
+ result.getShadowAlgorithms().put("shadowAlgorithmName", new
AlgorithmConfiguration("simple_hint", PropertiesBuilder.build(new
Property("foo", "bar"))));
return result;
}
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleResultSetTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleResultSetTest.java
index 332fd7a365b..56ff96ef269 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleResultSetTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleResultSetTest.java
@@ -17,15 +17,17 @@
package org.apache.shardingsphere.shadow.distsql.query;
+import
org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
-import
org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import
org.apache.shardingsphere.shadow.distsql.handler.query.ShadowTableRuleResultSet;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.ArrayList;
@@ -33,7 +35,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -64,13 +65,7 @@ public final class ShadowTableRuleResultSetTest {
private RuleConfiguration createRuleConfiguration() {
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
result.getTables().put("t_order", new
ShadowTableConfiguration(Collections.emptyList(),
Arrays.asList("shadowAlgorithmName_1", "shadowAlgorithmName_2")));
- result.getShadowAlgorithms().put("shadowAlgorithmName", new
AlgorithmConfiguration("simple_hint", createProperties()));
- return result;
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("foo", "bar");
+ result.getShadowAlgorithms().put("shadowAlgorithmName", new
AlgorithmConfiguration("simple_hint", PropertiesBuilder.build(new
Property("foo", "bar"))));
return result;
}
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
index e4350e54a9b..34cbced4000 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterDefaultShadowAlgorithmStatementUpdaterTest.java
@@ -17,16 +17,18 @@
package org.apache.shardingsphere.shadow.distsql.update;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.MissingRequiredAlgorithmException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.distsql.handler.update.AlterDefaultShadowAlgorithmStatementUpdater;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.AlterDefaultShadowAlgorithmStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -51,47 +53,40 @@ public final class
AlterDefaultShadowAlgorithmStatementUpdaterTest {
@Test(expected = MissingRequiredRuleException.class)
public void assertExecuteAlgorithmWithoutConfiguration() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
- AlterDefaultShadowAlgorithmStatement sqlStatement =
createSQLStatement(new ShadowAlgorithmSegment("simpleHintAlgorithm", new
AlgorithmSegment("SIMPLE_HINT", prop)));
+ AlterDefaultShadowAlgorithmStatement sqlStatement = new
AlterDefaultShadowAlgorithmStatement(
+ new ShadowAlgorithmSegment("simpleHintAlgorithm", new
AlgorithmSegment("SIMPLE_HINT", PropertiesBuilder.build(new Property("type",
"value")))));
updater.checkSQLStatement(database, sqlStatement, null);
}
@Test(expected = MissingRequiredAlgorithmException.class)
public void assertExecuteAlgorithmNotInMetaData() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
-
when(currentConfig.getShadowAlgorithms()).thenReturn(Collections.singletonMap("simpleHintAlgorithm",
new AlgorithmConfiguration("type", prop)));
- AlterDefaultShadowAlgorithmStatement sqlStatement =
createSQLStatement(new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("SIMPLE_HINT", prop)));
+ Properties props = PropertiesBuilder.build(new Property("type",
"value"));
+
when(currentConfig.getShadowAlgorithms()).thenReturn(Collections.singletonMap("simpleHintAlgorithm",
new AlgorithmConfiguration("type", props)));
+ AlterDefaultShadowAlgorithmStatement sqlStatement = new
AlterDefaultShadowAlgorithmStatement(
+ new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("SIMPLE_HINT", props)));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
}
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertExecuteInvalidAlgorithmType() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
- AlterDefaultShadowAlgorithmStatement sqlStatement =
createSQLStatement(new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("NOT_EXIST_SIMPLE_HINT", prop)));
+ AlterDefaultShadowAlgorithmStatement sqlStatement = new
AlterDefaultShadowAlgorithmStatement(
+ new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("NOT_EXIST_SIMPLE_HINT", PropertiesBuilder.build(new
Property("type", "value")))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
}
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertExecuteIncompletenessAlgorithm() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
- AlterDefaultShadowAlgorithmStatement sqlStatement =
createSQLStatement(new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("", prop)));
+ AlterDefaultShadowAlgorithmStatement sqlStatement = new
AlterDefaultShadowAlgorithmStatement(
+ new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("", PropertiesBuilder.build(new Property("type", "value")))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
}
@Test
public void assertExecuteSuccess() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
-
when(currentConfig.getShadowAlgorithms()).thenReturn(Collections.singletonMap("default_shadow_algorithm",
new AlgorithmConfiguration("type", prop)));
- AlterDefaultShadowAlgorithmStatement sqlStatement =
createSQLStatement(new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("SIMPLE_HINT", prop)));
+ Properties props = PropertiesBuilder.build(new Property("type",
"value"));
+
when(currentConfig.getShadowAlgorithms()).thenReturn(Collections.singletonMap("default_shadow_algorithm",
new AlgorithmConfiguration("type", props)));
+ AlterDefaultShadowAlgorithmStatement sqlStatement = new
AlterDefaultShadowAlgorithmStatement(
+ new ShadowAlgorithmSegment("default_shadow_algorithm", new
AlgorithmSegment("SIMPLE_HINT", props)));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
}
-
- private AlterDefaultShadowAlgorithmStatement createSQLStatement(final
ShadowAlgorithmSegment shadowAlgorithmSegment) {
- return new
AlterDefaultShadowAlgorithmStatement(shadowAlgorithmSegment);
- }
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java
index 8da4ab304bb..27376bb4b8a 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/AlterShadowRuleStatementUpdaterTest.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.shadow.distsql.update;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.AlgorithmInUsedException;
-import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
+import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
@@ -30,6 +30,8 @@ import
org.apache.shardingsphere.shadow.distsql.handler.update.AlterShadowRuleSt
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowRuleSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowRuleStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -98,9 +100,7 @@ public final class AlterShadowRuleStatementUpdaterTest {
@Test(expected = AlgorithmInUsedException.class)
public void assertExecuteDuplicateAlgorithm() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
- ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name", prop));
+ ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
PropertiesBuilder.build(new Property("type", "value"))));
AlterShadowRuleStatement sqlStatement = createSQLStatement(new
ShadowRuleSegment("initRuleName1", "ds", null,
Collections.singletonMap("t_order", Collections.singleton(segment))),
new ShadowRuleSegment("initRuleName2", "ds1", null,
Collections.singletonMap("t_order_1", Collections.singletonList(segment))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
@@ -108,9 +108,7 @@ public final class AlterShadowRuleStatementUpdaterTest {
@Test(expected = AlgorithmInUsedException.class)
public void assertExecuteDuplicateAlgorithmWithoutConfiguration() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
- ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name", prop));
+ ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
PropertiesBuilder.build(new Property("type", "value"))));
AlterShadowRuleStatement sqlStatement = createSQLStatement(new
ShadowRuleSegment("initRuleName1", "ds", null,
Collections.singletonMap("t_order", Collections.singleton(segment))),
new ShadowRuleSegment("initRuleName2", "ds1", null,
Collections.singletonMap("t_order_1", Collections.singletonList(segment))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
@@ -118,10 +116,9 @@ public final class AlterShadowRuleStatementUpdaterTest {
@Test
public void assertExecuteSuccess() {
- Properties prop = new Properties();
- prop.setProperty("type", "value");
- ShadowAlgorithmSegment segment1 = new
ShadowAlgorithmSegment("algorithmName1", new AlgorithmSegment("SIMPLE_HINT",
prop));
- ShadowAlgorithmSegment segment2 = new
ShadowAlgorithmSegment("algorithmName2", new AlgorithmSegment("SIMPLE_HINT",
prop));
+ Properties props = PropertiesBuilder.build(new Property("type",
"value"));
+ ShadowAlgorithmSegment segment1 = new
ShadowAlgorithmSegment("algorithmName1", new AlgorithmSegment("SIMPLE_HINT",
props));
+ ShadowAlgorithmSegment segment2 = new
ShadowAlgorithmSegment("algorithmName2", new AlgorithmSegment("SIMPLE_HINT",
props));
AlterShadowRuleStatement sqlStatement = createSQLStatement(new
ShadowRuleSegment("initRuleName1", "ds", null,
Collections.singletonMap("t_order", Collections.singleton(segment1))),
new ShadowRuleSegment("initRuleName2", "ds1", null,
Collections.singletonMap("t_order_1", Collections.singletonList(segment2))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
index 090c048aee4..03177c2b2b9 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateDefaultShadowAlgorithmStatementUpdaterTest.java
@@ -24,14 +24,14 @@ import
org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.distsql.handler.update.CreateDefaultShadowAlgorithmStatementUpdater;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.CreateDefaultShadowAlgorithmStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.util.Properties;
-
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -49,27 +49,22 @@ public final class
CreateDefaultShadowAlgorithmStatementUpdaterTest {
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertExecuteWithInvalidAlgorithm() {
CreateDefaultShadowAlgorithmStatement statement =
mock(CreateDefaultShadowAlgorithmStatement.class);
- when(statement.getShadowAlgorithmSegment()).thenReturn(new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
createProperties())));
+ when(statement.getShadowAlgorithmSegment()).thenReturn(new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
PropertiesBuilder.build(new Property("type", "value")))));
updater.checkSQLStatement(database, statement, currentConfig);
}
@Test
public void assertExecuteSuccess() {
CreateDefaultShadowAlgorithmStatement statement =
mock(CreateDefaultShadowAlgorithmStatement.class);
- when(statement.getShadowAlgorithmSegment()).thenReturn(new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("SIMPLE_HINT",
createProperties())));
+ when(statement.getShadowAlgorithmSegment()).thenReturn(
+ new ShadowAlgorithmSegment("algorithmName", new
AlgorithmSegment("SIMPLE_HINT", PropertiesBuilder.build(new Property("type",
"value")))));
updater.checkSQLStatement(database, statement, currentConfig);
}
@Test
public void assertExecuteWithIfNotExists() {
- ShadowAlgorithmSegment shadowAlgorithmSegment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("SIMPLE_HINT",
createProperties()));
+ ShadowAlgorithmSegment shadowAlgorithmSegment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("SIMPLE_HINT",
PropertiesBuilder.build(new Property("type", "value"))));
CreateDefaultShadowAlgorithmStatement statement = new
CreateDefaultShadowAlgorithmStatement(true, shadowAlgorithmSegment);
updater.checkSQLStatement(database, statement, currentConfig);
}
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("type", "value");
- return result;
- }
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
index d163662381c..bf5248ffb5c 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleStatementUpdaterTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.shadow.distsql.update;
import
org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException;
-import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
+import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
@@ -29,6 +29,8 @@ import
org.apache.shardingsphere.shadow.distsql.handler.update.CreateShadowRuleS
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowRuleSegment;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.CreateShadowRuleStatement;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,7 +40,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Properties;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@@ -86,7 +87,7 @@ public final class CreateShadowRuleStatementUpdaterTest {
@Test(expected = DuplicateRuleException.class)
public void assertExecuteDuplicateAlgorithm() {
- ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
createProperties()));
+ ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
PropertiesBuilder.build(new Property("type", "value"))));
CreateShadowRuleStatement sqlStatement = createSQLStatement(false, new
ShadowRuleSegment("ruleName", "ds", null, Collections.singletonMap("t_order",
Collections.singleton(segment))),
new ShadowRuleSegment("ruleName", "ds1", null,
Collections.singletonMap("t_order_1", Collections.singletonList(segment))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
@@ -94,7 +95,7 @@ public final class CreateShadowRuleStatementUpdaterTest {
@Test(expected = DuplicateRuleException.class)
public void assertExecuteDuplicateAlgorithmWithoutConfiguration() {
- ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
createProperties()));
+ ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("name",
PropertiesBuilder.build(new Property("type", "value"))));
CreateShadowRuleStatement sqlStatement = createSQLStatement(false, new
ShadowRuleSegment("ruleName", "ds", null, Collections.singletonMap("t_order",
Collections.singleton(segment))),
new ShadowRuleSegment("ruleName1", "ds1", null,
Collections.singletonMap("t_order_1", Collections.singletonList(segment))));
updater.checkSQLStatement(database, sqlStatement, null);
@@ -102,14 +103,14 @@ public final class CreateShadowRuleStatementUpdaterTest {
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertInvalidAlgorithmConfiguration() {
- ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("type",
createProperties()));
+ ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("type",
PropertiesBuilder.build(new Property("type", "value"))));
CreateShadowRuleStatement sqlStatement = createSQLStatement(false, new
ShadowRuleSegment("ruleName", "ds", null, Collections.singletonMap("t_order",
Collections.singleton(segment))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
}
@Test
public void assertExecuteWithIfNotExists() {
- ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("SIMPLE_HINT",
createProperties()));
+ ShadowAlgorithmSegment segment = new
ShadowAlgorithmSegment("algorithmName", new AlgorithmSegment("SIMPLE_HINT",
PropertiesBuilder.build(new Property("type", "value"))));
CreateShadowRuleStatement sqlStatement = createSQLStatement(true, new
ShadowRuleSegment("initRuleName", "ds", null,
Collections.singletonMap("t_order", Collections.singleton(segment))));
updater.checkSQLStatement(database, sqlStatement, currentConfig);
}
@@ -117,10 +118,4 @@ public final class CreateShadowRuleStatementUpdaterTest {
private CreateShadowRuleStatement createSQLStatement(final boolean
ifNotExists, final ShadowRuleSegment... ruleSegments) {
return new CreateShadowRuleStatement(ifNotExists,
Arrays.asList(ruleSegments));
}
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("type", "value");
- return result;
- }
}