Skip to content

Commit

Permalink
Add unit test for ModShardingAlgorithm check Argument(apache#17695)
Browse files Browse the repository at this point in the history
  • Loading branch information
galaxylqx committed May 18, 2022
1 parent ae0ec0d commit 3164f26
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 3164f26

Please sign in to comment.