You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/07/06 02:32:33 UTC
[shardingsphere] branch master updated: Add missing swap logic for auditor to avoid startup exception (#18880)
This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin 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 3e94cceb23c Add missing swap logic for auditor to avoid startup exception (#18880)
3e94cceb23c is described below
commit 3e94cceb23ce5835b7891ad094d7f42ffffc1b17
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Wed Jul 6 10:32:26 2022 +0800
Add missing swap logic for auditor to avoid startup exception (#18880)
---
.../yaml/swapper/ShardingRuleConfigurationYamlSwapper.java | 3 +++
.../sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java | 7 +++++++
2 files changed, 10 insertions(+)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java
index ae4f9ae2840..49d046a6de9 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java
@@ -88,6 +88,9 @@ public final class ShardingRuleConfigurationYamlSwapper implements YamlRuleConfi
if (null != data.getKeyGenerators()) {
data.getKeyGenerators().forEach((key, value) -> yamlConfig.getKeyGenerators().put(key, algorithmSwapper.swapToYamlConfiguration(value)));
}
+ if (null != data.getAuditors()) {
+ data.getAuditors().forEach((key, value) -> yamlConfig.getAuditors().put(key, algorithmSwapper.swapToYamlConfiguration(value)));
+ }
if (null != data.getScaling()) {
data.getScaling().forEach((key, value) -> yamlConfig.getScaling().put(key, onRuleAlteredActionYamlSwapper.swapToYamlConfiguration(value)));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
index 67ff0e399e0..f3d3e56674e 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.swapper;
+import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.yaml.config.swapper.YamlConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -161,6 +162,9 @@ public final class ShardingRuleConfigurationYamlSwapperTest {
yamlConfig.setDefaultKeyGenerateStrategy(mock(YamlKeyGenerateStrategyConfiguration.class));
yamlConfig.setAuditStrategy(mock(YamlShardingAuditStrategyConfiguration.class));
yamlConfig.setDefaultShardingColumn("user_id");
+ YamlShardingSphereAlgorithmConfiguration auditAlgorithmConfiguration = new YamlShardingSphereAlgorithmConfiguration();
+ auditAlgorithmConfiguration.setType("DML_SHARDING_CONDITIONS");
+ yamlConfig.getAuditors().put("sharding_key_required_auditor", auditAlgorithmConfiguration);
ShardingRuleConfiguration actual = shardingRuleConfigurationYamlSwapper.swapToObject(yamlConfig);
assertThat(actual.getTables().size(), is(1));
assertThat(actual.getBindingTableGroups().size(), is(1));
@@ -171,6 +175,9 @@ public final class ShardingRuleConfigurationYamlSwapperTest {
assertNotNull(actual.getDefaultTableShardingStrategy());
assertNotNull(actual.getDefaultKeyGenerateStrategy());
assertNotNull(actual.getAuditStrategy());
+ assertThat(actual.getAuditors().size(), is(1));
+ assertTrue(actual.getAuditors().containsKey("sharding_key_required_auditor"));
+ assertThat(actual.getAuditors().get("sharding_key_required_auditor").getType(), is("DML_SHARDING_CONDITIONS"));
assertThat(actual.getDefaultShardingColumn(), is("user_id"));
}