You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/11/16 03:36:58 UTC

[GitHub] [shardingsphere] tristaZero commented on a change in pull request #8141: Use mock to instead of TestShardingRule and TestTableRule in DataNodesTest class

tristaZero commented on a change in pull request #8141:
URL: https://github.com/apache/shardingsphere/pull/8141#discussion_r523883266



##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/DataNodesTest.java
##########
@@ -79,18 +77,19 @@ public void assertGetDataNodeGroups() {
     }
     
     private DataNodes getRoutedRuleDataNodes() {
-        TestTableRule tableRule1 = new TestTableRule(dataSourceNames1, logicTableName1);
-        TestTableRule tableRule2 = new TestTableRule(dataSourceNames2, logicTableName2);
-        List<TestTableRule> tableRules = Arrays.asList(tableRule1, tableRule2);
-        ShardingSphereRule rule1 = new TestShardingRule(tableRules);
+        Map<String, Collection<DataNode>> nodeMap = new HashMap<>();
+        nodeMap.put(logicTableName1, getExpectedDataNodes(dataSourceNames1, logicTableName1));
+        nodeMap.put(logicTableName2, getExpectedDataNodes(dataSourceNames2, logicTableName2));
+        DataNodeContainedRule rule1 = mock(DataNodeContainedRule.class);
+        when(rule1.getAllDataNodes()).thenReturn(nodeMap);
         Map<String, Collection<String>> dataSourceMapper = Collections.singletonMap(logicDataSourceName, replicaDataSourceNames);
         DataSourceContainedRule rule2 = mock(DataSourceContainedRule.class);
         when(rule2.getDataSourceMapper()).thenReturn(dataSourceMapper);
         return new DataNodes(Arrays.asList(rule1, rule2));
     }
     
     private DataNodes getNonRoutedRuleDataNodes() {
-        return new DataNodes(Collections.singleton(new TestShardingSphereRule()));

Review comment:
       Hi @wenweibin 
   Do you think `TestShardingSphereRule` is no longer needed? If so, please delete them. Thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org