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 397821d68cf Add more test cases on ShadowRuleTest (#38232)
397821d68cf is described below
commit 397821d68cfeb9683d45d5312ce562d83edc299d
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Feb 27 12:14:38 2026 +0800
Add more test cases on ShadowRuleTest (#38232)
---
.../shardingsphere/shadow/rule/ShadowRuleTest.java | 54 +++++++++++++++++++---
1 file changed, 48 insertions(+), 6 deletions(-)
diff --git
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
index 0a055ea246b..c0715770202 100644
---
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
+++
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/rule/ShadowRuleTest.java
@@ -23,21 +23,25 @@ import
org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.constant.ShadowOrder;
import org.apache.shardingsphere.shadow.spi.ShadowOperationType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -125,8 +129,12 @@ class ShadowRuleTest {
}
@Test
- void assertGetColumnShadowAlgorithms() {
+ void assertGetColumnShadowAlgorithmsWithMatchedColumn() {
assertThat(rule.getColumnShadowAlgorithms(ShadowOperationType.INSERT,
"foo_tbl", "foo_id").size(), is(1));
+ }
+
+ @Test
+ void assertGetColumnShadowAlgorithmsWithUnmatchedColumn() {
assertTrue(rule.getColumnShadowAlgorithms(ShadowOperationType.INSERT,
"foo_tbl", "bar_id").isEmpty());
}
@@ -140,21 +148,55 @@ class ShadowRuleTest {
assertThat(rule.getShadowDataSourceMappings("foo_tbl"),
is(Collections.singletonMap("prod_ds_0", "shadow_ds_0")));
}
+ @Test
+ void assertGetShadowDataSourceMappingsWithDuplicateTableName() {
+ ShadowRule mergedTableRule = new
ShadowRule(createRuleConfigurationWithDuplicateTableName());
+ assertThat(mergedTableRule.getShadowDataSourceMappings("foo_tbl"),
is(Collections.singletonMap("prod_ds_1", "shadow_ds_1")));
+ }
+
+ private ShadowRuleConfiguration
createRuleConfigurationWithDuplicateTableName() {
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration();
+ result.setDataSources(createDataSources());
+ result.setTables(createDuplicateTableConfigurations());
+ result.setShadowAlgorithms(createShadowAlgorithms());
+ return result;
+ }
+
+ private Map<String, ShadowTableConfiguration>
createDuplicateTableConfigurations() {
+ ShadowTableConfiguration firstTableConfig = new
ShadowTableConfiguration(Collections.singleton("foo_ds_0"),
createShadowAlgorithmNames("foo_tbl"));
+ ShadowTableConfiguration secondTableConfig = new
ShadowTableConfiguration(Collections.singleton("foo_ds_1"),
createShadowAlgorithmNames("bar_tbl"));
+ return new AbstractMap<String, ShadowTableConfiguration>() {
+
+ @Override
+ public Set<Entry<String, ShadowTableConfiguration>> entrySet() {
+ Set<Entry<String, ShadowTableConfiguration>> result = new
LinkedHashSet<>(2, 1F);
+ result.add(new AbstractMap.SimpleEntry<>("foo_tbl",
firstTableConfig));
+ result.add(new AbstractMap.SimpleEntry<>("foo_tbl",
secondTableConfig));
+ return result;
+ }
+ };
+ }
+
@Test
void assertGetAllShadowDataSourceMappings() {
- assertThat(rule.getAllShadowDataSourceMappings().size(), is(2));
- assertThat(rule.getAllShadowDataSourceMappings().get("prod_ds_0"),
is("shadow_ds_0"));
- assertThat(rule.getAllShadowDataSourceMappings().get("prod_ds_1"),
is("shadow_ds_1"));
+ Map<String, String> actual = rule.getAllShadowDataSourceMappings();
+ assertThat(actual.size(), is(2));
+ assertThat(actual.get("prod_ds_0"), is("shadow_ds_0"));
+ assertThat(actual.get("prod_ds_1"), is("shadow_ds_1"));
}
@Test
void assertFindProductionDataSourceNameSuccess() {
assertThat(rule.findProductionDataSourceName("foo_ds_0"),
is(Optional.of("prod_ds_0")));
- assertThat(rule.findProductionDataSourceName("foo_ds_1"),
is(Optional.of("prod_ds_1")));
}
@Test
void assertFindProductionDataSourceNameFailed() {
assertFalse(rule.findProductionDataSourceName("foo_ds_2").isPresent());
}
+
+ @Test
+ void assertGetOrder() {
+ assertThat(rule.getOrder(), is(ShadowOrder.ORDER));
+ }
}