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/06/12 14:25:06 UTC

[shardingsphere] branch master updated: Remove useless ReadwriteSplittingRuleExportableFixture (#18318)

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 98d93375c86 Remove useless ReadwriteSplittingRuleExportableFixture (#18318)
98d93375c86 is described below

commit 98d93375c8635f6179ab493b739c8aa35e0b61e1
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Jun 12 22:25:00 2022 +0800

    Remove useless ReadwriteSplittingRuleExportableFixture (#18318)
---
 .../ReadwriteSplittingRuleExportableFixture.java   | 58 -------------------
 ...pDatabaseDiscoveryRuleStatementUpdaterTest.java | 31 ++++++++++-
 .../ReadwriteSplittingRuleExportableFixture.java   | 65 ----------------------
 .../ReadwriteSplittingRuleQueryResultSetTest.java  | 40 ++++++++++++-
 4 files changed, 67 insertions(+), 127 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/ReadwriteSplittingRuleExportableFixture.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/ReadwriteSplittin [...]
deleted file mode 100644
index 27a53541d42..00000000000
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/ReadwriteSplittingRuleExportableFixture.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.dbdiscovery.distsql.handler.fixture;
-
-import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.distsql.constant.ExportableItemConstants;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public final class ReadwriteSplittingRuleExportableFixture implements ExportableRule {
-    
-    @Override
-    public String getType() {
-        return null;
-    }
-    
-    @Override
-    public Map<String, Object> getExportData() {
-        Map<String, Object> result = new HashMap<>(4, 1);
-        result.put(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE, exportDynamicDataSources());
-        result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
-        return result;
-    }
-    
-    private Map<String, Map<String, String>> exportDynamicDataSources() {
-        Map<String, String> dynamicRule = new LinkedHashMap<>(3, 1);
-        dynamicRule.put(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME, "ha_group");
-        dynamicRule.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "ds_0");
-        dynamicRule.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "ds_1,ds_2");
-        return Collections.singletonMap("dynamic_rule_1", dynamicRule);
-    }
-    
-    private Map<String, Map<String, String>> exportStaticDataSources() {
-        Map<String, String> staticRule = new LinkedHashMap<>(2, 1);
-        staticRule.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "ds_0");
-        staticRule.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "ds_1");
-        return Collections.singletonMap("static_rule_1", staticRule);
-    }
-}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseD [...]
index b9ccdc4221a..7acf540c78f 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -19,9 +19,10 @@ package org.apache.shardingsphere.dbdiscovery.distsql.handler.update;
 
 import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
 import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.handler.fixture.ReadwriteSplittingRuleExportableFixture;
 import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryRuleStatement;
 import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
+import org.apache.shardingsphere.infra.distsql.constant.ExportableItemConstants;
 import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
 import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
 import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException;
@@ -33,6 +34,8 @@ import org.junit.Test;
 
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Properties;
@@ -70,12 +73,36 @@ public final class DropDatabaseDiscoveryRuleStatementUpdaterTest {
     @Test(expected = RuleInUsedException.class)
     public void assertCheckSQLStatementWithRuleInUsed() throws DistSQLException {
         when(database.getRuleMetaData()).thenReturn(mock(ShardingSphereRuleMetaData.class, RETURNS_DEEP_STUBS));
-        when(database.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singleton(new ReadwriteSplittingRuleExportableFixture()));
+        ExportableRule exportableRule = mock(ExportableRule.class);
+        when(exportableRule.getExportData()).thenReturn(getExportData());
+        when(database.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singleton(exportableRule));
         DatabaseDiscoveryDataSourceRuleConfiguration configuration = new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group", null, null, null);
         updater.checkSQLStatement(database, createSQLStatement(),
                 new DatabaseDiscoveryRuleConfiguration(Collections.singletonList(configuration), Collections.emptyMap(), Collections.emptyMap()));
     }
     
+    private Map<String, Object> getExportData() {
+        Map<String, Object> result = new HashMap<>(2, 1);
+        result.put(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE, exportDynamicDataSources());
+        result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
+        return result;
+    }
+    
+    private Map<String, Map<String, String>> exportDynamicDataSources() {
+        Map<String, String> result = new LinkedHashMap<>(3, 1);
+        result.put(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME, "ha_group");
+        result.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
+        result.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "read_ds_0, read_ds_1");
+        return Collections.singletonMap("dynamic_rule", result);
+    }
+    
+    private Map<String, Map<String, String>> exportStaticDataSources() {
+        Map<String, String> result = new LinkedHashMap<>(2, 1);
+        result.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
+        result.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "read_ds");
+        return Collections.singletonMap("static_rule", result);
+    }
+    
     @Test
     public void assertUpdateCurrentRuleConfiguration() {
         DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfig = createCurrentRuleConfiguration();
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/fixture/ReadwriteSplittingRuleExportableFixture.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/read [...]
deleted file mode 100644
index fa4dc193fd5..00000000000
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/fixture/ReadwriteSplittingRuleExportableFixture.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.readwritesplitting.distsql.handler.fixture;
-
-import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
-import org.apache.shardingsphere.infra.distsql.constant.ExportableItemConstants;
-import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public final class ReadwriteSplittingRuleExportableFixture implements ExportableRule {
-    
-    @Override
-    public String getType() {
-        return null;
-    }
-    
-    @Override
-    public Map<String, Object> getExportData() {
-        Map<String, Object> result = new HashMap<>(4, 1);
-        result.put(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE, exportDynamicDataSources());
-        result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
-        return result;
-    }
-    
-    private Map<String, Map<String, String>> exportDynamicDataSources() {
-        Map<String, Map<String, String>> result = new HashMap<>(1, 1);
-        result.put("readwrite_ds", getAutoAwareDataSources());
-        return result;
-    }
-    
-    private Map<String, String> getAutoAwareDataSources() {
-        Map<String, String> result = new HashMap<>(3, 1);
-        result.put(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME, "ha_group");
-        result.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
-        result.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "read_ds_0,read_ds_1");
-        return result;
-    }
-    
-    private Map<String, Map<String, String>> exportStaticDataSources() {
-        Map<String, Map<String, String>> result = new LinkedHashMap<>();
-        Map<String, String> staticRule = new LinkedHashMap<>(2, 1);
-        staticRule.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "ds_0");
-        staticRule.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "ds_1");
-        result.put("static_rule_1", staticRule);
-        return result;
-    }
-}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readw [...]
index 0acdc5854b7..d767bc85166 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java
@@ -19,16 +19,20 @@ package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
 
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
+import org.apache.shardingsphere.infra.distsql.constant.ExportableItemConstants;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule;
 import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
 import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.distsql.handler.fixture.ReadwriteSplittingRuleExportableFixture;
 import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingRulesStatement;
 import org.junit.Test;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -95,7 +99,9 @@ public final class ReadwriteSplittingRuleQueryResultSetTest {
     @Test
     public void assertGetRowDataWithAutoAwareDataSource() {
         ShardingSphereDatabase metaData = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(metaData.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singletonList(new ReadwriteSplittingRuleExportableFixture()));
+        ExportableRule exportableRule = mock(ExportableRule.class);
+        when(exportableRule.getExportData()).thenReturn(getExportData());
+        when(metaData.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singleton(exportableRule));
         when(metaData.getRuleMetaData().findRuleConfigurations(any())).thenReturn(Collections.singleton(createRuleConfigurationWithAutoAwareDataSource()));
         ReadwriteSplittingRuleQueryResultSet resultSet = new ReadwriteSplittingRuleQueryResultSet();
         resultSet.init(metaData, mock(ShowReadwriteSplittingRulesStatement.class));
@@ -107,6 +113,36 @@ public final class ReadwriteSplittingRuleQueryResultSetTest {
         assertTrue(actual.contains("read_ds_0,read_ds_1"));
     }
     
+    private Map<String, Object> getExportData() {
+        Map<String, Object> result = new HashMap<>(2, 1);
+        result.put(ExportableConstants.EXPORT_DYNAMIC_READWRITE_SPLITTING_RULE, exportDynamicDataSources());
+        result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, exportStaticDataSources());
+        return result;
+    }
+    
+    private Map<String, Map<String, String>> exportDynamicDataSources() {
+        Map<String, Map<String, String>> result = new HashMap<>(1, 1);
+        result.put("readwrite_ds", getAutoAwareDataSources());
+        return result;
+    }
+    
+    private Map<String, String> getAutoAwareDataSources() {
+        Map<String, String> result = new HashMap<>(3, 1);
+        result.put(ExportableItemConstants.AUTO_AWARE_DATA_SOURCE_NAME, "ha_group");
+        result.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
+        result.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "read_ds_0,read_ds_1");
+        return result;
+    }
+    
+    private Map<String, Map<String, String>> exportStaticDataSources() {
+        Map<String, Map<String, String>> result = new LinkedHashMap<>();
+        Map<String, String> staticRule = new LinkedHashMap<>(2, 1);
+        staticRule.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, "ds_0");
+        staticRule.put(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES, "ds_1");
+        result.put("static_rule_1", staticRule);
+        return result;
+    }
+    
     private RuleConfiguration createRuleConfigurationWithAutoAwareDataSource() {
         Properties props = new Properties();
         props.setProperty("auto-aware-data-source-name", "rd_rs");