You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/01/03 00:41:40 UTC
[shardingsphere] branch master updated: Use PropertiesBuilder in sharding module (#23272)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 4fa9e07e10a Use PropertiesBuilder in sharding module (#23272)
4fa9e07e10a is described below
commit 4fa9e07e10a8d6b7eeb2205804cd13e8808c2a61
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Jan 3 08:41:33 2023 +0800
Use PropertiesBuilder in sharding module (#23272)
---
.../ShadowRuleStatementConverterTest.java | 2 +-
features/sharding/core/pom.xml | 6 +
.../keygen/SnowflakeKeyGenerateAlgorithmTest.java | 32 ++--
.../ClassBasedShardingAlgorithmTest.java | 52 ++----
.../ComplexInlineShardingAlgorithmTest.java | 48 ++----
.../AutoIntervalShardingAlgorithmTest.java | 41 ++---
.../datetime/IntervalShardingAlgorithmTest.java | 178 +++++++++------------
.../hint/HintInlineShardingAlgorithmTest.java | 11 +-
.../inline/InlineShardingAlgorithmTest.java | 34 ++--
.../sharding/mod/HashModShardingAlgorithmTest.java | 18 +--
.../sharding/mod/ModShardingAlgorithmTest.java | 28 ++--
.../BoundaryBasedRangeShardingAlgorithmTest.java | 12 +-
.../VolumeBasedRangeShardingAlgorithmTest.java | 18 +--
.../engine/fixture/AbstractRoutingEngineTest.java | 91 ++++-------
.../dml/ShardingInsertStatementValidatorTest.java | 13 +-
.../dml/ShardingUpdateStatementValidatorTest.java | 12 +-
.../sharding/rule/ShardingRuleTest.java | 37 ++---
.../sharding/rule/TableRuleTest.java | 15 +-
features/sharding/distsql/handler/pom.xml | 6 +
.../checker/ShardingRuleStatementCheckerTest.java | 34 ++--
.../ShardingRuleStatementConverterTest.java | 24 +--
.../query/ShardingAlgorithmResultSetTest.java | 9 +-
...ardingDefaultShardingStrategyResultSetTest.java | 11 +-
.../query/ShardingTableRuleResultSetTest.java | 8 +-
...ardingTableRulesUsedAlgorithmResultSetTest.java | 12 +-
...ShardingTableRulesUsedAuditorResultSetTest.java | 12 +-
...ingTableRulesUsedKeyGeneratorResultSetTest.java | 12 +-
.../UnusedShardingAlgorithmsResultSetTest.java | 11 +-
...efaultShardingStrategyStatementUpdaterTest.java | 16 +-
...AlterShardingTableRuleStatementUpdaterTest.java | 14 +-
...efaultShardingStrategyStatementUpdaterTest.java | 14 +-
...reateShardingTableRuleStatementUpdaterTest.java | 18 +--
features/sharding/plugin/cache/pom.xml | 6 +
.../checker/ShardingRouteCacheableCheckerTest.java | 11 +-
features/sharding/plugin/cosid/pom.xml | 7 +
.../keygen/CosIdKeyGenerateAlgorithmTest.java | 21 +--
.../CosIdSnowflakeKeyGenerateAlgorithmTest.java | 5 +-
...osIdSnowflakeIntervalShardingAlgorithmTest.java | 21 +--
.../IntervalShardingAlgorithmDataFixture.java | 28 ++--
.../mod/CosIdModShardingAlgorithmTest.java | 12 +-
40 files changed, 376 insertions(+), 584 deletions(-)
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 f458a455413..f5785945df4 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
@@ -46,7 +46,7 @@ public final class ShadowRuleStatementConverterTest {
}
private ShadowRuleSegment createTableRuleSegment() {
- return new ShadowRuleSegment("ruleName", "source", "shadow", Collections.singletonMap("t_order",
+ 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/sharding/core/pom.xml b/features/sharding/core/pom.xml
index 73c485560e8..1bc2462064c 100644
--- a/features/sharding/core/pom.xml
+++ b/features/sharding/core/pom.xml
@@ -86,6 +86,12 @@
<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>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-single-core</artifactId>
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
index 23f7be55c58..cf38b40355c 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
@@ -31,6 +31,8 @@ import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.sharding.algorithm.keygen.fixture.FixedTimeService;
import org.apache.shardingsphere.sharding.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import org.mockito.internal.configuration.plugins.Plugins;
@@ -99,9 +101,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertLastDigitalOfGenerateKeySameMillisecond() {
SnowflakeKeyGenerateAlgorithm.setTimeService(new FixedTimeService(5));
- Properties props = new Properties();
- props.setProperty("max-vibration-offset", "3");
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "3"))), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -114,10 +115,9 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertLastDigitalOfGenerateKeyDifferentMillisecond() throws InterruptedException {
- Properties props = new Properties();
SnowflakeKeyGenerateAlgorithm.setTimeService(new TimeService());
- props.setProperty("max-vibration-offset", String.valueOf(3));
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "3"))), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -158,9 +158,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
public void assertGenerateKeyWithClockCallBackBeyondTolerateTime() {
TimeService timeService = new FixedTimeService(1);
SnowflakeKeyGenerateAlgorithm.setTimeService(timeService);
- Properties props = new Properties();
- props.setProperty("max-tolerate-time-difference-milliseconds", String.valueOf(0));
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-tolerate-time-difference-milliseconds", "0"))), KeyGenerateAlgorithm.class);
if (algorithm instanceof InstanceContextAware) {
((InstanceContextAware) algorithm).setInstanceContext(INSTANCE);
}
@@ -211,9 +210,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertSetMaxVibrationOffsetFailureWhenNegative() {
- Properties props = new Properties();
- props.setProperty("max-vibration-offset", String.valueOf(-1));
- ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class)).generateKey();
+ ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "-1"))), KeyGenerateAlgorithm.class)).generateKey();
}
@Test(expected = IllegalArgumentException.class)
@@ -227,16 +225,14 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
@Test(expected = IllegalArgumentException.class)
public void assertSetMaxVibrationOffsetFailureWhenOutOfRange() {
- Properties props = new Properties();
- props.setProperty("max-vibration-offset", String.valueOf(4096));
- ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class)).generateKey();
+ ((KeyGenerateAlgorithm) ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-vibration-offset", "4096"))), KeyGenerateAlgorithm.class)).generateKey();
}
@Test
public void assertSetMaxTolerateTimeDifferenceMilliseconds() throws ReflectiveOperationException {
- Properties props = new Properties();
- props.setProperty("max-tolerate-time-difference-milliseconds", String.valueOf(1));
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SNOWFLAKE", props), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("max-tolerate-time-difference-milliseconds", "1"))), KeyGenerateAlgorithm.class);
assertThat(((Properties) Plugins.getMemberAccessor().get(algorithm.getClass().getDeclaredField("props"), algorithm)).getProperty("max-tolerate-time-difference-milliseconds"), is("1"));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java
index 34066363024..a89be3f557d 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmTest.java
@@ -30,6 +30,8 @@ import org.apache.shardingsphere.sharding.fixture.ClassBasedComplexKeysShardingA
import org.apache.shardingsphere.sharding.fixture.ClassBasedHintShardingAlgorithmFixture;
import org.apache.shardingsphere.sharding.fixture.ClassBasedStandardShardingAlgorithmFixture;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Arrays;
@@ -43,51 +45,46 @@ public final class ClassBasedShardingAlgorithmTest {
@Test(expected = NullPointerException.class)
public void assertInitWithNullStrategy() {
- Properties props = new Properties();
- props.setProperty("strategy", null);
+ Properties props = PropertiesBuilder.build(new Property("strategy", null));
ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = IllegalArgumentException.class)
public void assertInitWithWrongStrategy() {
- Properties props = new Properties();
- props.setProperty("strategy", "wrong");
+ Properties props = PropertiesBuilder.build(new Property("strategy", "wrong"));
ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = NullPointerException.class)
public void assertInitWithNullClass() {
- Properties props = new Properties();
- props.setProperty("strategy", "standard");
+ Properties props = PropertiesBuilder.build(new Property("strategy", "standard"));
ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = ClassNotFoundException.class)
public void assertInitWithUndefinedClass() {
- Properties props = new Properties();
- props.setProperty("strategy", "standard");
- props.setProperty("algorithmClassName", "org.apache.shardingsphere.sharding.UndefinedClass");
+ Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", "org.apache.shardingsphere.sharding.UndefinedClass"));
ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test(expected = ShardingAlgorithmClassImplementationException.class)
public void assertInitWithMismatchStrategy() {
- Properties props = new Properties();
- props.setProperty("strategy", "standard");
- props.setProperty("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName());
+ Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName()));
ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
}
@Test
public void assertPreciseDoSharding() {
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createStandardProperties()), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedStandardShardingAlgorithmFixture.class.getName()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
assertThat(algorithm.doSharding(availableTargetNames, new PreciseShardingValue<>("t_order", "order_id", new DataNodeInfo("t_order_", 1, '0'), 0)), is("t_order_0"));
}
@Test
public void assertRangeDoSharding() {
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createStandardProperties()), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("strategy", "standard"), new Property("algorithmClassName", ClassBasedStandardShardingAlgorithmFixture.class.getName()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
Collection<String> actual = algorithm.doSharding(availableTargetNames, new RangeShardingValue<>("t_order", "order_id", new DataNodeInfo("t_order_", 1, '0'), Range.closed(2, 15)));
assertThat(actual.size(), is(4));
@@ -95,7 +92,8 @@ public final class ClassBasedShardingAlgorithmTest {
@Test
public void assertComplexKeysDoSharding() {
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createComplexProperties()), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("strategy", "complex"), new Property("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
Collection<String> actual = algorithm.doSharding(availableTargetNames, new ComplexKeysShardingValue<>("t_order", null, null));
assertThat(actual.size(), is(4));
@@ -103,30 +101,10 @@ public final class ClassBasedShardingAlgorithmTest {
@Test
public void assertHintDoSharding() {
- ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", createHintProperties()), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property("strategy", "hint"), new Property("algorithmClassName", ClassBasedHintShardingAlgorithmFixture.class.getName()));
+ ClassBasedShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("CLASS_BASED", props), ShardingAlgorithm.class);
Collection<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
Collection<String> actual = algorithm.doSharding(availableTargetNames, new HintShardingValue<>("t_order", "order_id", null));
assertThat(actual.size(), is(4));
}
-
- private Properties createStandardProperties() {
- Properties result = new Properties();
- result.setProperty("strategy", "standard");
- result.setProperty("algorithmClassName", ClassBasedStandardShardingAlgorithmFixture.class.getName());
- return result;
- }
-
- private Properties createComplexProperties() {
- Properties result = new Properties();
- result.setProperty("strategy", "complex");
- result.setProperty("algorithmClassName", ClassBasedComplexKeysShardingAlgorithmFixture.class.getName());
- return result;
- }
-
- private Properties createHintProperties() {
- Properties result = new Properties();
- result.setProperty("strategy", "hint");
- result.setProperty("algorithmClassName", ClassBasedHintShardingAlgorithmFixture.class.getName());
- return result;
- }
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java
index e1f709d3e9d..6a8e3417205 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/complex/ComplexInlineShardingAlgorithmTest.java
@@ -22,6 +22,8 @@ import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.sharding.api.sharding.complex.ComplexKeysShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Arrays;
@@ -38,52 +40,36 @@ public final class ComplexInlineShardingAlgorithmTest {
@Test
public void assertDoSharding() {
+ Properties props = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${type % 2}_${order_id % 2}"), new Property("sharding-columns", "type,order_id"));
+ ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COMPLEX_INLINE", props), ShardingAlgorithm.class);
List<String> availableTargetNames = Arrays.asList("t_order_0_0", "t_order_0_1", "t_order_1_0", "t_order_1_1");
- Map<String, Collection<Comparable<?>>> sharingValueMap = new HashMap<>(2, 1);
- sharingValueMap.put("type", Collections.singletonList(2));
- sharingValueMap.put("order_id", Collections.singletonList(2));
- ComplexKeysShardingValue<Comparable<?>> shardingValue = new ComplexKeysShardingValue<>("t_order", sharingValueMap, Collections.emptyMap());
- ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("COMPLEX_INLINE", createDisallowRangeQueryProperties()), ShardingAlgorithm.class);
- Collection<String> actual = algorithm.doSharding(availableTargetNames, shardingValue);
+ Collection<String> actual = algorithm.doSharding(availableTargetNames, createComplexKeysShardingValue(Collections.singletonList(2)));
assertTrue(1 == actual.size() && actual.contains("t_order_0_0"));
}
@Test
public void assertDoShardingWithMultiValue() {
+ Properties props = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${type % 2}_${order_id % 2}"), new Property("sharding-columns", "type,order_id"));
+ ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COMPLEX_INLINE", props), ShardingAlgorithm.class);
List<String> availableTargetNames = Arrays.asList("t_order_0_0", "t_order_0_1", "t_order_1_0", "t_order_1_1");
- Map<String, Collection<Comparable<?>>> sharingValueMap = new HashMap<>(2, 1);
- sharingValueMap.put("type", Arrays.asList(1, 2));
- sharingValueMap.put("order_id", Arrays.asList(1, 2));
- ComplexKeysShardingValue<Comparable<?>> shardingValue = new ComplexKeysShardingValue<>("t_order", sharingValueMap, Collections.emptyMap());
- ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("COMPLEX_INLINE", createDisallowRangeQueryProperties()), ShardingAlgorithm.class);
- Collection<String> actual = algorithm.doSharding(availableTargetNames, shardingValue);
+ Collection<String> actual = algorithm.doSharding(availableTargetNames, createComplexKeysShardingValue(Arrays.asList(1, 2)));
assertTrue(actual.containsAll(availableTargetNames));
}
- private Properties createDisallowRangeQueryProperties() {
- Properties result = new Properties();
- result.setProperty("algorithm-expression", "t_order_${type % 2}_${order_id % 2}");
- result.setProperty("sharding-columns", "type,order_id");
- return result;
+ private ComplexKeysShardingValue<Comparable<?>> createComplexKeysShardingValue(final List<Comparable<?>> values) {
+ Map<String, Collection<Comparable<?>>> sharingValues = new HashMap<>(2, 1);
+ sharingValues.put("type", values);
+ sharingValues.put("order_id", values);
+ return new ComplexKeysShardingValue<>("t_order", sharingValues, Collections.emptyMap());
}
@Test
public void assertDoShardingWithRangeValue() {
+ Properties props = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${type % 2}_${order_id % 2}"),
+ new Property("sharding-columns", "type,order_id"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString()));
+ ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COMPLEX_INLINE", props), ShardingAlgorithm.class);
List<String> availableTargetNames = Arrays.asList("t_order_0_0", "t_order_0_1", "t_order_1_0", "t_order_1_1");
- ComplexKeysShardingValue<Comparable<?>> shardingValue = new ComplexKeysShardingValue<>("t_order", Collections.emptyMap(), Collections.singletonMap("type", Range.all()));
- ComplexInlineShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("COMPLEX_INLINE", createAllowRangeQueryProperties()), ShardingAlgorithm.class);
- Collection<String> actual = algorithm.doSharding(availableTargetNames, shardingValue);
+ Collection<String> actual = algorithm.doSharding(availableTargetNames, new ComplexKeysShardingValue<>("t_order", Collections.emptyMap(), Collections.singletonMap("type", Range.all())));
assertTrue(actual.containsAll(availableTargetNames));
}
-
- private Properties createAllowRangeQueryProperties() {
- Properties result = new Properties();
- result.setProperty("algorithm-expression", "t_order_${type % 2}_${order_id % 2}");
- result.setProperty("sharding-columns", "type,order_id");
- result.setProperty("allow-range-query-with-inline-sharding", Boolean.TRUE.toString());
- return result;
- }
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java
index 2366ed392d7..e5f2f3a1ed4 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithmTest.java
@@ -24,6 +24,8 @@ import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -45,15 +47,8 @@ public final class AutoIntervalShardingAlgorithmTest {
@Before
public void setup() {
- shardingAlgorithm = createAutoIntervalShardingAlgorithm(createNormalProperties());
- }
-
- private Properties createNormalProperties() {
- Properties result = new Properties();
- result.setProperty("datetime-lower", "2020-01-01 00:00:00");
- result.setProperty("datetime-upper", "2020-01-01 00:00:16");
- result.setProperty("sharding-seconds", "4");
- return result;
+ shardingAlgorithm = createAutoIntervalShardingAlgorithm(PropertiesBuilder.build(
+ new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2020-01-01 00:00:16"), new Property("sharding-seconds", "4")));
}
@Test
@@ -114,20 +109,16 @@ public final class AutoIntervalShardingAlgorithmTest {
@Test
public void assertGetAutoTablesAmount() {
- assertThat(createAutoIntervalShardingAlgorithm(createRangeWithDayProperties()).getAutoTablesAmount(), is(368));
- }
-
- private Properties createRangeWithDayProperties() {
- Properties result = new Properties();
- result.setProperty("datetime-lower", "2020-01-01 00:00:00");
- result.setProperty("datetime-upper", "2021-01-01 00:00:00");
- result.setProperty("sharding-seconds", "86400");
- return result;
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2021-01-01 00:00:00"), new Property("sharding-seconds", "86400"));
+ assertThat(createAutoIntervalShardingAlgorithm(props).getAutoTablesAmount(), is(368));
}
@Test
public void assertRangeDoShardingWithGreaterTenTables() {
- AutoIntervalShardingAlgorithm shardingAlgorithm = createAutoIntervalShardingAlgorithm(createRangeWithSecondProperties());
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2020-01-01 00:00:30"), new Property("sharding-seconds", "1"));
+ AutoIntervalShardingAlgorithm shardingAlgorithm = createAutoIntervalShardingAlgorithm(props);
List<String> availableTargetNames = new LinkedList<>();
for (int i = 0; i < 32; i++) {
availableTargetNames.add("t_order_" + i);
@@ -139,7 +130,9 @@ public final class AutoIntervalShardingAlgorithmTest {
@Test
public void assertRangeDoShardingInValueWithMilliseconds() {
- AutoIntervalShardingAlgorithm shardingAlgorithm = createAutoIntervalShardingAlgorithm(createRangeWithSecondProperties());
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-lower", "2020-01-01 00:00:00"), new Property("datetime-upper", "2020-01-01 00:00:30"), new Property("sharding-seconds", "1"));
+ AutoIntervalShardingAlgorithm shardingAlgorithm = createAutoIntervalShardingAlgorithm(props);
List<String> availableTargetNames = new LinkedList<>();
for (int i = 0; i < 32; i++) {
availableTargetNames.add("t_order_" + i);
@@ -158,14 +151,6 @@ public final class AutoIntervalShardingAlgorithmTest {
assertThat(actualWithThreeMilliseconds.size(), is(11));
}
- private Properties createRangeWithSecondProperties() {
- Properties result = new Properties();
- result.setProperty("datetime-lower", "2020-01-01 00:00:00");
- result.setProperty("datetime-upper", "2020-01-01 00:00:30");
- result.setProperty("sharding-seconds", "1");
- return result;
- }
-
private AutoIntervalShardingAlgorithm createAutoIntervalShardingAlgorithm(final Properties props) {
return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("AUTO_INTERVAL", props), ShardingAlgorithm.class);
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
index c933f287131..59f58458bf8 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
@@ -25,6 +25,8 @@ import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -105,7 +107,14 @@ public final class IntervalShardingAlgorithmTest {
}
private void initShardStrategyByQuarter() {
- shardingAlgorithmByQuarter = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createQuarterProperties()), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy-MM-dd HH:mm:ss"),
+ new Property("datetime-lower", "2016-01-01 00:00:00"),
+ new Property("datetime-upper", "2021-12-31 00:00:00"),
+ new Property("sharding-suffix-pattern", "yyyyQQ"),
+ new Property("datetime-interval-amount", "3"),
+ new Property("datetime-interval-unit", "Months"));
+ shardingAlgorithmByQuarter = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int i = 2016; i <= 2020; i++) {
for (int j = 1; j <= 4; j++) {
availableTablesForQuarterDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -113,19 +122,15 @@ public final class IntervalShardingAlgorithmTest {
}
}
- private Properties createQuarterProperties() {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "yyyy-MM-dd HH:mm:ss");
- result.setProperty("datetime-lower", "2016-01-01 00:00:00");
- result.setProperty("datetime-upper", "2021-12-31 00:00:00");
- result.setProperty("sharding-suffix-pattern", "yyyyQQ");
- result.setProperty("datetime-interval-amount", "3");
- result.setProperty("datetime-interval-unit", "Months");
- return result;
- }
-
private void initShardStrategyByMonth() {
- shardingAlgorithmByMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createMonthProperties()), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy-MM-dd HH:mm:ss"),
+ new Property("datetime-lower", "2016-01-01 00:00:00"),
+ new Property("datetime-upper", "2021-12-31 00:00:00"),
+ new Property("sharding-suffix-pattern", "yyyyMM"),
+ new Property("datetime-interval-amount", "1"),
+ new Property("datetime-interval-unit", "Months"));
+ shardingAlgorithmByMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int i = 2016; i <= 2020; i++) {
for (int j = 1; j <= 12; j++) {
availableTablesForMonthDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -133,20 +138,15 @@ public final class IntervalShardingAlgorithmTest {
}
}
- private Properties createMonthProperties() {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "yyyy-MM-dd HH:mm:ss");
- result.setProperty("datetime-lower", "2016-01-01 00:00:00");
- result.setProperty("datetime-upper", "2021-12-31 00:00:00");
- result.setProperty("sharding-suffix-pattern", "yyyyMM");
- result.setProperty("datetime-interval-amount", "1");
- result.setProperty("datetime-interval-unit", "Months");
- return result;
- }
-
private void initShardingStrategyByDay() {
int stepAmount = 2;
- shardingAlgorithmByDay = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createDayProperties(stepAmount)), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy-MM-dd HH:mm:ss"),
+ new Property("datetime-lower", "2021-06-01 00:00:00"),
+ new Property("datetime-upper", "2021-07-31 00:00:00"),
+ new Property("sharding-suffix-pattern", "yyyyMMdd"),
+ new Property("datetime-interval-amount", Integer.toString(stepAmount)));
+ shardingAlgorithmByDay = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int j = 6; j <= 7; j++) {
for (int i = 1; j == 6 ? i <= 30 : i <= 31; i = i + stepAmount) {
availableTablesForDayDataSources.add(String.format("t_order_%04d%02d%02d", 2021, j, i));
@@ -154,20 +154,17 @@ public final class IntervalShardingAlgorithmTest {
}
}
- private Properties createDayProperties(final int stepAmount) {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "yyyy-MM-dd HH:mm:ss");
- result.setProperty("datetime-lower", "2021-06-01 00:00:00");
- result.setProperty("datetime-upper", "2021-07-31 00:00:00");
- result.setProperty("sharding-suffix-pattern", "yyyyMMdd");
- result.setProperty("datetime-interval-amount", Integer.toString(stepAmount));
- return result;
- }
-
private void initShardStrategyByDayWithMillisecond() {
int stepAmount = 2;
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy-MM-dd HH:mm:ss.SSS"),
+ new Property("datetime-lower", "2021-06-01 00:00:00.000"),
+ new Property("datetime-upper", "2021-07-31 00:00:00.000"),
+ new Property("sharding-suffix-pattern", "yyyyMMdd"),
+ new Property("datetime-interval-amount", Integer.toString(stepAmount)),
+ new Property("datetime-interval-unit", "DAYS"));
shardingAlgorithmByDayWithMillisecond = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("INTERVAL", createDayWithMillisecondProperties(stepAmount)), ShardingAlgorithm.class);
+ new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int j = 6; j <= 7; j++) {
for (int i = 1; j == 6 ? i <= 30 : i <= 31; i = i + stepAmount) {
availableTablesForDayWithMillisecondDataSources.add(String.format("t_order_%04d%02d%02d", 2021, j, i));
@@ -175,20 +172,15 @@ public final class IntervalShardingAlgorithmTest {
}
}
- private Properties createDayWithMillisecondProperties(final int stepAmount) {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "yyyy-MM-dd HH:mm:ss.SSS");
- result.setProperty("datetime-lower", "2021-06-01 00:00:00.000");
- result.setProperty("datetime-upper", "2021-07-31 00:00:00.000");
- result.setProperty("sharding-suffix-pattern", "yyyyMMdd");
- result.setProperty("datetime-interval-amount", Integer.toString(stepAmount));
- result.setProperty("datetime-interval-unit", "DAYS");
- return result;
- }
-
private void initShardingStrategyByJDBCDate() {
int stepAmount = 2;
- shardingAlgorithmByJDBCDate = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createJDBCDateProperties(stepAmount)), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy-MM-dd"),
+ new Property("datetime-lower", "2021-06-01"),
+ new Property("datetime-upper", "2021-07-31"),
+ new Property("sharding-suffix-pattern", "yyyyMMdd"),
+ new Property("datetime-interval-amount", Integer.toString(stepAmount)));
+ shardingAlgorithmByJDBCDate = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int j = 6; j <= 7; j++) {
for (int i = 1; j == 6 ? i <= 30 : i <= 31; i = i + stepAmount) {
availableTablesForJDBCDateDataSources.add(String.format("t_order_%04d%02d%02d", 2021, j, i));
@@ -196,57 +188,46 @@ public final class IntervalShardingAlgorithmTest {
}
}
- private Properties createJDBCDateProperties(final int stepAmount) {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "yyyy-MM-dd");
- result.setProperty("datetime-lower", "2021-06-01");
- result.setProperty("datetime-upper", "2021-07-31");
- result.setProperty("sharding-suffix-pattern", "yyyyMMdd");
- result.setProperty("datetime-interval-amount", Integer.toString(stepAmount));
- return result;
- }
-
private void initShardingStrategyByJDBCTime() {
int stepAmount = 2;
- shardingAlgorithmByJDBCTime = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createJDBCTimeProperties(stepAmount)), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "HH:mm:ss.SSS"),
+ new Property("datetime-lower", "02:00:00.000"),
+ new Property("datetime-upper", "13:00:00.000"),
+ new Property("sharding-suffix-pattern", "HHmm"),
+ new Property("datetime-interval-amount", Integer.toString(stepAmount)),
+ new Property("datetime-interval-unit", "Hours"));
+ shardingAlgorithmByJDBCTime = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int i = 2; i < 13; i++) {
availableTablesForJDBCTimeDataSources.add(String.format("t_order_%02d%02d", i, 0));
}
}
- private Properties createJDBCTimeProperties(final int stepAmount) {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "HH:mm:ss.SSS");
- result.setProperty("datetime-lower", "02:00:00.000");
- result.setProperty("datetime-upper", "13:00:00.000");
- result.setProperty("sharding-suffix-pattern", "HHmm");
- result.setProperty("datetime-interval-amount", Integer.toString(stepAmount));
- result.setProperty("datetime-interval-unit", "Hours");
- return result;
- }
-
private void initShardingStrategyByYear() {
int stepAmount = 2;
- shardingAlgorithmByYear = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createYearProperties(stepAmount)), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy"),
+ new Property("datetime-lower", "2000"),
+ new Property("datetime-upper", "2022"),
+ new Property("sharding-suffix-pattern", "yyyy"),
+ new Property("datetime-interval-amount", Integer.toString(stepAmount)),
+ new Property("datetime-interval-unit", "Years"));
+ shardingAlgorithmByYear = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int i = 2000; i < 2023; i++) {
availableTablesForYearDataSources.add(String.format("t_order_%04d", i));
}
}
- private Properties createYearProperties(final int stepAmount) {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "yyyy");
- result.setProperty("datetime-lower", "2000");
- result.setProperty("datetime-upper", "2022");
- result.setProperty("sharding-suffix-pattern", "yyyy");
- result.setProperty("datetime-interval-amount", Integer.toString(stepAmount));
- result.setProperty("datetime-interval-unit", "Years");
- return result;
- }
-
private void initShardingStrategyByYearMonth() {
int stepAmount = 2;
- shardingAlgorithmByYearMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createYearMonthProperties(stepAmount)), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy-MM"),
+ new Property("datetime-lower", "2016-01"),
+ new Property("datetime-upper", "2021-12"),
+ new Property("sharding-suffix-pattern", "yyyyMM"),
+ new Property("datetime-interval-amount", Integer.toString(stepAmount)),
+ new Property("datetime-interval-unit", "Years"));
+ shardingAlgorithmByYearMonth = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int i = 2016; i <= 2021; i++) {
for (int j = 1; j <= 12; j++) {
availableTablesForYearMonthDataSources.add(String.format("t_order_%04d%02d", i, j));
@@ -254,36 +235,21 @@ public final class IntervalShardingAlgorithmTest {
}
}
- private Properties createYearMonthProperties(final int stepAmount) {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "yyyy-MM");
- result.setProperty("datetime-lower", "2016-01");
- result.setProperty("datetime-upper", "2021-12");
- result.setProperty("sharding-suffix-pattern", "yyyyMM");
- result.setProperty("datetime-interval-amount", Integer.toString(stepAmount));
- result.setProperty("datetime-interval-unit", "Years");
- return result;
- }
-
private void initShardingStrategyByMonthInJSR310() {
int stepAmount = 2;
- shardingAlgorithmByMonthInJSR310 = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", createMonthInJSR310Properties(stepAmount)), ShardingAlgorithm.class);
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "MM"),
+ new Property("datetime-lower", "02"),
+ new Property("datetime-upper", "12"),
+ new Property("sharding-suffix-pattern", "MM"),
+ new Property("datetime-interval-amount", Integer.toString(stepAmount)),
+ new Property("datetime-interval-unit", "Months"));
+ shardingAlgorithmByMonthInJSR310 = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INTERVAL", props), ShardingAlgorithm.class);
for (int i = 2; i < 13; i++) {
availableTablesForMonthInJSR310DataSources.add(String.format("t_order_%02d", i));
}
}
- private Properties createMonthInJSR310Properties(final int stepAmount) {
- Properties result = new Properties();
- result.setProperty("datetime-pattern", "MM");
- result.setProperty("datetime-lower", "02");
- result.setProperty("datetime-upper", "12");
- result.setProperty("sharding-suffix-pattern", "MM");
- result.setProperty("datetime-interval-amount", Integer.toString(stepAmount));
- result.setProperty("datetime-interval-unit", "Months");
- return result;
- }
-
@Test
public void assertPreciseDoShardingByQuarter() {
assertThat(shardingAlgorithmByQuarter.doSharding(availableTablesForQuarterDataSources,
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java
index 420e9937d67..41926732856 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/hint/HintInlineShardingAlgorithmTest.java
@@ -21,6 +21,8 @@ import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.sharding.api.sharding.hint.HintShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -40,17 +42,12 @@ public final class HintInlineShardingAlgorithmTest {
@Before
public void setUp() {
- hintInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("HINT_INLINE", createProperties()), ShardingAlgorithm.class);
+ hintInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("HINT_INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_$->{value % 4}"))), ShardingAlgorithm.class);
hintInlineShardingAlgorithmDefault = new HintInlineShardingAlgorithm();
hintInlineShardingAlgorithmDefault.init(new Properties());
}
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("algorithm-expression", "t_order_$->{value % 4}");
- return result;
- }
-
@Test
public void assertDoShardingWithSingleValueOfDefault() {
List<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
index de814d9019f..286e7b18b9e 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
@@ -26,6 +26,8 @@ import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingV
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.exception.algorithm.MismatchedInlineShardingAlgorithmExpressionAndColumnException;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -52,30 +54,14 @@ public final class InlineShardingAlgorithmTest {
@Before
public void setUp() {
- inlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createAllowRangeQueryProperties()), ShardingAlgorithm.class);
- inlineShardingAlgorithmWithSimplified = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createDisallowRangeQueryProperties()), ShardingAlgorithm.class);
- negativeNumberInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
- new AlgorithmConfiguration("INLINE", createNegativeAllowRangeQueryProperties()), ShardingAlgorithm.class);
- }
-
- private Properties createAllowRangeQueryProperties() {
- Properties result = new Properties();
- result.setProperty("algorithm-expression", "t_order_$->{order_id % 4}");
- result.setProperty("allow-range-query-with-inline-sharding", Boolean.TRUE.toString());
- return result;
- }
-
- private Properties createNegativeAllowRangeQueryProperties() {
- Properties result = new Properties();
- result.setProperty("algorithm-expression", "t_order_$->{(order_id % 4).abs()}");
- result.setProperty("allow-range-query-with-inline-sharding", Boolean.TRUE.toString());
- return result;
- }
-
- private Properties createDisallowRangeQueryProperties() {
- Properties result = new Properties();
- result.setProperty("algorithm-expression", "t_order_${order_id % 4}");
- return result;
+ Properties allowRangeQueryProps = PropertiesBuilder.build(
+ new Property("algorithm-expression", "t_order_$->{order_id % 4}"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString()));
+ inlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", allowRangeQueryProps), ShardingAlgorithm.class);
+ Properties disallowRangeQueryProps = PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${order_id % 4}"));
+ inlineShardingAlgorithmWithSimplified = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", disallowRangeQueryProps), ShardingAlgorithm.class);
+ Properties negativeAllowRangeQuery = PropertiesBuilder.build(
+ new Property("algorithm-expression", "t_order_$->{(order_id % 4).abs()}"), new Property("allow-range-query-with-inline-sharding", Boolean.TRUE.toString()));
+ negativeNumberInlineShardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", negativeAllowRangeQuery), ShardingAlgorithm.class);
}
@Test(expected = MismatchedInlineShardingAlgorithmExpressionAndColumnException.class)
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java
index cbfacdc4c46..da25c5913cf 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithmTest.java
@@ -24,13 +24,14 @@ import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+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.Collection;
import java.util.List;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -43,27 +44,20 @@ public final class HashModShardingAlgorithmTest {
@Before
public void setup() {
- shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("HASH_MOD", createProperties()), ShardingAlgorithm.class);
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.put("sharding-count", 4);
- return result;
+ shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("HASH_MOD", PropertiesBuilder.build(new Property("sharding-count", "4"))), ShardingAlgorithm.class);
}
@Test
public void assertPreciseDoSharding() {
List<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
- assertThat(shardingAlgorithm.doSharding(availableTargetNames,
- new PreciseShardingValue<>("t_order", "order_type", DATA_NODE_INFO, "a")), is("t_order_1"));
+ assertThat(shardingAlgorithm.doSharding(availableTargetNames, new PreciseShardingValue<>("t_order", "order_type", DATA_NODE_INFO, "a")), is("t_order_1"));
}
@Test
public void assertRangeDoSharding() {
List<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
- Collection<String> actual = shardingAlgorithm.doSharding(availableTargetNames,
- new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed("a", "f")));
+ Collection<String> actual = shardingAlgorithm.doSharding(availableTargetNames, new RangeShardingValue<>("t_order", "create_time", DATA_NODE_INFO, Range.closed("a", "f")));
assertThat(actual.size(), is(4));
}
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java
index 466a70a9d3c..d2a3b394677 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java
@@ -24,6 +24,8 @@ import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Arrays;
@@ -40,26 +42,30 @@ public final class ModShardingAlgorithmTest {
@Test
public void assertPreciseDoShardingWithIntShardingValue() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
assertThat(algorithm.doSharding(createAvailableTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, 17)), is("t_order_1"));
}
@Test
public void assertPreciseDoShardingWithBigIntegerShardingValue() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
assertThat(algorithm.doSharding(createAvailableTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_12"));
}
@Test
public void assertRangeDoShardingWithAllTargets() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
Collection<String> actual = algorithm.doSharding(createAvailableTargetNames(), new RangeShardingValue<>("t_order", "order_id", DATA_NODE_INFO, Range.closed(1L, 16L)));
assertThat(actual.size(), is(16));
}
@Test
public void assertRangeDoShardingWithPartTargets() {
- ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "16"))), ShardingAlgorithm.class);
Collection<String> actual = algorithm.doSharding(createAvailableTargetNames(),
new RangeShardingValue<>("t_order", "order_id", DATA_NODE_INFO, Range.closed(1L, 2L)));
assertThat(actual.size(), is(2));
@@ -67,12 +73,6 @@ public final class ModShardingAlgorithmTest {
assertTrue(actual.contains("t_order_2"));
}
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("sharding-count", "16");
- return result;
- }
-
private Collection<String> createAvailableTargetNames() {
return Arrays.asList("t_order_8", "t_order_9", "t_order_10", "t_order_11", "t_order_12", "t_order_13", "t_order_14", "t_order_15",
"t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4", "t_order_5", "t_order_6", "t_order_7");
@@ -109,12 +109,8 @@ public final class ModShardingAlgorithmTest {
}
private Properties createZeroPaddingProperties() {
- Properties result = new Properties();
- result.setProperty("sharding-count", "16");
- result.setProperty("zero-padding", Boolean.TRUE.toString());
- result.setProperty("start-offset", "1");
- result.setProperty("stop-offset", "1");
- return result;
+ return PropertiesBuilder.build(
+ new Property("sharding-count", "16"), new Property("zero-padding", Boolean.TRUE.toString()), new Property("start-offset", "1"), new Property("stop-offset", "1"));
}
private Collection<String> createAvailableIncludeZeroTargetNames() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java
index 7fb1b0de79d..2a5fa210f51 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithmTest.java
@@ -24,13 +24,14 @@ import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+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.Collection;
import java.util.List;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -44,13 +45,8 @@ public final class BoundaryBasedRangeShardingAlgorithmTest {
@Before
public void setUp() {
- shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("BOUNDARY_RANGE", createProperties()), ShardingAlgorithm.class);
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("sharding-ranges", "1,5,10");
- return result;
+ shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("BOUNDARY_RANGE", PropertiesBuilder.build(new Property("sharding-ranges", "1,5,10"))), ShardingAlgorithm.class);
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java
index 802c0728d06..8051d240a7b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithmTest.java
@@ -24,6 +24,8 @@ import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
@@ -48,11 +50,7 @@ public final class VolumeBasedRangeShardingAlgorithmTest {
}
private Properties createProperties() {
- Properties result = new Properties();
- result.put("range-lower", 10);
- result.put("range-upper", 45);
- result.put("sharding-volume", 10);
- return result;
+ return PropertiesBuilder.build(new Property("range-lower", "10"), new Property("range-upper", "45"), new Property("sharding-volume", "10"));
}
@Test
@@ -130,15 +128,7 @@ public final class VolumeBasedRangeShardingAlgorithmTest {
@Test
public void assertGetAutoTablesAmount() {
VolumeBasedRangeShardingAlgorithm shardingAlgorithm = new VolumeBasedRangeShardingAlgorithm();
- shardingAlgorithm.init(createPropertiesForStringValue());
+ shardingAlgorithm.init(PropertiesBuilder.build(new Property("range-lower", "10"), new Property("range-upper", "45"), new Property("sharding-volume", "10")));
assertThat(shardingAlgorithm.getAutoTablesAmount(), is(6));
}
-
- private Properties createPropertiesForStringValue() {
- Properties result = new Properties();
- result.setProperty("range-lower", "10");
- result.setProperty("range-upper", "45");
- result.setProperty("sharding-volume", "10");
- return result;
- }
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
index b21b1ca8d66..e498db2412b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
@@ -37,6 +37,8 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.rule.SingleRule;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -59,24 +61,18 @@ public abstract class AbstractRoutingEngineTest {
protected final ShardingRule createBasedShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order", "ds_${0..1}.t_order_${0..1}", "t_order_${order_id % 2}", "ds_${user_id % 2}"));
- Properties props0 = new Properties();
- props0.setProperty("algorithm-expression", "ds_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", props0));
- Properties props1 = new Properties();
- props1.setProperty("algorithm-expression", "t_order_${order_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", new AlgorithmConfiguration("INLINE", props1));
+ shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${order_id % 2}"))));
return new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
protected final ShardingRule createErrorShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order", "ds_${0..1}.t_order_${0..1}", "t_order_${order_id % 2}", "ds_${user_id % 2}"));
- Properties props0 = new Properties();
- props0.setProperty("algorithm-expression", "ds_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", props0));
- Properties props1 = new Properties();
- props1.setProperty("algorithm-expression", "t_order_${order_id % 3}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", new AlgorithmConfiguration("INLINE", props1));
+ shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${order_id % 3}"))));
return new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
@@ -85,15 +81,11 @@ public abstract class AbstractRoutingEngineTest {
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order", "ds_${0..1}.t_order_${0..1}", "t_order_${order_id % 2}", "ds_${user_id % 2}"));
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order_item", "ds_${0..1}.t_order_item_${0..1}", "t_order_item_${order_id % 2}", "ds_${user_id % 2}"));
shardingRuleConfig.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration("foo", "t_order,t_order_item"));
- Properties props0 = new Properties();
- props0.setProperty("algorithm-expression", "ds_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", props0));
- Properties props1 = new Properties();
- props1.setProperty("algorithm-expression", "t_order_${order_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", new AlgorithmConfiguration("INLINE", props1));
- Properties props2 = new Properties();
- props2.setProperty("algorithm-expression", "t_order_item_${order_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_item_inline", new AlgorithmConfiguration("INLINE", props2));
+ shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${order_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_item_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_item_${order_id % 2}"))));
return new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
@@ -102,15 +94,11 @@ public abstract class AbstractRoutingEngineTest {
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order", "ds_${0..1}.t_order_${0..1}", "t_order_${order_id % 2}", "ds_${user_id % 2}"));
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order_item", "ds_${0..1}.t_order_item_${0..1}", "t_order_item_${order_id % 2}", "ds_${user_id % 2}"));
shardingRuleConfig.getBroadcastTables().add("t_config");
- Properties props0 = new Properties();
- props0.setProperty("algorithm-expression", "ds_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", props0));
- Properties props1 = new Properties();
- props1.setProperty("algorithm-expression", "t_order_${order_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", new AlgorithmConfiguration("INLINE", props1));
- Properties props2 = new Properties();
- props2.setProperty("algorithm-expression", "t_order_item_${order_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_item_inline", new AlgorithmConfiguration("INLINE", props2));
+ shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${order_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_item_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_item_${order_id % 2}"))));
return new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
@@ -128,36 +116,27 @@ public abstract class AbstractRoutingEngineTest {
shardingRuleConfig.getTables().add(createTableRuleConfig("t_hint_table_test", "ds_${0..1}.t_hint_table_test_${0..1}",
createStandardShardingStrategyConfiguration("ds_inline", "ds_${user_id % 2}"), new HintShardingStrategyConfiguration("core_hint_fixture")));
shardingRuleConfig.getShardingAlgorithms().put("core_hint_fixture", new AlgorithmConfiguration("CORE.HINT.FIXTURE", new Properties()));
- Properties props0 = new Properties();
- props0.setProperty("algorithm-expression", "ds_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", props0));
- Properties props1 = new Properties();
- props1.setProperty("algorithm-expression", "t_hint_ds_test_${order_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_hint_ds_test_inline", new AlgorithmConfiguration("INLINE", props1));
+ shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_hint_ds_test_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_hint_ds_test_${order_id % 2}"))));
return new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
protected final ShardingRule createAllShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getBroadcastTables().add("t_product");
- Properties props0 = new Properties();
- props0.setProperty("algorithm-expression", "ds_${user_id % 2}");
shardingRuleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "ds_inline"));
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order", "ds_${0..1}.t_order_${0..1}", "t_order_${user_id % 2}", "ds_${user_id % 2}"));
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_order_item", "ds_${0..1}.t_order_item_${0..1}", "t_order_item_${user_id % 2}", "ds_${user_id % 2}"));
shardingRuleConfig.getTables().add(createInlineTableRuleConfig("t_user", "ds_${0..1}.t_user_${0..1}", "t_user_${user_id % 2}", "ds_${user_id % 2}"));
shardingRuleConfig.getTables().add(createTableRuleWithHintConfig());
shardingRuleConfig.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration("foo", "t_order,t_order_item"));
- shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", props0));
- Properties props1 = new Properties();
- props1.setProperty("algorithm-expression", "t_order_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", new AlgorithmConfiguration("INLINE", props1));
- Properties props2 = new Properties();
- props2.setProperty("algorithm-expression", "t_order_item_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_order_item_inline", new AlgorithmConfiguration("INLINE", props2));
- Properties props3 = new Properties();
- props3.setProperty("algorithm-expression", "t_user_${user_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("t_user_inline", new AlgorithmConfiguration("INLINE", props3));
+ shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "t_order_item_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_order_item_${user_id % 2}"))));
+ shardingRuleConfig.getShardingAlgorithms().put("t_user_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "t_user_${user_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put("core_hint_fixture", new AlgorithmConfiguration("CORE.HINT.FIXTURE", new Properties()));
return new ShardingRule(shardingRuleConfig, Arrays.asList("ds_0", "ds_1", "main"), mock(InstanceContext.class));
}
@@ -166,14 +145,14 @@ public abstract class AbstractRoutingEngineTest {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfig("t_interval_test", "ds_0.t_interval_test_202101,ds_1.t_interval_test_202102",
null, new StandardShardingStrategyConfiguration("create_at", "interval_test")));
- Properties props0 = new Properties();
- props0.setProperty("datetime-pattern", "yyyy-MM-dd HH:mm:ss");
- props0.setProperty("datetime-lower", "2021-01-01 00:00:00");
- props0.setProperty("datetime-upper", "2021-01-02 00:00:00");
- props0.setProperty("sharding-suffix-pattern", "yyyyMM");
- props0.setProperty("datetime-interval-amount", "1");
- props0.setProperty("datetime-interval-unit", "MONTHS");
- shardingRuleConfig.getShardingAlgorithms().put("interval_test", new AlgorithmConfiguration("INTERVAL", props0));
+ Properties props = PropertiesBuilder.build(
+ new Property("datetime-pattern", "yyyy-MM-dd HH:mm:ss"),
+ new Property("datetime-lower", "2021-01-01 00:00:00"),
+ new Property("datetime-upper", "2021-01-02 00:00:00"),
+ new Property("sharding-suffix-pattern", "yyyyMM"),
+ new Property("datetime-interval-amount", "1"),
+ new Property("datetime-interval-unit", "MONTHS"));
+ shardingRuleConfig.getShardingAlgorithms().put("interval_test", new AlgorithmConfiguration("INTERVAL", props));
return new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
index 6c0a1a42c4f..d715acfec4b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
@@ -59,6 +59,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectState
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.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.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -70,7 +72,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
-import java.util.Properties;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -225,14 +226,8 @@ public final class ShardingInsertStatementValidatorTest {
when(databaseStrategyConfig.getShardingColumn()).thenReturn("id");
when(databaseStrategyConfig.getShardingAlgorithmName()).thenReturn("database_inline");
when(shardingRule.getDatabaseShardingStrategyConfiguration(tableRule)).thenReturn(databaseStrategyConfig);
- when(shardingRule.getShardingAlgorithms()).thenReturn(
- Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createProperties()), ShardingAlgorithm.class)));
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.put("algorithm-expression", "ds_${id % 2}");
- return result;
+ when(shardingRule.getShardingAlgorithms()).thenReturn(Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${id % 2}"))), ShardingAlgorithm.class)));
}
private RouteContext createSingleRouteContext() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
index 3dacf33b1c0..07371b2951f 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
@@ -45,6 +45,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Tab
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLUpdateStatement;
+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.Mock;
@@ -57,7 +59,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.Properties;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -136,13 +137,8 @@ public final class ShardingUpdateStatementValidatorTest {
}
private Map<String, ShardingAlgorithm> createShardingAlgorithmMap() {
- return Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("INLINE", createProperties()), ShardingAlgorithm.class));
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.put("algorithm-expression", "ds_${id % 2}");
- return result;
+ return Collections.singletonMap("database_inline", ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${id % 2}"))), ShardingAlgorithm.class));
}
private RouteContext createSingleRouteContext() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 674c395a8ea..ec0ba6f3bc6 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -53,6 +53,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.Test;
import java.util.Arrays;
@@ -332,13 +334,9 @@ public final class ShardingRuleTest {
shardingRuleConfig.getTables().add(subTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration("foo", shardingTableRuleConfig.getLogicTable() + "," + subTableRuleConfig.getLogicTable()));
shardingTableRuleConfig.setDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("ds_id", "shardingAlgorithmDB"));
- Properties shardingProps = new Properties();
- shardingProps.setProperty("algorithm-expression", "ds_%{ds_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("shardingAlgorithmDB", new AlgorithmConfiguration("INLINE", shardingProps));
+ shardingRuleConfig.getShardingAlgorithms().put("shardingAlgorithmDB", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_%{ds_id % 2}"))));
subTableRuleConfig.setDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("ds_id", "subAlgorithmDB"));
- Properties subProps = new Properties();
- subProps.setProperty("algorithm-expression", "ds_%{ds_id % 3}");
- shardingRuleConfig.getShardingAlgorithms().put("subAlgorithmDB", new AlgorithmConfiguration("INLINE", subProps));
+ shardingRuleConfig.getShardingAlgorithms().put("subAlgorithmDB", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_%{ds_id % 3}"))));
new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
@@ -351,13 +349,11 @@ public final class ShardingRuleTest {
shardingRuleConfig.getTables().add(subTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration("foo", shardingTableRuleConfig.getLogicTable() + "," + subTableRuleConfig.getLogicTable()));
shardingTableRuleConfig.setTableShardingStrategy(new StandardShardingStrategyConfiguration("table_id", "shardingAlgorithmTBL"));
- Properties shardingProps = new Properties();
- shardingProps.setProperty("algorithm-expression", "table_%{table_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("shardingAlgorithmTBL", new AlgorithmConfiguration("INLINE", shardingProps));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "shardingAlgorithmTBL", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "table_%{table_id % 2}"))));
subTableRuleConfig.setTableShardingStrategy(new StandardShardingStrategyConfiguration("table_id", "subAlgorithmTBL"));
- Properties subProps = new Properties();
- subProps.setProperty("algorithm-expression", "table_%{table_id % 3}");
- shardingRuleConfig.getShardingAlgorithms().put("subAlgorithmTBL", new AlgorithmConfiguration("INLINE", subProps));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "subAlgorithmTBL", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "table_%{table_id % 3}"))));
new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
@@ -370,14 +366,11 @@ public final class ShardingRuleTest {
shardingRuleConfig.getTables().add(subTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration("foo", shardingTableRuleConfig.getLogicTable() + "," + subTableRuleConfig.getLogicTable()));
shardingTableRuleConfig.setTableShardingStrategy(new StandardShardingStrategyConfiguration("table_id", "shardingAlgorithmTBL"));
- Properties shardingProps = new Properties();
- shardingProps.setProperty("algorithm-expression", "table_%{table_id % 2}");
- shardingRuleConfig.getShardingAlgorithms().put("shardingAlgorithmTBL", new AlgorithmConfiguration("INLINE", shardingProps));
+ shardingRuleConfig.getShardingAlgorithms().put(
+ "shardingAlgorithmTBL", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "table_%{table_id % 2}"))));
shardingRuleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("table_id", "table_inline"));
shardingRuleConfig.setDefaultShardingColumn("table_id");
- Properties subProps = new Properties();
- subProps.setProperty("algorithm-expression", "table_%{table_id % 3}");
- shardingRuleConfig.getShardingAlgorithms().put("table_inline", new AlgorithmConfiguration("INLINE", subProps));
+ shardingRuleConfig.getShardingAlgorithms().put("table_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "table_%{table_id % 3}"))));
new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
}
@@ -430,9 +423,7 @@ public final class ShardingRuleTest {
ShardingAutoTableRuleConfiguration autoTableRuleConfig = new ShardingAutoTableRuleConfiguration("auto_table", "resource0, resource1");
autoTableRuleConfig.setShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "hash_mod"));
shardingRuleConfig.getAutoTables().add(autoTableRuleConfig);
- Properties props = new Properties();
- props.put("sharding-count", 4);
- shardingRuleConfig.getShardingAlgorithms().put("hash_mod", new AlgorithmConfiguration("hash_mod", props));
+ shardingRuleConfig.getShardingAlgorithms().put("hash_mod", new AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new Property("sharding-count", "4"))));
ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
assertThat(shardingRule.getDataSourceNames(), is(new LinkedHashSet<>(Arrays.asList("ds_0", "ds_1", "resource0", "resource1"))));
}
@@ -452,9 +443,7 @@ public final class ShardingRuleTest {
ShardingAutoTableRuleConfiguration autoTableRuleConfig = new ShardingAutoTableRuleConfiguration("auto_table", "resource${0..1}");
autoTableRuleConfig.setShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "hash_mod"));
shardingRuleConfig.getAutoTables().add(autoTableRuleConfig);
- Properties props = new Properties();
- props.put("sharding-count", 4);
- shardingRuleConfig.getShardingAlgorithms().put("hash_mod", new AlgorithmConfiguration("hash_mod", props));
+ shardingRuleConfig.getShardingAlgorithms().put("hash_mod", new AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new Property("sharding-count", "4"))));
ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, createDataSourceNames(), mock(InstanceContext.class));
assertThat(shardingRule.getDataSourceNames(), is(new LinkedHashSet<>(Arrays.asList("resource0", "resource1"))));
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
index 4cbc6c962d8..3fbcf5f1cb3 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShard
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.exception.metadata.DataNodesMissedWithShardingTableException;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Arrays;
@@ -38,7 +40,6 @@ import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -81,7 +82,8 @@ public final class TableRuleTest {
public void assertCreateAutoTableRuleWithModAlgorithm() {
ShardingAutoTableRuleConfiguration tableRuleConfig = new ShardingAutoTableRuleConfiguration("LOGIC_TABLE", "ds0,ds1");
tableRuleConfig.setShardingStrategy(new StandardShardingStrategyConfiguration("col_1", "MOD"));
- ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4"))), ShardingAlgorithm.class);
TableRule actual = new TableRule(tableRuleConfig, Arrays.asList("ds0", "ds1", "ds2"), shardingAlgorithm, null);
assertThat(actual.getLogicTable(), is("LOGIC_TABLE"));
assertThat(actual.getActualDataNodes().size(), is(4));
@@ -95,7 +97,8 @@ public final class TableRuleTest {
public void assertCreateAutoTableRuleWithModAlgorithmWithoutActualDataSources() {
ShardingAutoTableRuleConfiguration tableRuleConfig = new ShardingAutoTableRuleConfiguration("LOGIC_TABLE", null);
tableRuleConfig.setShardingStrategy(new StandardShardingStrategyConfiguration("col_1", "MOD"));
- ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("MOD", createProperties()), ShardingAlgorithm.class);
+ ModShardingAlgorithm shardingAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4"))), ShardingAlgorithm.class);
TableRule actual = new TableRule(tableRuleConfig, Arrays.asList("ds0", "ds1", "ds2"), shardingAlgorithm, null);
assertThat(actual.getLogicTable(), is("LOGIC_TABLE"));
assertThat(actual.getActualDataNodes().size(), is(4));
@@ -105,12 +108,6 @@ public final class TableRuleTest {
assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "logic_table_3")));
}
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("sharding-count", "4");
- return result;
- }
-
@Test
public void assertGetActualDataSourceNames() {
TableRule actual = new TableRule(new ShardingTableRuleConfiguration("LOGIC_TABLE", "ds${0..1}.table_${0..2}"), Arrays.asList("ds0", "ds1"), null);
diff --git a/features/sharding/distsql/handler/pom.xml b/features/sharding/distsql/handler/pom.xml
index 751b71ebe4b..3cf7f5c06e5 100644
--- a/features/sharding/distsql/handler/pom.xml
+++ b/features/sharding/distsql/handler/pom.xml
@@ -55,5 +55,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/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
index 7e1068b99ce..83467c509d2 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.sharding.distsql.checker;
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.rule.MissingRequiredRuleException;
+import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -42,6 +42,8 @@ import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AbstractT
import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AutoTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.table.TableRuleSegment;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
+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;
@@ -99,9 +101,9 @@ public final class ShardingRuleStatementCheckerTest {
shardingRuleConfig.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration("reference_0", "t_order,t_order_item"));
Collection<AbstractTableRuleSegment> rules = new LinkedList<>();
rules.add(new AutoTableRuleSegment("t_order", Arrays.asList("ds_0", "ds_1"), "order_id",
- new AlgorithmSegment("CORE.AUTO.FIXTURE", newProperties("sharding-count", "2")), null, null));
+ new AlgorithmSegment("CORE.AUTO.FIXTURE", PropertiesBuilder.build(new Property("sharding-count", "2"))), null, null));
rules.add(new AutoTableRuleSegment("t_order_item", Arrays.asList("ds_0", "ds_1"), "order_id",
- new AlgorithmSegment("CORE.AUTO.FIXTURE", newProperties("sharding-count", "2")), null, null));
+ new AlgorithmSegment("CORE.AUTO.FIXTURE", PropertiesBuilder.build(new Property("sharding-count", "2"))), null, null));
ShardingTableRuleStatementChecker.checkAlteration(database, rules, shardingRuleConfig);
}
@@ -134,7 +136,7 @@ public final class ShardingRuleStatementCheckerTest {
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertCheckCreationWithInvalidKeyGenerateAlgorithm() {
AutoTableRuleSegment autoTableRuleSegment = new AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
- autoTableRuleSegment.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("invalid", newProperties("invalid", "invalid"))));
+ autoTableRuleSegment.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("invalid", PropertiesBuilder.build(new Property("invalid", "invalid")))));
ShardingTableRuleStatementChecker.checkCreation(database, Collections.singleton(autoTableRuleSegment), false, shardingRuleConfig);
}
@@ -150,10 +152,10 @@ public final class ShardingRuleStatementCheckerTest {
public void assertCheckAutoTableWithNotExistShardingAlgorithms() {
AutoTableRuleSegment autoTableRuleSegment = new AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
autoTableRuleSegment.setShardingColumn("product_id");
- autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("not_exist", newProperties("", "")));
+ autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("not_exist", PropertiesBuilder.build(new Property("", ""))));
List<AbstractTableRuleSegment> rules = Collections.singletonList(autoTableRuleSegment);
ShardingTableRuleStatementChecker.checkCreation(database, rules, false, shardingRuleConfig);
- autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("complex", newProperties("", "")));
+ autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("complex", PropertiesBuilder.build(new Property("", ""))));
ShardingTableRuleStatementChecker.checkCreation(database, rules, false, shardingRuleConfig);
}
@@ -161,7 +163,7 @@ public final class ShardingRuleStatementCheckerTest {
public void assertCheckAutoTableWithComplexShardingAlgorithms() {
AutoTableRuleSegment autoTableRuleSegment = new AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
autoTableRuleSegment.setShardingColumn("product_id");
- autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("complex", newProperties("", "")));
+ autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("complex", PropertiesBuilder.build(new Property("", ""))));
List<AbstractTableRuleSegment> rules = Collections.singletonList(autoTableRuleSegment);
ShardingTableRuleStatementChecker.checkCreation(database, rules, false, shardingRuleConfig);
}
@@ -193,7 +195,7 @@ public final class ShardingRuleStatementCheckerTest {
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertCheckTableWithUnmatchedShardingStrategyType3() {
TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
- AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("CORE.AUTO.FIXTURE", newProperties("sharding-count", "4"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("CORE.AUTO.FIXTURE", PropertiesBuilder.build(new Property("sharding-count", "4")));
tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("standard", "user_id", databaseAlgorithmSegment));
List<AbstractTableRuleSegment> rules = Collections.singletonList(tableRuleSegment);
ShardingTableRuleStatementChecker.checkCreation(database, rules, false, shardingRuleConfig);
@@ -218,7 +220,7 @@ public final class ShardingRuleStatementCheckerTest {
@Test
public void assertCheckNullAlgorithmNameAndAlgorithmSegment() {
TableRuleSegment tableRuleSegment = new TableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
- AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${product_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${product_id % 2}")));
tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id", databaseAlgorithmSegment));
List<AbstractTableRuleSegment> rules = Collections.singletonList(tableRuleSegment);
ShardingTableRuleStatementChecker.checkCreation(database, rules, false, shardingRuleConfig);
@@ -235,7 +237,7 @@ public final class ShardingRuleStatementCheckerTest {
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertCheckAutoTableRuleWithStandardShardingAlgoithm() {
AutoTableRuleSegment autoTableRuleSegment = new AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
- autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("INLINE", newProperties("algorithm-expression", "ds_${product_id% 2}")));
+ autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${product_id % 2}"))));
List<AbstractTableRuleSegment> rules = Collections.singletonList(autoTableRuleSegment);
ShardingTableRuleStatementChecker.checkCreation(database, rules, false, shardingRuleConfig);
}
@@ -243,7 +245,7 @@ public final class ShardingRuleStatementCheckerTest {
@Test
public void assertCheckAutoTableRuleWithAutoShardingAlgoithm() {
AutoTableRuleSegment autoTableRuleSegment = new AutoTableRuleSegment("t_product", Arrays.asList("ds_0", "ds_1"));
- autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("CORE.AUTO.FIXTURE", newProperties("sharding-count", "4")));
+ autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("CORE.AUTO.FIXTURE", PropertiesBuilder.build(new Property("sharding-count", "4"))));
List<AbstractTableRuleSegment> rules = Collections.singletonList(autoTableRuleSegment);
ShardingTableRuleStatementChecker.checkCreation(database, rules, false, shardingRuleConfig);
}
@@ -265,18 +267,12 @@ public final class ShardingRuleStatementCheckerTest {
autoTableRuleConfig.setShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "t_order_algorithm"));
autoTableRuleConfig.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("order_item_id", "t_order_item_snowflake"));
result.getAutoTables().add(autoTableRuleConfig);
- result.getShardingAlgorithms().put("t_order_algorithm", new AlgorithmConfiguration("hash_mod", newProperties("sharding-count", "4")));
+ result.getShardingAlgorithms().put("t_order_algorithm", new AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new Property("sharding-count", "4"))));
result.getKeyGenerators().put("t_order_item_snowflake", new AlgorithmConfiguration("snowflake", new Properties()));
result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
return result;
}
- private static Properties newProperties(final String key, final String value) {
- Properties result = new Properties();
- result.put(key, value);
- return result;
- }
-
private static Map<String, DataSource> createDataSource() {
Map<String, DataSource> result = new HashMap<>(2, 1);
result.put("ds_0", new MockedDataSource());
@@ -288,7 +284,7 @@ public final class ShardingRuleStatementCheckerTest {
AutoTableRuleSegment result = new AutoTableRuleSegment("t_product_0", Arrays.asList("ds_0", "ds_1"));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
result.setShardingColumn("product_id");
- result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", newProperties("", "")));
+ result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", PropertiesBuilder.build(new Property("", ""))));
return result;
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/converter/ShardingRuleStatementConverterTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/converter/ShardingRuleStatementConverterTest.java
index f7bc80975ad..8ae011c901b 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/converter/ShardingRuleStatementConverterTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/converter/ShardingRuleStatementConverterTest.java
@@ -22,13 +22,15 @@ import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.converter.ShardingTableRuleStatementConverter;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AbstractTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.strategy.AuditStrategySegment;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AutoTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.strategy.KeyGenerateStrategySegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.strategy.ShardingAuditorSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.strategy.ShardingStrategySegment;
+import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AbstractTableRuleSegment;
+import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AutoTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.table.TableRuleSegment;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Arrays;
@@ -76,17 +78,17 @@ public final class ShardingRuleStatementConverterTest {
private Collection<AbstractTableRuleSegment> createTableRuleSegment1() {
Collection<AbstractTableRuleSegment> result = new LinkedList<>();
AutoTableRuleSegment autoTableRuleSegment1 = new AutoTableRuleSegment("t_order", Arrays.asList("ds0", "ds1"), "order_id",
- new AlgorithmSegment("MOD", newProperties("sharding_count", "2")), null, null);
- AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${product_id% 2}"));
+ new AlgorithmSegment("MOD", PropertiesBuilder.build(new Property("sharding_count", "2"))), null, null);
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${product_id % 2}")));
AutoTableRuleSegment autoTableRuleSegment2 = new AutoTableRuleSegment("t_order_2", Arrays.asList("ds0", "ds1"), "order_id",
- new AlgorithmSegment("MOD", newProperties("sharding_count", "2")),
+ new AlgorithmSegment("MOD", PropertiesBuilder.build(new Property("sharding_count", "2"))),
new KeyGenerateStrategySegment("order_id", "snowflake_algorithm"),
new AuditStrategySegment(Collections.singleton(new ShardingAuditorSegment("sharding_key_required_auditor",
new AlgorithmSegment("DML_SHARDING_CONDITIONS", new Properties()))), true));
TableRuleSegment tableRuleSegment = new TableRuleSegment("t_order", Arrays.asList("ds0", "ds1"),
new ShardingStrategySegment("standard", "order_id", databaseAlgorithmSegment),
new ShardingStrategySegment("standard", "order_id", new AlgorithmSegment("order_id_algorithm", new Properties())),
- new KeyGenerateStrategySegment("order_id", new AlgorithmSegment("snowflake", newProperties("", ""))),
+ new KeyGenerateStrategySegment("order_id", new AlgorithmSegment("snowflake", PropertiesBuilder.build(new Property("", "")))),
new AuditStrategySegment(Collections.singleton(new ShardingAuditorSegment("sharding_key_required_auditor",
new AlgorithmSegment("DML_SHARDING_CONDITIONS", new Properties()))), true));
result.add(autoTableRuleSegment1);
@@ -94,14 +96,4 @@ public final class ShardingRuleStatementConverterTest {
result.add(tableRuleSegment);
return result;
}
-
- private AlgorithmSegment getAutoCreativeAlgorithmSegment(final String name, final Properties props) {
- return new AlgorithmSegment(name, props);
- }
-
- private Properties newProperties(final String key, final String value) {
- Properties result = new Properties();
- result.put(key, value);
- return result;
- }
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmResultSetTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmResultSetTest.java
index 27ec55f562a..b25aaaa653e 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmResultSetTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingAlgorithmResultSetTest.java
@@ -23,16 +23,17 @@ import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingAlgorithmResultSet;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingAlgorithmsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+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.List;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -63,9 +64,7 @@ public final class ShardingAlgorithmResultSetTest {
private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- Properties props = new Properties();
- props.put("algorithm-expression", "ds_${user_id % 2}");
- result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", props));
+ result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
return result;
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyResultSetTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyResultSetTest.java
index 5ffac9bf36f..b5ddac7795d 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyResultSetTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingDefaultShardingStrategyResultSetTest.java
@@ -28,12 +28,13 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardS
import org.apache.shardingsphere.sharding.distsql.handler.query.DefaultShardingStrategyResultSet;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingAlgorithmsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+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.List;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -92,9 +93,7 @@ public final class ShardingDefaultShardingStrategyResultSetTest {
private RuleConfiguration createRuleConfiguration1() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- Properties props = new Properties();
- props.put("algorithm-expression", "ds_${user_id % 2}");
- result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", props));
+ result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
result.setDefaultTableShardingStrategy(new NoneShardingStrategyConfiguration());
result.setDefaultDatabaseShardingStrategy(new ComplexShardingStrategyConfiguration("use_id, order_id", "database_inline"));
return result;
@@ -102,9 +101,7 @@ public final class ShardingDefaultShardingStrategyResultSetTest {
private RuleConfiguration createRuleConfiguration2() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- Properties props = new Properties();
- props.put("algorithm-expression", "ds_${user_id % 2}");
- result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", props));
+ result.getShardingAlgorithms().put("database_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}"))));
result.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("use_id", "database_inline"));
result.setDefaultDatabaseShardingStrategy(new HintShardingStrategyConfiguration("database_inline"));
return result;
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleResultSetTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleResultSetTest.java
index 477b7ae7b3e..587109b39aa 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleResultSetTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingTableRuleResultSetTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.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.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -30,6 +30,8 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardS
import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingTableRuleResultSet;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.ArrayList;
@@ -99,9 +101,7 @@ public final class ShardingTableRuleResultSetTest {
}
private AlgorithmConfiguration createShardingInlineAlgorithmConfiguration(final String algorithmExpression) {
- Properties props = new Properties();
- props.put("algorithm-expression", algorithmExpression);
- return new AlgorithmConfiguration("INLINE", props);
+ return new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", algorithmExpression)));
}
private AlgorithmConfiguration createKeyGeneratorConfiguration() {
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmResultSetTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmResultSetTest.java
index 3093021a07d..6d51c8ad1b5 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmResultSetTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmResultSetTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardS
import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingTableRulesUsedAlgorithmResultSet;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedAlgorithmStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.ArrayList;
@@ -94,15 +96,11 @@ public final class ShowShardingTableRulesUsedAlgorithmResultSetTest {
}
private AlgorithmConfiguration createShardingInlineAlgorithmConfiguration(final String algorithmExpression) {
- Properties props = new Properties();
- props.put("algorithm-expression", algorithmExpression);
- return new AlgorithmConfiguration("INLINE", props);
+ return new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", algorithmExpression)));
}
private AlgorithmConfiguration createShardingAutoModAlgorithmConfiguration() {
- Properties props = new Properties();
- props.put("sharding-count", 4);
- return new AlgorithmConfiguration("MOD", props);
+ return new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
}
private AlgorithmConfiguration createKeyGeneratorConfiguration() {
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorResultSetTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorResultSetTest.java
index e7f3dc60043..97cc93f1030 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorResultSetTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorResultSetTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardS
import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingTableRulesUsedAuditorResultSet;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedAuditorStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.ArrayList;
@@ -93,15 +95,11 @@ public final class ShowShardingTableRulesUsedAuditorResultSetTest {
}
private AlgorithmConfiguration createShardingInlineAlgorithmConfiguration(final String algorithmExpression) {
- Properties props = new Properties();
- props.put("algorithm-expression", algorithmExpression);
- return new AlgorithmConfiguration("INLINE", props);
+ return new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", algorithmExpression)));
}
private AlgorithmConfiguration createShardingAutoModAlgorithmConfiguration() {
- Properties props = new Properties();
- props.put("sharding-count", 4);
- return new AlgorithmConfiguration("MOD", props);
+ return new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
}
private AlgorithmConfiguration createAuditorConfiguration() {
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorResultSetTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorResultSetTest.java
index 65c4df2a07f..df20c71e644 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorResultSetTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorResultSetTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.distsql.query;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardS
import org.apache.shardingsphere.sharding.distsql.handler.query.ShardingTableRulesUsedKeyGeneratorResultSet;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedKeyGeneratorStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.ArrayList;
@@ -92,15 +94,11 @@ public final class ShowShardingTableRulesUsedKeyGeneratorResultSetTest {
}
private AlgorithmConfiguration createShardingInlineAlgorithmConfiguration(final String algorithmExpression) {
- Properties props = new Properties();
- props.put("algorithm-expression", algorithmExpression);
- return new AlgorithmConfiguration("INLINE", props);
+ return new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", algorithmExpression)));
}
private AlgorithmConfiguration createShardingAutoModAlgorithmConfiguration() {
- Properties props = new Properties();
- props.put("sharding-count", 4);
- return new AlgorithmConfiguration("MOD", props);
+ return new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
}
private AlgorithmConfiguration createKeyGeneratorConfiguration() {
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsResultSetTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsResultSetTest.java
index c37171d0299..68353f727ea 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsResultSetTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/UnusedShardingAlgorithmsResultSetTest.java
@@ -26,12 +26,13 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardS
import org.apache.shardingsphere.sharding.distsql.handler.query.UnusedShardingAlgorithmsResultSet;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingAlgorithmsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+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.List;
import java.util.Optional;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -69,15 +70,11 @@ public final class UnusedShardingAlgorithmsResultSetTest {
}
private AlgorithmConfiguration createShardingInlineAlgorithmConfiguration() {
- Properties props = new Properties();
- props.put("algorithm-expression", "ds_${user_id % 2}");
- return new AlgorithmConfiguration("INLINE", props);
+ return new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}")));
}
private AlgorithmConfiguration createShardingHashModAlgorithmConfiguration() {
- Properties props = new Properties();
- props.put("sharding-count", 4);
- return new AlgorithmConfiguration("hash_mod", props);
+ return new AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new Property("sharding-count", "4")));
}
private ShardingAutoTableRuleConfiguration createShardingAutoTableRuleConfiguration() {
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java
index 6ad350de76c..1716f922836 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterDefaultShardingStrategyStatementUpdaterTest.java
@@ -17,15 +17,17 @@
package org.apache.shardingsphere.sharding.distsql.update;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
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.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.update.AlterDefaultShardingStrategyStatementUpdater;
import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterDefaultShardingStrategyStatement;
+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,7 +100,7 @@ public final class AlterDefaultShardingStrategyStatementUpdaterTest {
@Test
public void assertAlterDefaultDatabaseShardingStrategy() {
- AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}")));
AlterDefaultShardingStrategyStatement statement = new AlterDefaultShardingStrategyStatement("DATABASE", "standard", "user_id", databaseAlgorithmSegment);
ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration();
currentRuleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "orderAlgorithm"));
@@ -109,14 +111,4 @@ public final class AlterDefaultShardingStrategyStatementUpdaterTest {
assertThat(defaultDatabaseShardingStrategy.getShardingAlgorithmName(), is("default_database_inline"));
assertThat(defaultDatabaseShardingStrategy.getShardingColumn(), is("user_id"));
}
-
- private AlgorithmSegment getAutoCreativeAlgorithmSegment(final String name, final Properties props) {
- return new AlgorithmSegment(name, props);
- }
-
- private static Properties newProperties(final String key, final String value) {
- Properties result = new Properties();
- result.put(key, value);
- return result;
- }
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
index 4008894954b..1d5f9b6d603 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
@@ -34,6 +34,8 @@ import org.apache.shardingsphere.sharding.distsql.parser.segment.table.AutoTable
import org.apache.shardingsphere.sharding.distsql.parser.segment.table.TableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.statement.AlterShardingTableRuleStatement;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
+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;
@@ -155,14 +157,14 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
AutoTableRuleSegment result = new AutoTableRuleSegment(logicTableName, Arrays.asList("ds_0", "ds_1"));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
result.setShardingColumn("order_id");
- result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", createProperties("", "")));
+ result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", PropertiesBuilder.build(new Property("", ""))));
return result;
}
private TableRuleSegment createCompleteTableRule(final String logicTableName) {
TableRuleSegment result = new TableRuleSegment(logicTableName, Collections.singletonList("ds_${0..1}.t_order${0..1}"));
result.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id", new AlgorithmSegment("CORE.STANDARD.FIXTURE", new Properties())));
- AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", createProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}")));
result.setDatabaseStrategySegment(new ShardingStrategySegment("standard", "product_id", databaseAlgorithmSegment));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
return result;
@@ -172,7 +174,7 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createTableRuleConfiguration());
result.getAutoTables().add(createAutoTableRuleConfiguration());
- result.getShardingAlgorithms().put("t_order_algorithm", new AlgorithmConfiguration("hash_mod", createProperties("sharding-count", "4")));
+ result.getShardingAlgorithms().put("t_order_algorithm", new AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new Property("sharding-count", "4"))));
result.getKeyGenerators().put("t_order_item_snowflake", new AlgorithmConfiguration("snowflake", new Properties()));
return result;
}
@@ -190,12 +192,6 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
return result;
}
- private static Properties createProperties(final String key, final String value) {
- Properties result = new Properties();
- result.put(key, value);
- return result;
- }
-
private static Map<String, DataSource> createDataSource() {
Map<String, DataSource> result = new HashMap<>(2, 1);
result.put("ds_0", new MockedDataSource());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java
index 688a34382ac..f8edc67c7c0 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyStatementUpdaterTest.java
@@ -26,6 +26,8 @@ import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.update.CreateDefaultShardingStrategyStatementUpdater;
import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateDefaultShardingStrategyStatement;
+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;
@@ -99,7 +101,7 @@ public final class CreateDefaultShardingStrategyStatementUpdaterTest {
@Test
public void assertCreateDefaultDatabaseShardingStrategy() {
- AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}")));
CreateDefaultShardingStrategyStatement statement = new CreateDefaultShardingStrategyStatement(false, "DATABASE", "standard", "user_id", databaseAlgorithmSegment);
ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration();
updater.checkSQLStatement(database, statement, currentRuleConfig);
@@ -132,13 +134,13 @@ public final class CreateDefaultShardingStrategyStatementUpdaterTest {
@Test
public void assertCreateDefaultDatabaseShardingStrategyWithIfNotExists() {
- AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}")));
CreateDefaultShardingStrategyStatement statement = new CreateDefaultShardingStrategyStatement(false, "DATABASE", "standard", "user_id", databaseAlgorithmSegment);
ShardingRuleConfiguration currentRuleConfig = new ShardingRuleConfiguration();
updater.checkSQLStatement(database, statement, currentRuleConfig);
ShardingRuleConfiguration toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentRuleConfig, statement);
updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig);
- databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${order_id% 2}"));
+ databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${order_id % 2}")));
CreateDefaultShardingStrategyStatement statementWithIfNotExists = new CreateDefaultShardingStrategyStatement(true, "TABLE", "standard", "order_id", databaseAlgorithmSegment);
updater.checkSQLStatement(database, statementWithIfNotExists, currentRuleConfig);
toBeCreatedRuleConfig = updater.buildToBeCreatedRuleConfiguration(currentRuleConfig, statementWithIfNotExists);
@@ -151,10 +153,4 @@ public final class CreateDefaultShardingStrategyStatementUpdaterTest {
private AlgorithmSegment getAutoCreativeAlgorithmSegment(final String name, final Properties props) {
return new AlgorithmSegment(name, props);
}
-
- private static Properties newProperties(final String key, final String value) {
- Properties result = new Properties();
- result.put(key, value);
- return result;
- }
}
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
index d4bfc2d4e44..7d09ca1e9a8 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
@@ -46,6 +46,8 @@ import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
import org.apache.shardingsphere.sql.parser.core.SQLParserFactory;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
+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;
@@ -162,10 +164,10 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
AutoTableRuleSegment autoTableRuleSegment = new AutoTableRuleSegment("t_order_item_input", Collections.singletonList("logic_ds"));
autoTableRuleSegment.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("test_product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
autoTableRuleSegment.setShardingColumn("custom_id");
- autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", createProperties("", "")));
+ autoTableRuleSegment.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", PropertiesBuilder.build(new Property("", ""))));
TableRuleSegment tableRuleSegment = new TableRuleSegment("t_order_input", Collections.singletonList("ds_${0..1}.t_order_${0..5}"));
tableRuleSegment.setTableStrategySegment(new ShardingStrategySegment("standard", "user_id", new AlgorithmSegment("CORE.STANDARD.FIXTURE", new Properties())));
- AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", createProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}")));
tableRuleSegment.setDatabaseStrategySegment(new ShardingStrategySegment("standard", "order_id", databaseAlgorithmSegment));
tableRuleSegment.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("order_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
CreateShardingTableRuleStatement statementWithIfNotExists = new CreateShardingTableRuleStatement(true, Arrays.asList(autoTableRuleSegment, tableRuleSegment));
@@ -210,14 +212,14 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
AutoTableRuleSegment result = new AutoTableRuleSegment("t_order_item_input", Collections.singletonList("logic_ds"));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
result.setShardingColumn("order_id");
- result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", createProperties("", "")));
+ result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", PropertiesBuilder.build(new Property("", ""))));
return result;
}
private TableRuleSegment createCompleteTableRule() {
TableRuleSegment result = new TableRuleSegment("t_order_input", Collections.singletonList("ds_${0..1}.t_order_${0..1}"));
result.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id", new AlgorithmSegment("CORE.STANDARD.FIXTURE", new Properties())));
- AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", createProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${user_id % 2}")));
result.setDatabaseStrategySegment(new ShardingStrategySegment("standard", "product_id", databaseAlgorithmSegment));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
return result;
@@ -227,7 +229,7 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createTableRuleConfiguration());
result.getAutoTables().add(createAutoTableRuleConfiguration());
- result.getShardingAlgorithms().put("t_order_algorithm", new AlgorithmConfiguration("hash_mod", createProperties("sharding-count", "4")));
+ result.getShardingAlgorithms().put("t_order_algorithm", new AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new Property("sharding-count", "4"))));
result.getKeyGenerators().put("t_order_item_snowflake", new AlgorithmConfiguration("snowflake", new Properties()));
return result;
}
@@ -245,12 +247,6 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
return result;
}
- private Properties createProperties(final String key, final String value) {
- Properties result = new Properties();
- result.put(key, value);
- return result;
- }
-
private Map<String, DataSource> createDataSource() {
Map<String, DataSource> result = new HashMap<>(2, 1);
result.put("ds_0", new MockedDataSource());
diff --git a/features/sharding/plugin/cache/pom.xml b/features/sharding/plugin/cache/pom.xml
index 3328f84e730..35f3754ce4c 100644
--- a/features/sharding/plugin/cache/pom.xml
+++ b/features/sharding/plugin/cache/pom.xml
@@ -34,6 +34,12 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-sql-parser-postgresql</artifactId>
diff --git a/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java b/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
index fc613be96c5..03f58215f8f 100644
--- a/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
+++ b/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
@@ -45,6 +45,8 @@ import org.apache.shardingsphere.sharding.cache.rule.ShardingCacheRule;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+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.junit.runners.Parameterized;
@@ -55,7 +57,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Properties;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -126,12 +127,8 @@ public final class ShardingRouteCacheableCheckerTest {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ruleConfig.getBroadcastTables().add("t_broadcast_table");
ruleConfig.getBindingTableGroups().add(new ShardingTableReferenceRuleConfiguration("foo", "t_order,t_order_item"));
- Properties modShardingAlgorithmProps = new Properties();
- modShardingAlgorithmProps.setProperty("sharding-count", "2");
- ruleConfig.getShardingAlgorithms().put("mod", new AlgorithmConfiguration("MOD", modShardingAlgorithmProps));
- Properties inlineShardingAlgorithmProps = new Properties();
- inlineShardingAlgorithmProps.setProperty("algorithm-expression", "ds_${id % 2}");
- ruleConfig.getShardingAlgorithms().put("inline", new AlgorithmConfiguration("INLINE", inlineShardingAlgorithmProps));
+ ruleConfig.getShardingAlgorithms().put("mod", new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "2"))));
+ ruleConfig.getShardingAlgorithms().put("inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${id % 2}"))));
ruleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("warehouse_id", "mod"));
ShardingTableRuleConfiguration warehouse = new ShardingTableRuleConfiguration("t_warehouse", "ds_${0..1}.t_warehouse");
warehouse.setDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("id", "mod"));
diff --git a/features/sharding/plugin/cosid/pom.xml b/features/sharding/plugin/cosid/pom.xml
index 7c144676720..e8be14ccce1 100644
--- a/features/sharding/plugin/cosid/pom.xml
+++ b/features/sharding/plugin/cosid/pom.xml
@@ -38,6 +38,13 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>me.ahoo.cosid</groupId>
<artifactId>cosid-core</artifactId>
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java
index 9ddef2028ff..49b3d485da5 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdKeyGenerateAlgorithmTest.java
@@ -30,6 +30,8 @@ import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Properties;
@@ -47,17 +49,12 @@ public final class CosIdKeyGenerateAlgorithmTest {
String idName = "test-cosid";
DefaultSegmentId defaultSegmentId = new DefaultSegmentId(new IdSegmentDistributor.Mock());
DefaultIdGeneratorProvider.INSTANCE.set(idName, defaultSegmentId);
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", createAsLongProperties(idName)), KeyGenerateAlgorithm.class);
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+ new AlgorithmConfiguration("COSID", PropertiesBuilder.build(new Property(CosIdAlgorithmConstants.ID_NAME_KEY, idName))), KeyGenerateAlgorithm.class);
assertThat(algorithm.generateKey(), is(1L));
assertThat(algorithm.generateKey(), is(2L));
}
- private Properties createAsLongProperties(final String idName) {
- Properties result = new Properties();
- result.setProperty(CosIdAlgorithmConstants.ID_NAME_KEY, idName);
- return result;
- }
-
@Test
public void assertGenerateKeyWhenNotSetIdName() {
DefaultSegmentId defaultSegmentId = new DefaultSegmentId(new IdSegmentDistributor.Mock());
@@ -79,17 +76,11 @@ public final class CosIdKeyGenerateAlgorithmTest {
String prefix = "test_";
IdGenerator idGeneratorDecorator = new StringIdGeneratorDecorator(new MillisecondSnowflakeId(1, 0), new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE));
DefaultIdGeneratorProvider.INSTANCE.set(idName, idGeneratorDecorator);
- KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", createAsStringProperties(idName)), KeyGenerateAlgorithm.class);
+ Properties props = PropertiesBuilder.build(new Property(CosIdAlgorithmConstants.ID_NAME_KEY, idName), new Property("as-string", Boolean.TRUE.toString()));
+ KeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID", props), KeyGenerateAlgorithm.class);
Comparable<?> actual = algorithm.generateKey();
assertThat(actual, instanceOf(String.class));
assertThat(actual.toString(), startsWith(prefix));
assertThat(actual.toString().length(), lessThanOrEqualTo(16));
}
-
- private Properties createAsStringProperties(final String idName) {
- Properties result = new Properties();
- result.setProperty(CosIdAlgorithmConstants.ID_NAME_KEY, idName);
- result.setProperty("as-string", Boolean.TRUE.toString());
- return result;
- }
}
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
index 175e3d61904..b702ebd2e0e 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
@@ -33,6 +33,8 @@ import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.apache.shardingsphere.sharding.cosid.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Properties;
@@ -116,8 +118,7 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
@Test
public void assertGenerateKeyAsString() {
- Properties props = new Properties();
- props.setProperty(CosIdSnowflakeKeyGenerateAlgorithm.AS_STRING_KEY, Boolean.TRUE.toString());
+ Properties props = PropertiesBuilder.build(new Property(CosIdSnowflakeKeyGenerateAlgorithm.AS_STRING_KEY, Boolean.TRUE.toString()));
CosIdSnowflakeKeyGenerateAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_SNOWFLAKE", props), KeyGenerateAlgorithm.class);
algorithm.setInstanceContext(new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)),
new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), new ModeConfiguration("Standalone", null),
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java
index d557cd3497c..f930399d72b 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithmTest.java
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstant
import org.apache.shardingsphere.sharding.cosid.algorithm.keygen.CosIdSnowflakeKeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.fixture.IntervalShardingAlgorithmDataFixture;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+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.junit.runners.Parameterized;
@@ -50,15 +52,16 @@ public final class CosIdSnowflakeIntervalShardingAlgorithmTest {
}
private static Properties createProperties() {
- Properties result = new Properties();
- result.setProperty(CosIdIntervalShardingAlgorithm.ZONE_ID_KEY, "Asia/Shanghai");
- result.setProperty(CosIdAlgorithmConstants.LOGIC_NAME_PREFIX_KEY, IntervalShardingAlgorithmDataFixture.LOGIC_NAME_PREFIX);
- result.setProperty(CosIdIntervalShardingAlgorithm.DATE_TIME_LOWER_KEY, IntervalShardingAlgorithmDataFixture.LOWER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER));
- result.setProperty(CosIdIntervalShardingAlgorithm.DATE_TIME_UPPER_KEY, IntervalShardingAlgorithmDataFixture.UPPER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER));
- result.setProperty(CosIdIntervalShardingAlgorithm.SHARDING_SUFFIX_FORMAT_KEY, IntervalShardingAlgorithmDataFixture.SUFFIX_FORMATTER_STRING);
- result.setProperty(CosIdIntervalShardingAlgorithm.INTERVAL_UNIT_KEY, "MONTHS");
- result.put(CosIdIntervalShardingAlgorithm.INTERVAL_AMOUNT_KEY, 1);
- return result;
+ return PropertiesBuilder.build(
+ new Property(CosIdIntervalShardingAlgorithm.ZONE_ID_KEY, "Asia/Shanghai"),
+ new Property(CosIdAlgorithmConstants.LOGIC_NAME_PREFIX_KEY, IntervalShardingAlgorithmDataFixture.LOGIC_NAME_PREFIX),
+ new Property(CosIdIntervalShardingAlgorithm.DATE_TIME_LOWER_KEY,
+ IntervalShardingAlgorithmDataFixture.LOWER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER)),
+ new Property(CosIdIntervalShardingAlgorithm.DATE_TIME_UPPER_KEY,
+ IntervalShardingAlgorithmDataFixture.UPPER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER)),
+ new Property(CosIdIntervalShardingAlgorithm.SHARDING_SUFFIX_FORMAT_KEY, IntervalShardingAlgorithmDataFixture.SUFFIX_FORMATTER_STRING),
+ new Property(CosIdIntervalShardingAlgorithm.INTERVAL_UNIT_KEY, "MONTHS"),
+ new Property(CosIdIntervalShardingAlgorithm.INTERVAL_AMOUNT_KEY, "1"));
}
@RunWith(Parameterized.class)
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java
index d96417df1d4..84bd4e098ad 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/fixture/IntervalShardingAlgorithmDataFixture.java
@@ -27,6 +27,8 @@ import org.apache.shardingsphere.sharding.cosid.algorithm.Arguments;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
import org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.CosIdIntervalShardingAlgorithm;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
@@ -121,23 +123,19 @@ public final class IntervalShardingAlgorithmDataFixture {
}
/**
- * Create CosIdIntervalShardingAlgorithm.
+ * Create CosId interval sharding algorithm.
*
- * @return CosIdIntervalShardingAlgorithm
+ * @return CosId interval sharding algorithm
*/
public static CosIdIntervalShardingAlgorithm createShardingAlgorithm() {
- return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_INTERVAL", createProperties()), ShardingAlgorithm.class);
- }
-
- private static Properties createProperties() {
- Properties result = new Properties();
- result.setProperty(CosIdIntervalShardingAlgorithm.ZONE_ID_KEY, "Asia/Shanghai");
- result.setProperty(CosIdAlgorithmConstants.LOGIC_NAME_PREFIX_KEY, LOGIC_NAME_PREFIX);
- result.setProperty(CosIdIntervalShardingAlgorithm.DATE_TIME_LOWER_KEY, LOWER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER));
- result.setProperty(CosIdIntervalShardingAlgorithm.DATE_TIME_UPPER_KEY, UPPER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER));
- result.setProperty(CosIdIntervalShardingAlgorithm.SHARDING_SUFFIX_FORMAT_KEY, SUFFIX_FORMATTER_STRING);
- result.setProperty(CosIdIntervalShardingAlgorithm.INTERVAL_UNIT_KEY, "MONTHS");
- result.put(CosIdIntervalShardingAlgorithm.INTERVAL_AMOUNT_KEY, 1);
- return result;
+ Properties props = PropertiesBuilder.build(
+ new Property(CosIdIntervalShardingAlgorithm.ZONE_ID_KEY, "Asia/Shanghai"),
+ new Property(CosIdAlgorithmConstants.LOGIC_NAME_PREFIX_KEY, LOGIC_NAME_PREFIX),
+ new Property(CosIdIntervalShardingAlgorithm.DATE_TIME_LOWER_KEY, LOWER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER)),
+ new Property(CosIdIntervalShardingAlgorithm.DATE_TIME_UPPER_KEY, UPPER_DATE_TIME.format(CosIdIntervalShardingAlgorithm.DEFAULT_DATE_TIME_FORMATTER)),
+ new Property(CosIdIntervalShardingAlgorithm.SHARDING_SUFFIX_FORMAT_KEY, SUFFIX_FORMATTER_STRING),
+ new Property(CosIdIntervalShardingAlgorithm.INTERVAL_UNIT_KEY, "MONTHS"),
+ new Property(CosIdIntervalShardingAlgorithm.INTERVAL_AMOUNT_KEY, "1"));
+ return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_INTERVAL", props), ShardingAlgorithm.class);
}
}
diff --git a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java
index 21fe8bba6b5..53a706a65f6 100644
--- a/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java
+++ b/features/sharding/plugin/cosid/src/test/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/mod/CosIdModShardingAlgorithmTest.java
@@ -28,6 +28,8 @@ import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingVal
import org.apache.shardingsphere.sharding.cosid.algorithm.Arguments;
import org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+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;
@@ -53,14 +55,8 @@ public final class CosIdModShardingAlgorithmTest {
static final ExactCollection<String> ALL_NODES = new ExactCollection<>("t_mod_0", "t_mod_1", "t_mod_2", "t_mod_3");
static CosIdModShardingAlgorithm<Long> createShardingAlgorithm() {
- return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_MOD", createProperties()), ShardingAlgorithm.class);
- }
-
- private static Properties createProperties() {
- Properties result = new Properties();
- result.setProperty(CosIdAlgorithmConstants.LOGIC_NAME_PREFIX_KEY, LOGIC_NAME_PREFIX);
- result.put("mod", DIVISOR);
- return result;
+ Properties props = PropertiesBuilder.build(new Property(CosIdAlgorithmConstants.LOGIC_NAME_PREFIX_KEY, LOGIC_NAME_PREFIX), new Property("mod", Integer.toString(DIVISOR)));
+ return ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("COSID_MOD", props), ShardingAlgorithm.class);
}
@RunWith(Parameterized.class)