Skip to content

Commit

Permalink
ADD RDL unit test for springBoot (#7672)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaZero committed Sep 30, 2020
1 parent 14b0662 commit 848a483
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.junit.Test;
Expand Down Expand Up @@ -83,6 +84,7 @@ public void assertShardingConfiguration() {

private void assertShardingConfigurationTables() {
assertThat(shardingRuleConfiguration.getTables().size(), is(2));
assertThat(shardingRuleConfiguration.getAutoTables().size(), is(1));
List<ShardingTableRuleConfiguration> shardingTableRuleConfigurationList = Lists.newArrayList(shardingRuleConfiguration.getTables());
assertThat(shardingTableRuleConfigurationList.get(0).getLogicTable(), is("t_order"));
assertThat(shardingTableRuleConfigurationList.get(0).getActualDataNodes(), is("ds_$->{0..1}.t_order_$->{0..1}"));
Expand All @@ -98,6 +100,12 @@ private void assertShardingConfigurationTables() {
assertThat(shardingTableRuleConfigurationList.get(1).getTableShardingStrategy().getShardingAlgorithmName(), is("orderItemTableShardingAlgorithm"));
assertThat(shardingTableRuleConfigurationList.get(1).getKeyGenerateStrategy().getColumn(), is("order_item_id"));
assertThat(shardingTableRuleConfigurationList.get(1).getKeyGenerateStrategy().getKeyGeneratorName(), is("keyGenerator"));
List<ShardingAutoTableRuleConfiguration> autoShardingTableRuleConfigurationList = Lists.newArrayList(shardingRuleConfiguration.getAutoTables());
assertThat(autoShardingTableRuleConfigurationList.get(0).getLogicTable(), is("t_order_auto"));
assertThat(autoShardingTableRuleConfigurationList.get(0).getActualDataSources(), is("ds0, ds1"));
assertThat(autoShardingTableRuleConfigurationList.get(0).getShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(((StandardShardingStrategyConfiguration) autoShardingTableRuleConfigurationList.get(0).getShardingStrategy()).getShardingColumn(), is("order_id"));
assertThat(autoShardingTableRuleConfigurationList.get(0).getShardingStrategy().getShardingAlgorithmName(), is("mod"));
}

private void assertShardingConfigurationBindingTableGroups() {
Expand Down
Expand Up @@ -46,5 +46,11 @@ spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard
spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=keyGenerator

spring.shardingsphere.rules.sharding.auto-tables.t_order_auto.actual-data-sources=ds0, ds1

spring.shardingsphere.rules.sharding.auto-tables.t_order_auto.sharding-strategy.standard.sharding-column=order_id
spring.shardingsphere.rules.sharding.auto-tables.t_order_auto.sharding-strategy.standard.sharding-algorithm-name=mod


spring.shardingsphere.rules.sharding.binding-tables=t_order,t_order_item
spring.shardingsphere.rules.sharding.broadcast-tables=t_config

0 comments on commit 848a483

Please sign in to comment.