You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/04/14 02:15:29 UTC
[shardingsphere] branch master updated: Add more unit test for TableRule. (#16289) (#16767)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 97bf22f04ab Add more unit test for TableRule. (#16289) (#16767)
97bf22f04ab is described below
commit 97bf22f04ab850d87a2fcf9cfb8e03c2ecf935b6
Author: yangsen <73...@users.noreply.github.com>
AuthorDate: Thu Apr 14 10:15:22 2022 +0800
Add more unit test for TableRule. (#16289) (#16767)
* feat:Add class-based-sharding-spring-boot-mybatis-example for class-based-sharding-algorithm-example (#15714)
* Add more unit test for TableRule. (#16289)
* Add more unit test for TableRule. (#16289)
Co-authored-by: yangsen <73...@users.noreply.github.com>
Co-authored-by: sen4.yang <se...@ly.com>
---
.../sharding/rule/TableRuleTest.java | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
index ffacb3c8c57..4833a043733 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
@@ -33,6 +33,10 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Collection;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
@@ -154,4 +158,29 @@ public final class TableRuleTest {
shardingTableRuleConfig.setTableShardingStrategy(new StandardShardingStrategyConfiguration("shardingColumn", "INLINE"));
new TableRule(shardingTableRuleConfig, Arrays.asList("ds0", "ds1"), null);
}
+
+ @Test
+ public void assertDatNodeGroups() {
+ Collection<String> dataSourceNames = new LinkedList<>();
+ String logicTableName = "table_0";
+ dataSourceNames.add("ds0");
+ dataSourceNames.add("ds1");
+ TableRule tableRule = new TableRule(dataSourceNames, logicTableName);
+ Map<String, List<DataNode>> actual = tableRule.getDataNodeGroups();
+ assertThat(actual.size(), is(2));
+ assertTrue(actual.get("ds0").contains(new DataNode("ds0", "table_0")));
+ assertTrue(actual.get("ds1").contains(new DataNode("ds1", "table_0")));
+ }
+
+ @Test
+ public void assertCreateTableRuleWithdataSourceNames() {
+ Collection<String> dataSourceNames = new LinkedList<>();
+ String logicTableName = "table_0";
+ dataSourceNames.add("ds0");
+ dataSourceNames.add("ds1");
+ TableRule actual = new TableRule(dataSourceNames, logicTableName);
+ assertThat(actual.getActualDataNodes().size(), is(2));
+ assertTrue(actual.getActualDataNodes().contains(new DataNode("ds0", "table_0")));
+ assertTrue(actual.getActualDataNodes().contains(new DataNode("ds1", "table_0")));
+ }
}