You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/09 06:14:15 UTC

[shardingsphere] branch master updated: Refactor YamlShardingSphereAlgorithmConfiguration (#9396)

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

panjuan 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 3beb7e5  Refactor YamlShardingSphereAlgorithmConfiguration (#9396)
3beb7e5 is described below

commit 3beb7e55059a6f15fd684ddeb8a6851ef5cc42b2
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Feb 9 14:13:39 2021 +0800

    Refactor YamlShardingSphereAlgorithmConfiguration (#9396)
    
    * Add more assertion for YamlRuleConfigurationSwapperEngineTest
    
    * Rename YamlConfigurationSwapper
    
    * Refactor YamlRuleConfigurationSwapperEngine
    
    * Rename YamlRuleConfigurationSwapperFixture
    
    * Rename RuleConfigurationFixture
    
    * Refactor YamlRuleConfigurationFixture
    
    * Rename YamlPropsRuleConfigurationFixture
    
    * Refactor YamlShardingSphereAlgorithmConfiguration
    
    * Refactor YamlShardingSphereAlgorithmConfiguration
---
 ...eAlgorithmProviderConfigurationYamlSwapper.java |  2 +-
 ...eAlgorithmProviderConfigurationYamlSwapper.java |  2 +-
 ...eAlgorithmProviderConfigurationYamlSwapper.java |  2 +-
 ...eAlgorithmProviderConfigurationYamlSwapper.java |  4 +-
 .../YamlShardingSphereAlgorithmConfiguration.java  | 18 ++------
 ...mlShardingSphereAlgorithmConfigurationTest.java | 53 ----------------------
 6 files changed, 9 insertions(+), 72 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapper.java
index b473375..6c13831 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -41,7 +41,7 @@ public final class EncryptRuleAlgorithmProviderConfigurationYamlSwapper implemen
     public YamlEncryptRuleConfiguration swapToYamlConfiguration(final AlgorithmProvidedEncryptRuleConfiguration data) {
         YamlEncryptRuleConfiguration result = new YamlEncryptRuleConfiguration();
         data.getTables().forEach(each -> result.getTables().put(each.getName(), tableYamlSwapper.swapToYamlConfiguration(each)));
-        data.getEncryptors().forEach((key, value) -> result.getEncryptors().put(key, YamlShardingSphereAlgorithmConfiguration.buildByTypedSPI(value)));
+        data.getEncryptors().forEach((key, value) -> result.getEncryptors().put(key, new YamlShardingSphereAlgorithmConfiguration(value.getType(), value.getProps())));
         return result;
     }
     
diff --git a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
index ff12b31..47095ec 100644
--- a/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-ha/shardingsphere-ha-common/src/main/java/org/apache/shardingsphere/ha/yaml/swapper/HARuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -43,7 +43,7 @@ public final class HARuleAlgorithmProviderConfigurationYamlSwapper
         result.setDataSources(data.getDataSources().stream().collect(
                 Collectors.toMap(HADataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
         if (null != data.getLoadBalanceAlgorithms()) {
-            data.getLoadBalanceAlgorithms().forEach((key, value) -> result.getLoadBalancers().put(key, YamlShardingSphereAlgorithmConfiguration.buildByTypedSPI(value)));
+            data.getLoadBalanceAlgorithms().forEach((key, value) -> result.getLoadBalancers().put(key, new YamlShardingSphereAlgorithmConfiguration(value.getType(), value.getProps())));
         }
         return result;
     }
diff --git a/shardingsphere-features/shardingsphere-replica-query/shardingsphere-replica-query-common/src/main/java/org/apache/shardingsphere/replicaquery/yaml/swapper/ReplicaQueryRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-replica-query/shardingsphere-replica-query-common/src/main/java/org/apache/shardingsphere/replicaquery/yaml/swapper/ReplicaQueryRuleAlgorithmProviderConfigurationYamlSwapper.java
index 05b5af3..9732150 100644
--- a/shardingsphere-features/shardingsphere-replica-query/shardingsphere-replica-query-common/src/main/java/org/apache/shardingsphere/replicaquery/yaml/swapper/ReplicaQueryRuleAlgorithmProviderConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-replica-query/shardingsphere-replica-query-common/src/main/java/org/apache/shardingsphere/replicaquery/yaml/swapper/ReplicaQueryRuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -43,7 +43,7 @@ public final class ReplicaQueryRuleAlgorithmProviderConfigurationYamlSwapper
         result.setDataSources(data.getDataSources().stream().collect(
                 Collectors.toMap(ReplicaQueryDataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
         if (null != data.getLoadBalanceAlgorithms()) {
-            data.getLoadBalanceAlgorithms().forEach((key, value) -> result.getLoadBalancers().put(key, YamlShardingSphereAlgorithmConfiguration.buildByTypedSPI(value)));
+            data.getLoadBalanceAlgorithms().forEach((key, value) -> result.getLoadBalancers().put(key, new YamlShardingSphereAlgorithmConfiguration(value.getType(), value.getProps())));
         }
         return result;
     }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java
index 3f23263..9585ed7 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -116,10 +116,10 @@ public final class ShardingRuleAlgorithmProviderConfigurationYamlSwapper impleme
     
     private void setYamlAlgorithms(final AlgorithmProvidedShardingRuleConfiguration data, final YamlShardingRuleConfiguration yamlConfig) {
         if (null != data.getShardingAlgorithms()) {
-            data.getShardingAlgorithms().forEach((key, value) -> yamlConfig.getShardingAlgorithms().put(key, YamlShardingSphereAlgorithmConfiguration.buildByTypedSPI(value)));
+            data.getShardingAlgorithms().forEach((key, value) -> yamlConfig.getShardingAlgorithms().put(key, new YamlShardingSphereAlgorithmConfiguration(value.getType(), value.getProps())));
         }
         if (null != data.getKeyGenerators()) {
-            data.getKeyGenerators().forEach((key, value) -> yamlConfig.getKeyGenerators().put(key, YamlShardingSphereAlgorithmConfiguration.buildByTypedSPI(value)));
+            data.getKeyGenerators().forEach((key, value) -> yamlConfig.getKeyGenerators().put(key, new YamlShardingSphereAlgorithmConfiguration(value.getType(), value.getProps())));
         }
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/algorithm/YamlShardingSphereAlgorithmConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/algorithm/YamlShardingSphereAlgorithmConfiguration.java
index 477ca36..32ba1df 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/algorithm/YamlShardingSphereAlgorithmConfiguration.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/algorithm/YamlShardingSphereAlgorithmConfiguration.java
@@ -17,9 +17,10 @@
 
 package org.apache.shardingsphere.infra.yaml.config.algorithm;
 
+import lombok.AllArgsConstructor;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import lombok.Setter;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
 import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
 
 import java.util.Properties;
@@ -27,6 +28,8 @@ import java.util.Properties;
 /**
  * ShardingSphere algorithm configuration for YAML.
  */
+@AllArgsConstructor
+@NoArgsConstructor
 @Getter
 @Setter
 public final class YamlShardingSphereAlgorithmConfiguration implements YamlConfiguration {
@@ -34,17 +37,4 @@ public final class YamlShardingSphereAlgorithmConfiguration implements YamlConfi
     private String type;
     
     private Properties props = new Properties();
-    
-    /**
-     * Build by typed SPI.
-     *
-     * @param value typed SPI
-     * @return YAML sharding sphere algorithm configuration
-     */
-    public static YamlShardingSphereAlgorithmConfiguration buildByTypedSPI(final TypedSPI value) {
-        YamlShardingSphereAlgorithmConfiguration result = new YamlShardingSphereAlgorithmConfiguration();
-        result.setType(value.getType());
-        result.setProps(value.getProps());
-        return result;
-    }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/algorithm/YamlShardingSphereAlgorithmConfigurationTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/algorithm/YamlShardingSphereAlgorithmConfigurationTest.java
deleted file mode 100644
index c636d93..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/algorithm/YamlShardingSphereAlgorithmConfigurationTest.java
+++ /dev/null
@@ -1,53 +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.infra.yaml.config.algorithm;
-
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.fixture.TypedSPIFixture;
-import org.apache.shardingsphere.infra.spi.fixture.TypedSPIFixtureImpl;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.Optional;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class YamlShardingSphereAlgorithmConfigurationTest {
-    
-    @Test
-    public void assertBuildByTypedSPI() {
-        ShardingSphereServiceLoader.register(TypedSPIFixture.class);
-        Collection<TypedSPIFixture> spiFixtures = ShardingSphereServiceLoader.newServiceInstances(TypedSPIFixture.class);
-        Optional<TypedSPIFixture> spiOptional = spiFixtures.stream().filter(echo -> echo instanceof TypedSPIFixtureImpl).findFirst();
-        assertTrue(spiOptional.isPresent());
-        TypedSPIFixture typedSPIFixture = spiOptional.get();
-        typedSPIFixture.setProps(createProps());
-        YamlShardingSphereAlgorithmConfiguration actual = YamlShardingSphereAlgorithmConfiguration.buildByTypedSPI(typedSPIFixture);
-        assertThat(actual.getType(), is("FIXTURE"));
-        assertThat(actual.getProps().getProperty("key"), is("value"));
-    }
-    
-    private Properties createProps() {
-        Properties result = new Properties();
-        result.setProperty("key", "value");
-        return result;
-    }
-}