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 7eabd57  Meet distSQL requirements. Remove check (#14225)
7eabd57 is described below

commit 7eabd576570881ea10e182b2e89094410369bc75
Author: zhaojinchao <[email protected]>
AuthorDate: Wed Dec 22 20:05:31 2021 +0800

    Meet distSQL requirements. Remove check (#14225)
    
    * remove check
    
    * fixed unit test
---
 .../dbdiscovery/rule/DatabaseDiscoveryRule.java         | 17 -----------------
 .../dbdiscovery/rule/DatabaseDiscoveryRuleTest.java     |  2 +-
 ...gorithmProvidedDatabaseDiscoveryRuleBuilderTest.java |  6 +++++-
 3 files changed, 6 insertions(+), 19 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 53a6f43..adb948d 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
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.dbdiscovery.rule;
 
-import com.google.common.base.Preconditions;
 import lombok.Getter;
 import 
org.apache.shardingsphere.dbdiscovery.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
@@ -79,7 +78,6 @@ public final class DatabaseDiscoveryRule implements 
SchemaRule, DataSourceContai
     
     private DatabaseDiscoveryRule(final String schemaName, final Map<String, 
DataSource> dataSourceMap, final 
Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfigs,
                                   final Map<String, 
DatabaseDiscoveryHeartBeatConfiguration> heartBeatConfig, final Map<String, 
DatabaseDiscoveryType> discoveryTypes) {
-        checkDataSourcesArguments(dataSourceMap, dataSourceRuleConfigs);
         this.discoveryTypes = discoveryTypes;
         dataSourceRules = getDataSourceRules(dataSourceRuleConfigs, 
heartBeatConfig);
         findMasterSlaveRelation(schemaName, dataSourceMap);
@@ -94,30 +92,15 @@ public final class DatabaseDiscoveryRule implements 
SchemaRule, DataSourceContai
         return result;
     }
     
-    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,
                                                                             
final Map<String, DatabaseDiscoveryHeartBeatConfiguration> heartbeatConfig) {
         Map<String, DatabaseDiscoveryDataSourceRule> result = new 
HashMap<>(dataSources.size(), 1);
         for (DatabaseDiscoveryDataSourceRuleConfiguration each : dataSources) {
-            checkDatabaseDiscoveryDataSourceRuleConfigurationArguments(each, 
heartbeatConfig);
             result.put(each.getName(), new 
DatabaseDiscoveryDataSourceRule(each, 
heartbeatConfig.get(each.getDiscoveryHeartbeatName()).getProps(), 
discoveryTypes.get(each.getDiscoveryTypeName())));
         }
         return result;
     }
     
-    private void 
checkDatabaseDiscoveryDataSourceRuleConfigurationArguments(final 
DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig,
-                                                                            
final Map<String, DatabaseDiscoveryHeartBeatConfiguration> heartbeatConfig) {
-        
Preconditions.checkNotNull(dataSourceRuleConfig.getDiscoveryHeartbeatName(), 
"Discovery heartbeat cannot be null of rule name `%s`.", 
dataSourceRuleConfig.getName());
-        
Preconditions.checkArgument(heartbeatConfig.containsKey(dataSourceRuleConfig.getDiscoveryHeartbeatName()),
-                "Can not find discovery heartbeat of rule name `%s`.", 
dataSourceRuleConfig.getName());
-        
Preconditions.checkNotNull(dataSourceRuleConfig.getDiscoveryTypeName(), 
"Discovery type cannot be null of rule name `%s`.", 
dataSourceRuleConfig.getName());
-        
Preconditions.checkArgument(discoveryTypes.containsKey(dataSourceRuleConfig.getDiscoveryTypeName()),
 "Can not find discovery type of rule name `%s`.", 
dataSourceRuleConfig.getName());
-    }
-    
     private void findMasterSlaveRelation(final String schemaName, final 
Map<String, DataSource> dataSourceMap) {
         for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : 
dataSourceRules.entrySet()) {
             String groupName = entry.getKey();
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 b6c4646..942797d 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
@@ -42,7 +42,7 @@ public final class DatabaseDiscoveryRuleTest {
     
     private final Map<String, DataSource> dataSourceMap = 
Collections.singletonMap("ds", mock(DataSource.class));
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void assertNewWithEmptyDataSourceRule() {
         new DatabaseDiscoveryRule("ha_db", dataSourceMap, new 
DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), 
Collections.emptyMap(), Collections.emptyMap()));
     }
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
index 2ca699b..f8dd2f4 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/builder/AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest.java
@@ -19,6 +19,8 @@ package org.apache.shardingsphere.dbdiscovery.rule.builder;
 
 import 
org.apache.shardingsphere.dbdiscovery.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
 import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
+import org.apache.shardingsphere.dbdiscovery.fixture.TestDatabaseDiscoveryType;
 import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
 import 
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -43,11 +45,13 @@ public final class 
AlgorithmProvidedDatabaseDiscoveryRuleBuilderTest {
     }
     
     @SuppressWarnings({"rawtypes", "unchecked"})
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void assertBuild() {
         AlgorithmProvidedDatabaseDiscoveryRuleConfiguration 
algorithmProvidedRuleConfig = 
mock(AlgorithmProvidedDatabaseDiscoveryRuleConfiguration.class);
         DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = new 
DatabaseDiscoveryDataSourceRuleConfiguration("name", 
Collections.singletonList("name"), "ha_heartbeat", "discoveryTypeName");
         
when(algorithmProvidedRuleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfig));
+        
when(algorithmProvidedRuleConfig.getDiscoveryHeartbeats()).thenReturn(Collections.singletonMap("ha_heartbeat",
 new DatabaseDiscoveryHeartBeatConfiguration(new Properties())));
+        
when(algorithmProvidedRuleConfig.getDiscoveryTypes()).thenReturn(Collections.singletonMap("discoveryTypeName",
 new TestDatabaseDiscoveryType()));
         SchemaRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(
                 SchemaRuleBuilder.class, 
Collections.singletonList(algorithmProvidedRuleConfig)).get(algorithmProvidedRuleConfig);
         assertThat(builder.build(new SchemaRulesBuilderMaterials("", 
Collections.emptyList(), mock(DatabaseType.class),

Reply via email to