You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/07/23 05:06:32 UTC
[shardingsphere] branch master updated: add test case for ShardingRuleAlgorithmProviderConfigurationYamlSwapper (#19480)
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 9ffb7838f9c add test case for ShardingRuleAlgorithmProviderConfigurationYamlSwapper (#19480)
9ffb7838f9c is described below
commit 9ffb7838f9c2d88cb01c227e289cc749ae0229e2
Author: xuup <33...@users.noreply.github.com>
AuthorDate: Sat Jul 23 13:06:27 2022 +0800
add test case for ShardingRuleAlgorithmProviderConfigurationYamlSwapper (#19480)
---
...orithmProviderConfigurationYamlSwapperTest.java | 93 ++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapperTest.java
new file mode 100644
index 00000000000..5bc93b2dd8c
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapperTest.java
@@ -0,0 +1,93 @@
+
+/*
+ * 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.sharding.yaml.swapper;
+
+import org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapperFactory;
+import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class ShardingRuleAlgorithmProviderConfigurationYamlSwapperTest {
+
+ private AlgorithmProvidedShardingRuleConfiguration ruleConfig;
+
+ @Before
+ public void setUp() {
+ ruleConfig = mock(AlgorithmProvidedShardingRuleConfiguration.class);
+ }
+
+ @Test
+ public void assertSwapToYamlConfiguration() {
+ YamlShardingRuleConfiguration actualResult = getSwapper().swapToYamlConfiguration(createAlgorithmProvidedShardingRuleConfiguration());
+ assertNotNull(actualResult);
+ assertThat(actualResult.getDefaultShardingColumn(), equalTo("foo_column"));
+ assertThat(actualResult.getScalingName(), equalTo("foo_scale_name"));
+ }
+
+ @Test
+ public void assertSwapToObject() {
+ AlgorithmProvidedShardingRuleConfiguration algorithmProvidedShardingRuleConfiguration = getSwapper().swapToObject(createYamlShardingRuleConfiguration());
+ assertThat(algorithmProvidedShardingRuleConfiguration.getDefaultShardingColumn(), equalTo("foo_column"));
+ }
+
+ @Test
+ public void assertGetRuleTagName() {
+ assertThat(getSwapper().getRuleTagName(), equalTo("SHARDING"));
+ }
+
+ private ShardingRuleAlgorithmProviderConfigurationYamlSwapper getSwapper() {
+ return (ShardingRuleAlgorithmProviderConfigurationYamlSwapper) YamlRuleConfigurationSwapperFactory.getInstanceMapByRuleConfigurations(Collections.singletonList(ruleConfig)).get(ruleConfig);
+ }
+
+ private AlgorithmProvidedShardingRuleConfiguration createAlgorithmProvidedShardingRuleConfiguration() {
+ AlgorithmProvidedShardingRuleConfiguration algorithmProvidedShardingRuleConfiguration = new AlgorithmProvidedShardingRuleConfiguration();
+ ShardingTableRuleConfiguration shardingTableRuleConfiguration = new ShardingTableRuleConfiguration("foo_db");
+ algorithmProvidedShardingRuleConfiguration.setTables(Collections.singletonList(shardingTableRuleConfiguration));
+ ShardingAutoTableRuleConfiguration shardingAutoTableRuleConfiguration = new ShardingAutoTableRuleConfiguration("foo_db");
+ algorithmProvidedShardingRuleConfiguration.setAutoTables(Collections.singletonList(shardingAutoTableRuleConfiguration));
+ algorithmProvidedShardingRuleConfiguration.setBindingTableGroups(Collections.singletonList("foo_bind_tb"));
+ algorithmProvidedShardingRuleConfiguration.setDefaultShardingColumn("foo_column");
+ algorithmProvidedShardingRuleConfiguration.setScalingName("foo_scale_name");
+ return algorithmProvidedShardingRuleConfiguration;
+ }
+
+ private YamlShardingRuleConfiguration createYamlShardingRuleConfiguration() {
+ YamlShardingRuleConfiguration yamlShardingRuleConfiguration = new YamlShardingRuleConfiguration();
+ Map<String, YamlTableRuleConfiguration> yamlTableRuleConfigurationMap = new HashMap<>();
+ YamlTableRuleConfiguration yamlTableRuleConfiguration = new YamlTableRuleConfiguration();
+ yamlTableRuleConfiguration.setLogicTable("foo_tbl");
+ yamlTableRuleConfigurationMap.put("foo_key", yamlTableRuleConfiguration);
+ yamlShardingRuleConfiguration.setTables(yamlTableRuleConfigurationMap);
+ yamlShardingRuleConfiguration.setDefaultShardingColumn("foo_column");
+ return yamlShardingRuleConfiguration;
+ }
+}