From 14a2d75cc9b00668c1cc0b63c01520c023918211 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Mon, 4 Nov 2024 00:38:12 +0800 Subject: [PATCH] Add test cases on ShadowRuleConfigurationChecker (#33521) * Add ShadowDataSourceMappingsFinder * Add ShadowDataSourceMappingsFinder * Add ShadowDataSourceMappingsFinder * Add ShadowDataSourceMappingsFinder * Add test cases on ShadowRuleConfigurationChecker --- .../ShadowRuleConfigurationCheckerTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java index cbe581d548470..fca4809e4ee6a 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.shadow.exception.metadata.MissingRequiredProductionDataSourceException; import org.apache.shardingsphere.shadow.exception.metadata.MissingRequiredShadowDataSourceException; import org.apache.shardingsphere.shadow.exception.metadata.NotImplementHintShadowAlgorithmException; +import org.apache.shardingsphere.shadow.exception.metadata.ShadowDataSourceMappingNotFoundException; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.util.PropertiesBuilder; import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; @@ -88,6 +89,21 @@ private ShadowRuleConfiguration createRuleConfigurationWithInvalidDefaultShadowA return result; } + @Test + void assertCheckWithInvalidShadowTableDataSourcesReferences() { + assertThrows(ShadowDataSourceMappingNotFoundException.class, + () -> ruleConfigChecker.check("foo_db", createRuleConfigurationWithInvalidShadowTableDataSourcesReferences(), createDataSourceMap(), Collections.emptyList())); + } + + private ShadowRuleConfiguration createRuleConfigurationWithInvalidShadowTableDataSourcesReferences() { + ShadowRuleConfiguration result = new ShadowRuleConfiguration(); + result.setShadowAlgorithms(Collections.singletonMap("foo-algo", new AlgorithmConfiguration("SQL_HINT", new Properties()))); + result.setDefaultShadowAlgorithmName("foo-algo"); + result.setDataSources(Collections.singleton(new ShadowDataSourceConfiguration("foo_ds", "prod_ds", "shadow_ds"))); + result.setTables(Collections.singletonMap("foo_tbl", new ShadowTableConfiguration(Collections.singletonList("bar_ds"), new LinkedList<>(Collections.singleton("foo-algo"))))); + return result; + } + @Test void assertCheckWithInvalidShadowTableAlgorithmsReferences() { assertThrows(MissingRequiredAlgorithmException.class,