You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/04/12 10:37:05 UTC
[shardingsphere] branch master updated: Add more unit test for ShardingRule. (#16755)
This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin 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 c3959cf6fee Add more unit test for ShardingRule. (#16755)
c3959cf6fee is described below
commit c3959cf6feef2eb897c1a89899304f50431ff684
Author: 龙台 Long Tai <77...@users.noreply.github.com>
AuthorDate: Tue Apr 12 18:37:00 2022 +0800
Add more unit test for ShardingRule. (#16755)
* Add more unit test for ShardingRule.
* Fix variable naming.
* Fix variable naming.
* Fix ci errors.
---
.../sharding/rule/ShardingRuleTest.java | 48 ++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 5098518993a..d1f9a7b0077 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -745,4 +745,52 @@ public final class ShardingRuleTest {
actual.getLogicAndActualTablesFromBindingTable("ds_0", "LOGIC_TABLE", "table_0", Lists.newArrayList("logic_table", "sub_logic_table"));
assertThat(logicAndActualTablesFromBindingTable.get("sub_logic_table"), is("sub_table_0"));
}
+
+ @Test
+ public void assertGetAllDataNodes() {
+ ShardingRule actual = createMaximumShardingRule();
+ Map<String, Collection<DataNode>> allDataNodes = actual.getAllDataNodes();
+ assertTrue(allDataNodes.containsKey("logic_table"));
+ assertTrue(allDataNodes.containsKey("sub_logic_table"));
+ Collection<DataNode> logicTableDataNodes = allDataNodes.get("logic_table");
+ assertGetDataNodes(logicTableDataNodes, "table_");
+ Collection<DataNode> subLogicTableDataNodes = allDataNodes.get("sub_logic_table");
+ assertGetDataNodes(subLogicTableDataNodes, "sub_table_");
+ }
+
+ private void assertGetDataNodes(final Collection<DataNode> dataNodes, final String tableNamePrefix) {
+ int dataSourceNameSuffix = 0;
+ int tableNameSuffix = 0;
+ Iterator<DataNode> dataNodeIterator = dataNodes.iterator();
+ while (dataNodeIterator.hasNext()) {
+ DataNode dataNode = dataNodeIterator.next();
+ assertThat(dataNode.getDataSourceName(), is("ds_" + dataSourceNameSuffix));
+ assertThat(dataNode.getTableName(), is(tableNamePrefix + tableNameSuffix));
+ if (++tableNameSuffix == (dataNodes.size() / 2)) {
+ tableNameSuffix = 0;
+ dataSourceNameSuffix++;
+ }
+ }
+ }
+
+ @Test
+ public void assertFindFirstActualTable() {
+ ShardingRule actual = createMaximumShardingRule();
+ Optional<String> logicTable = actual.findFirstActualTable("logic_table");
+ assertThat(logicTable.orElse(""), is("table_0"));
+ }
+
+ @Test
+ public void assertIsNeedAccumulate() {
+ ShardingRule actual = createMaximumShardingRule();
+ assertTrue(actual.isNeedAccumulate(Collections.singletonList("table_0")));
+ assertFalse(actual.isNeedAccumulate(Collections.singletonList("BROADCAST_TABLE")));
+ }
+
+ @Test
+ public void assertFindActualTableByCatalog() {
+ ShardingRule actual = createMaximumShardingRule();
+ Optional<String> actualTableByCatalog = actual.findActualTableByCatalog("ds_0", "logic_table");
+ assertThat(actualTableByCatalog.orElse(""), is("table_0"));
+ }
}