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

zhangliang 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 3b1da41  Refactor YamlProxyConfigurationSwapperTest (#15085)
3b1da41 is described below

commit 3b1da414ba2b4fa949ee5bf6516c044f8178e6bf
Author: liguoping <[email protected]>
AuthorDate: Wed Jan 26 20:03:34 2022 +0800

    Refactor YamlProxyConfigurationSwapperTest (#15085)
    
    * Refactor YamlProxyConfigurationSwapperTest
    
    * add blank line
    
    * remove blank line
---
 .../swapper/YamlProxyConfigurationSwapperTest.java | 75 ++--------------------
 .../conf/swap/config-readwrite-splitting.yaml      | 46 +++++++++++++
 .../src/test/resources/conf/swap/server.yaml       | 40 ++++++++++++
 3 files changed, 90 insertions(+), 71 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
index 0c90641..16c7484 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
@@ -19,25 +19,20 @@ package org.apache.shardingsphere.proxy.config.yaml.swapper;
 
 import com.zaxxer.hikari.HikariDataSource;
 import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
-import 
org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import 
org.apache.shardingsphere.infra.config.schema.impl.DataSourceGeneratedSchemaConfiguration;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
-import 
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
+import org.apache.shardingsphere.proxy.config.ProxyConfigurationLoader;
 import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
-import 
org.apache.shardingsphere.proxy.config.yaml.YamlProxyDataSourceConfiguration;
-import 
org.apache.shardingsphere.proxy.config.yaml.YamlProxySchemaConfiguration;
-import 
org.apache.shardingsphere.proxy.config.yaml.YamlProxyServerConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import 
org.apache.shardingsphere.readwritesplitting.yaml.config.YamlReadwriteSplittingRuleConfiguration;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
@@ -46,14 +41,12 @@ import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public final class YamlProxyConfigurationSwapperTest {
     
     @Test
-    public void assertSwap() {
-        YamlProxyConfiguration yamlProxyConfig = mockYamlProxyConfiguration();
+    public void assertSwap() throws IOException {
+        YamlProxyConfiguration yamlProxyConfig = 
ProxyConfigurationLoader.load("/conf/swap");
         ProxyConfiguration proxyConfig = new 
YamlProxyConfigurationSwapper().swap(yamlProxyConfig);
         assertAuthority(proxyConfig);
         assertProxyConfigurationProps(proxyConfig);
@@ -106,64 +99,4 @@ public final class YamlProxyConfigurationSwapperTest {
         }
         return Collections.emptyList();
     }
-    
-    private YamlProxyConfiguration mockYamlProxyConfiguration() {
-        YamlProxyConfiguration result = mock(YamlProxyConfiguration.class);
-        YamlProxyServerConfiguration yamlProxyServerConfig = 
getYamlProxyServerConfiguration(result);
-        mockAuthentication(yamlProxyServerConfig);
-        mockProps(yamlProxyServerConfig);
-        YamlProxySchemaConfiguration yamlProxySchemaConfig = 
mockSchemaConfigurations(result);
-        mockDataSourceConfiguration(yamlProxySchemaConfig);
-        
when(yamlProxySchemaConfig.getRules()).thenReturn(Collections.singletonList(new 
YamlReadwriteSplittingRuleConfiguration()));
-        return result;
-    }
-    
-    private void mockProps(final YamlProxyServerConfiguration 
yamlProxyServerConfig) {
-        Properties props = new Properties();
-        props.setProperty("key4", "value4");
-        when(yamlProxyServerConfig.getProps()).thenReturn(props);
-    }
-    
-    private YamlProxySchemaConfiguration mockSchemaConfigurations(final 
YamlProxyConfiguration yamlProxyConfig) {
-        Map<String, YamlProxySchemaConfiguration> yamlSchemaConfigs = new 
HashMap<>(1, 1);
-        
when(yamlProxyConfig.getSchemaConfigurations()).thenReturn(yamlSchemaConfigs);
-        YamlProxySchemaConfiguration result = 
mock(YamlProxySchemaConfiguration.class);
-        yamlSchemaConfigs.put("yamlProxyRule1", result);
-        return result;
-    }
-    
-    private void mockDataSourceConfiguration(final 
YamlProxySchemaConfiguration yamlProxySchemaConfig) {
-        YamlProxyDataSourceConfiguration yamlDataSourceConfig = new 
YamlProxyDataSourceConfiguration();
-        yamlDataSourceConfig.setUrl("jdbc:h2:mem:foo_db;DB_CLOSE_DELAY=-1");
-        yamlDataSourceConfig.setUsername("sa");
-        yamlDataSourceConfig.setPassword("");
-        yamlDataSourceConfig.setConnectionTimeoutMilliseconds(250L);
-        yamlDataSourceConfig.setIdleTimeoutMilliseconds(2L);
-        yamlDataSourceConfig.setMaxLifetimeMilliseconds(3L);
-        yamlDataSourceConfig.setMaxPoolSize(4);
-        yamlDataSourceConfig.setMinPoolSize(5);
-        yamlDataSourceConfig.setReadOnly(true);
-        Map<String, YamlProxyDataSourceConfiguration> yamlDataSources = new 
HashMap<>(1, 1);
-        yamlDataSources.put("foo_db", yamlDataSourceConfig);
-        
when(yamlProxySchemaConfig.getDataSources()).thenReturn(yamlDataSources);
-    }
-    
-    private void mockAuthentication(final YamlProxyServerConfiguration 
yamlProxyServerConfig) {
-        YamlAuthorityRuleConfiguration yamlAuthorityRuleConfig = new 
YamlAuthorityRuleConfiguration();
-        yamlAuthorityRuleConfig.setUsers(getUsers());
-        YamlShardingSphereAlgorithmConfiguration provider = new 
YamlShardingSphereAlgorithmConfiguration();
-        provider.setType("test");
-        yamlAuthorityRuleConfig.setProvider(provider);
-        
when(yamlProxyServerConfig.getRules()).thenReturn(Collections.singletonList(yamlAuthorityRuleConfig));
-    }
-    
-    private Collection<String> getUsers() {
-        return Collections.singleton("user1@:pass");
-    }
-    
-    private YamlProxyServerConfiguration getYamlProxyServerConfiguration(final 
YamlProxyConfiguration yamlProxyConfig) {
-        YamlProxyServerConfiguration result = 
mock(YamlProxyServerConfiguration.class);
-        when(yamlProxyConfig.getServerConfiguration()).thenReturn(result);
-        return result;
-    }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/swap/config-readwrite-splitting.yaml
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/swap/config-readwrite-splitting.yaml
new file mode 100644
index 0000000..f04ace9
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/swap/config-readwrite-splitting.yaml
@@ -0,0 +1,46 @@
+#
+# 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.
+#
+
+schemaName: yamlProxyRule1
+
+dataSources:
+  foo_db:
+    url: jdbc:h2:mem:foo_db;DB_CLOSE_DELAY=-1
+    username: sa
+    password: ""
+    connectionTimeoutMilliseconds: 250
+    idleTimeoutMilliseconds: 2
+    maxLifetimeMilliseconds: 3
+    maxPoolSize:  4
+    minPoolSize: 5
+    readOnly: true
+
+rules:
+- !READWRITE_SPLITTING
+  dataSources:
+    pr_ds:
+      type: Static
+      props:
+        write-data-source-name: foo_db
+        read-data-source-names: foo_db
+        
+  loadBalancers: 
+    round_robin:
+      type: ROUND_ROBIN
+      props:
+        key1: value1
+    
\ No newline at end of file
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/swap/server.yaml
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/swap/server.yaml
new file mode 100644
index 0000000..032b6e2
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/swap/server.yaml
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+
+mode:
+  type: Cluster
+  repository:
+    type: GOV_FIXTURE
+    props:
+      namespace: governance_ds
+      server-lists: localhost:2181
+      retryIntervalMilliseconds: 500
+      timeToLiveSeconds: 60
+      maxRetries: 3
+      operationTimeoutMilliseconds: 500
+  overwrite: false
+
+rules:
+  - !AUTHORITY
+    users:
+      - user1@:pass
+    provider:
+      type: test
+
+props:
+  key4: value4
+ 
\ No newline at end of file

Reply via email to