Skip to content

Commit

Permalink
Add unit test for ModShardingAlgorithm check Argument(#17695) (#17772)
Browse files Browse the repository at this point in the history
* Add unit test for ModShardingAlgorithm check Argument(#17695)

* Fix CI ERROR (#17695)

* Fix CI ERROR (#17695)
  • Loading branch information
galaxylqx authored May 19, 2022
1 parent a0eac34 commit a393962
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a393962

Please sign in to comment.