This is an automated email from the ASF dual-hosted git repository.

menghaoran 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 bd1ce08  adjust param (#13952)
bd1ce08 is described below

commit bd1ce08f0d070b0541fe4a1b98a1664b6b6ac660
Author: zhaojinchao <[email protected]>
AuthorDate: Tue Dec 7 14:18:55 2021 +0800

    adjust param (#13952)
---
 .../dbdiscovery/rule/DatabaseDiscoveryRule.java        | 18 +++++++++---------
 .../AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java |  2 +-
 .../rule/builder/DatabaseDiscoveryRuleBuilder.java     |  2 +-
 .../route/DatabaseDiscoverySQLRouterTest.java          |  2 +-
 .../dbdiscovery/rule/DatabaseDiscoveryRuleTest.java    |  6 +++---
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 070ac84..e826032 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -62,17 +62,17 @@ public final class DatabaseDiscoveryRule implements 
SchemaRule, DataSourceContai
     @Getter
     private final Map<String, DatabaseDiscoveryDataSourceRule> dataSourceRules;
     
-    public DatabaseDiscoveryRule(final DatabaseDiscoveryRuleConfiguration 
config, final String schemaName, final Map<String, DataSource> dataSourceMap) {
-        this(config.getDataSources(), 
getDiscoveryTypes(config.getDiscoveryTypes()), schemaName, dataSourceMap);
+    public DatabaseDiscoveryRule(final String schemaName, final Map<String, 
DataSource> dataSourceMap, final DatabaseDiscoveryRuleConfiguration config) {
+        this(schemaName, dataSourceMap, config.getDataSources(), 
getDiscoveryTypes(config.getDiscoveryTypes()));
     }
     
-    public DatabaseDiscoveryRule(final 
AlgorithmProvidedDatabaseDiscoveryRuleConfiguration config, final String 
schemaName, final Map<String, DataSource> dataSourceMap) {
-        this(config.getDataSources(), config.getDiscoveryTypes(), schemaName, 
dataSourceMap);
+    public DatabaseDiscoveryRule(final String schemaName, final Map<String, 
DataSource> dataSourceMap, final 
AlgorithmProvidedDatabaseDiscoveryRuleConfiguration config) {
+        this(schemaName, dataSourceMap, config.getDataSources(), 
config.getDiscoveryTypes());
     }
     
-    private DatabaseDiscoveryRule(final 
Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfigs, 
final Map<String, DatabaseDiscoveryType> discoveryTypes,
-                                  final String schemaName, final Map<String, 
DataSource> dataSourceMap) {
-        checkDataSourcesArguments(dataSourceRuleConfigs, dataSourceMap);
+    private DatabaseDiscoveryRule(final String schemaName, final Map<String, 
DataSource> dataSourceMap, final 
Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfigs,
+                                  final Map<String, DatabaseDiscoveryType> 
discoveryTypes) {
+        checkDataSourcesArguments(dataSourceMap, dataSourceRuleConfigs);
         this.discoveryTypes = discoveryTypes;
         dataSourceRules = getDataSourceRules(dataSourceRuleConfigs);
         startMonitor(schemaName, dataSourceMap);
@@ -87,9 +87,9 @@ public final class DatabaseDiscoveryRule implements 
SchemaRule, DataSourceContai
         return result;
     }
     
-    private void checkDataSourcesArguments(final 
Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources, final 
Map<String, DataSource> dataSourceMap) {
-        Preconditions.checkArgument(!dataSources.isEmpty(), "Database 
discovery rules can not be empty.");
+    private void checkDataSourcesArguments(final Map<String, DataSource> 
dataSourceMap, final Collection<DatabaseDiscoveryDataSourceRuleConfiguration> 
dataSources) {
         Preconditions.checkArgument(null != dataSourceMap && 
!dataSourceMap.isEmpty(), "Data sources cannot be empty.");
+        Preconditions.checkArgument(!dataSources.isEmpty(), "Database 
discovery rules can not be empty.");
     }
     
     private Map<String, DatabaseDiscoveryDataSourceRule> 
getDataSourceRules(final 
Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSources) {
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
index 5709aa3..3f30309 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilder.java
@@ -34,7 +34,7 @@ public final class 
AlgorithmProvidedDatabaseDiscoveryRuleBuilder implements Sche
     @Override
     public DatabaseDiscoveryRule build(final SchemaRulesBuilderMaterials 
materials, final AlgorithmProvidedDatabaseDiscoveryRuleConfiguration config,
                                        final Collection<ShardingSphereRule> 
builtRules) {
-        return new DatabaseDiscoveryRule(config, materials.getSchemaName(), 
materials.getDataSourceMap());
+        return new DatabaseDiscoveryRule(materials.getSchemaName(), 
materials.getDataSourceMap(), config);
     }
     
     @Override
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
index 9ec1860..82580ee 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/builder/DatabaseDiscoveryRuleBuilder.java
@@ -43,7 +43,7 @@ public final class DatabaseDiscoveryRuleBuilder implements 
SchemaRuleBuilder<Dat
                 realDataSourceMap.put(datasourceName, 
materials.getDataSourceMap().get(datasourceName));
             }
         }
-        return new DatabaseDiscoveryRule(config, materials.getSchemaName(), 
realDataSourceMap);
+        return new DatabaseDiscoveryRule(materials.getSchemaName(), 
realDataSourceMap, config);
     }
     
     @Override
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
index c46ba1c..492b7ee 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouterTest.java
@@ -78,7 +78,7 @@ public final class DatabaseDiscoverySQLRouterTest {
         ShardingSphereAlgorithmConfiguration algorithmConfig = new 
ShardingSphereAlgorithmConfiguration("TEST", new Properties());
         DatabaseDiscoveryRuleConfiguration config = new 
DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceConfig), 
Collections.emptyMap(),
                 Collections.singletonMap("TEST", algorithmConfig));
-        rule = new DatabaseDiscoveryRule(config, "TEST", 
Collections.singletonMap("ds", mock(DataSource.class)));
+        rule = new DatabaseDiscoveryRule("TEST", 
Collections.singletonMap("ds", mock(DataSource.class)), config);
         sqlRouter = (DatabaseDiscoverySQLRouter) 
OrderedSPIRegistry.getRegisteredServices(SQLRouter.class, 
Collections.singleton(rule)).get(rule);
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
index 1688fbf..f712154 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
@@ -43,7 +43,7 @@ public final class DatabaseDiscoveryRuleTest {
     
     @Test(expected = IllegalArgumentException.class)
     public void assertNewWithEmptyDataSourceRule() {
-        new DatabaseDiscoveryRule(new 
DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), 
Collections.emptyMap(), Collections.emptyMap()), "ha_db", dataSourceMap);
+        new DatabaseDiscoveryRule("ha_db", dataSourceMap, new 
DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), 
Collections.emptyMap(), Collections.emptyMap()));
     }
     
     @Test
@@ -102,7 +102,7 @@ public final class DatabaseDiscoveryRuleTest {
     
     private DatabaseDiscoveryRule createRule() {
         DatabaseDiscoveryDataSourceRuleConfiguration config = new 
DatabaseDiscoveryDataSourceRuleConfiguration("test_pr", Arrays.asList("ds_0", 
"ds_1"), "ha_heartbeat", "TEST");
-        return new DatabaseDiscoveryRule(new 
DatabaseDiscoveryRuleConfiguration(
-                Collections.singleton(config), Collections.emptyMap(), 
ImmutableMap.of("TEST", new ShardingSphereAlgorithmConfiguration("TEST", new 
Properties()))), "ha_db", dataSourceMap);
+        return new DatabaseDiscoveryRule("ha_db", dataSourceMap, new 
DatabaseDiscoveryRuleConfiguration(
+                Collections.singleton(config), Collections.emptyMap(), 
ImmutableMap.of("TEST", new ShardingSphereAlgorithmConfiguration("TEST", new 
Properties()))));
     }
 }

Reply via email to