From 3164f263d551077038c67e45f5c5002be0713f95 Mon Sep 17 00:00:00 2001 From: galaxylei Date: Wed, 18 May 2022 10:16:41 +0800 Subject: [PATCH 1/3] Add unit test for ModShardingAlgorithm check Argument(#17695) --- .../sharding/mod/ModShardingAlgorithmTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java index 80cffac5de4a7..88de9f1d84639 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java @@ -92,13 +92,21 @@ public void assertRangeDoShardingWithAllTargetsZeroPadding() { } @Test(expected = IllegalArgumentException.class) - public void assertRangeDoShardingWithWrongArgument() { + public void assertRangeDoShardingWithWrongArgumentForStartOffset() { Properties properties = createZeroPaddingProperties(); properties.setProperty("start-offset", "-1"); ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new ShardingSphereAlgorithmConfiguration("MOD", properties)); assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07")); } + @Test(expected = IllegalArgumentException.class) + public void assertRangeDoShardingWithWrongArgumentForStopOffset() { + Properties properties = createZeroPaddingProperties(); + properties.setProperty("stop-offset", "-1"); + ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new ShardingSphereAlgorithmConfiguration("MOD", properties)); + assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07")); + } + private Properties createZeroPaddingProperties() { Properties result = new Properties(); result.setProperty("sharding-count", "16"); From 40f1eb93666e4526f378f6ac307d09c93262ea08 Mon Sep 17 00:00:00 2001 From: galaxylei Date: Thu, 19 May 2022 09:21:15 +0800 Subject: [PATCH 2/3] Fix CI ERROR (#17695) --- .../algorithm/sharding/mod/ModShardingAlgorithmTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java index 88de9f1d84639..bedf878d91c85 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java @@ -102,7 +102,7 @@ public void assertRangeDoShardingWithWrongArgumentForStartOffset() { @Test(expected = IllegalArgumentException.class) public void assertRangeDoShardingWithWrongArgumentForStopOffset() { Properties properties = createZeroPaddingProperties(); - properties.setProperty("stop-offset", "-1"); + properties.setProperty("stop-offset", "-2"); ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new ShardingSphereAlgorithmConfiguration("MOD", properties)); assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07")); } From 0edbcfe133157a03f5a3a0c0eca9eb0f66d9b918 Mon Sep 17 00:00:00 2001 From: galaxylei Date: Thu, 19 May 2022 12:03:37 +0800 Subject: [PATCH 3/3] Fix CI ERROR (#17695) --- .../algorithm/sharding/mod/ModShardingAlgorithmTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java index bedf878d91c85..88de9f1d84639 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithmTest.java @@ -102,7 +102,7 @@ public void assertRangeDoShardingWithWrongArgumentForStartOffset() { @Test(expected = IllegalArgumentException.class) public void assertRangeDoShardingWithWrongArgumentForStopOffset() { Properties properties = createZeroPaddingProperties(); - properties.setProperty("stop-offset", "-2"); + properties.setProperty("stop-offset", "-1"); ModShardingAlgorithm algorithm = (ModShardingAlgorithm) ShardingAlgorithmFactory.newInstance(new ShardingSphereAlgorithmConfiguration("MOD", properties)); assertThat(algorithm.doSharding(createAvailableIncludeZeroTargetNames(), new PreciseShardingValue<>("t_order", "order_id", DATA_NODE_INFO, "12345678910111213141516")), is("t_order_07")); }