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 2026/09/14 08:31:38 UTC

(shardingsphere) branch master updated: Apply default shadow algorithm when swapping YAML shadow rule (#39749)

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

terrymanu 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 517a6b3f5f3 Apply default shadow algorithm when swapping YAML shadow rule (#39749)
517a6b3f5f3 is described below

commit 517a6b3f5f3d65faf05bb235c503e60e24aca532
Author: Eunbin Son <58...@users.noreply.github.com>
AuthorDate: Mon Sep 14 17:31:31 2026 +0900

    Apply default shadow algorithm when swapping YAML shadow rule (#39749)
    
    Co-authored-by: Liang Zhang <zh...@apache.org>
---
 RELEASE-NOTES.md                                   |  1 +
 .../YamlShadowRuleConfigurationSwapper.java        |  2 +-
 .../YamlShadowRuleConfigurationSwapperTest.java    | 66 ++++++++++++++++++++++
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index c0426bf31cb..e3e01b3a2f3 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -88,6 +88,7 @@
 1. SQL Federation: Fix SQL Federation pagination binding for long LIMIT parameters - [#39237](https://github.com/apache/shardingsphere/pull/39237)
 1. Broadcast: Fix case-sensitive table name lookup in broadcast data node rule attribute - [#39153](https://github.com/apache/shardingsphere/pull/39153)
 1. Encrypt: Fix stale encryptors leaking when altering an encrypt rule - [#39209](https://github.com/apache/shardingsphere/pull/39209)
+1. Shadow: Apply default shadow algorithm to shadow tables when swapping YAML rule configuration - [#39749](https://github.com/apache/shardingsphere/pull/39749)
 1. Shadow: Fix INSERT SELECT statement being routed to shadow data source - [#39751](https://github.com/apache/shardingsphere/pull/39751)
 
 ### Enhancements
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java
index 362eddcd2a0..ff0b089e18a 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapper.java
@@ -81,9 +81,9 @@ public final class YamlShadowRuleConfigurationSwapper implements YamlRuleConfigu
         result.setDataSources(swapToDataSources(yamlConfig.getDataSources()));
         result.setTables(swapToShadowTables(yamlConfig.getTables()));
         result.setShadowAlgorithms(swapToShadowAlgorithms(yamlConfig.getShadowAlgorithms()));
+        result.setDefaultShadowAlgorithmName(yamlConfig.getDefaultShadowAlgorithmName());
         setTableDefaultShadowDataSource(result.getTables(), result.getDataSources());
         setTableDefaultShadowAlgorithm(result.getTables(), result.getDefaultShadowAlgorithmName());
-        result.setDefaultShadowAlgorithmName(yamlConfig.getDefaultShadowAlgorithmName());
         return result;
     }
     
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapperTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapperTest.java
new file mode 100644
index 00000000000..2fb631a8b9c
--- /dev/null
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowRuleConfigurationSwapperTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.shadow.yaml.swapper;
+
+import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.yaml.config.YamlShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.yaml.config.table.YamlShadowTableConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+class YamlShadowRuleConfigurationSwapperTest {
+    
+    private final YamlShadowRuleConfigurationSwapper swapper = new YamlShadowRuleConfigurationSwapper();
+    
+    @Test
+    void assertSwapToObjectWithDefaultShadowAlgorithmName() {
+        YamlShadowRuleConfiguration yamlConfig = createYamlRuleConfiguration(Collections.emptyList());
+        yamlConfig.setDefaultShadowAlgorithmName("foo_algo");
+        ShadowRuleConfiguration actual = swapper.swapToObject(yamlConfig);
+        assertThat(actual.getDefaultShadowAlgorithmName(), is("foo_algo"));
+        assertThat(actual.getTables().get("foo_tbl").getShadowAlgorithmNames(), is(Collections.singletonList("foo_algo")));
+    }
+    
+    @Test
+    void assertSwapToObjectWithoutDefaultShadowAlgorithmName() {
+        ShadowRuleConfiguration actual = swapper.swapToObject(createYamlRuleConfiguration(Collections.emptyList()));
+        assertThat(actual.getTables().get("foo_tbl").getShadowAlgorithmNames(), is(Collections.emptyList()));
+    }
+    
+    @Test
+    void assertSwapToObjectWithTableShadowAlgorithmNames() {
+        YamlShadowRuleConfiguration yamlConfig = createYamlRuleConfiguration(Collections.singletonList("bar_algo"));
+        yamlConfig.setDefaultShadowAlgorithmName("foo_algo");
+        ShadowRuleConfiguration actual = swapper.swapToObject(yamlConfig);
+        assertThat(actual.getTables().get("foo_tbl").getShadowAlgorithmNames(), is(Collections.singletonList("bar_algo")));
+    }
+    
+    private YamlShadowRuleConfiguration createYamlRuleConfiguration(final Collection<String> shadowAlgorithmNames) {
+        YamlShadowTableConfiguration yamlTableConfig = new YamlShadowTableConfiguration();
+        yamlTableConfig.setShadowAlgorithmNames(new LinkedList<>(shadowAlgorithmNames));
+        YamlShadowRuleConfiguration result = new YamlShadowRuleConfiguration();
+        result.getTables().put("foo_tbl", yamlTableConfig);
+        return result;
+    }
+}