You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2024/05/02 09:36:16 UTC
(shardingsphere) branch master updated: Add SingleRuleConfigurationRepositoryTupleSwapperIT (#31096)
This is an automated email from the ASF dual-hosted git repository.
yx9o 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 e11fd97ecdb Add SingleRuleConfigurationRepositoryTupleSwapperIT (#31096)
e11fd97ecdb is described below
commit e11fd97ecdbc4321dc638db977b3598cad17a4b5
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu May 2 17:36:10 2024 +0800
Add SingleRuleConfigurationRepositoryTupleSwapperIT (#31096)
---
kernel/single/core/pom.xml | 6 +++
...eRuleConfigurationRepositoryTupleSwapperIT.java | 47 ++++++++++++++++++++++
.../SingleRuleConfigurationYamlIT.java} | 24 +++++++----
.../core/src/test/resources/yaml/single-rule.yaml | 22 ++++++++++
4 files changed, 92 insertions(+), 7 deletions(-)
diff --git a/kernel/single/core/pom.xml b/kernel/single/core/pom.xml
index f1312e8385d..a61380fdf2b 100644
--- a/kernel/single/core/pom.xml
+++ b/kernel/single/core/pom.xml
@@ -60,5 +60,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-it-yaml</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/it/SingleRuleConfigurationRepositoryTupleSwapperIT.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/it/SingleRuleConfigurationRepositoryTupleSwapperIT.java
new file mode 100644
index 00000000000..bfa5dd746a8
--- /dev/null
+++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/it/SingleRuleConfigurationRepositoryTupleSwapperIT.java
@@ -0,0 +1,47 @@
+/*
+ * 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.single.it;
+
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
+import org.apache.shardingsphere.single.yaml.config.swapper.SingleRuleConfigurationRepositoryTupleSwapper;
+import org.apache.shardingsphere.test.it.yaml.RepositoryTupleSwapperIT;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class SingleRuleConfigurationRepositoryTupleSwapperIT extends RepositoryTupleSwapperIT {
+
+ SingleRuleConfigurationRepositoryTupleSwapperIT() {
+ super("yaml/single-rule.yaml", new SingleRuleConfigurationRepositoryTupleSwapper(), false);
+ }
+
+ @Override
+ protected void assertRepositoryTuples(final Collection<RepositoryTuple> actualRepositoryTuples) {
+ assertThat(actualRepositoryTuples.size(), is(1));
+ Iterator<RepositoryTuple> iterator = actualRepositoryTuples.iterator();
+ assertSingle(iterator.next());
+ }
+
+ private void assertSingle(final RepositoryTuple actual) {
+ assertThat(actual.getKey(), is("tables"));
+ assertThat(actual.getValue(), is("defaultDataSource: foo_ds\ntables:\n- foo_tbl\n"));
+ }
+}
diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapperTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/it/SingleRuleConfigurationYamlIT.java
similarity index 55%
rename from kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapperTest.java
rename to kernel/single/core/src/test/java/org/apache/shardingsphere/single/it/SingleRuleConfigurationYamlIT.java
index 702a4b1084c..79c301d7492 100644
--- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapperTest.java
+++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/it/SingleRuleConfigurationYamlIT.java
@@ -15,20 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.single.yaml.config.swapper;
+package org.apache.shardingsphere.single.it;
+import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
import org.apache.shardingsphere.single.yaml.config.pojo.YamlSingleRuleConfiguration;
-import org.junit.jupiter.api.Test;
+import org.apache.shardingsphere.test.it.yaml.YamlRuleConfigurationIT;
+
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class SingleRuleConfigurationRepositoryTupleSwapperTest {
+class SingleRuleConfigurationYamlIT extends YamlRuleConfigurationIT {
+
+ SingleRuleConfigurationYamlIT() {
+ super("yaml/single-rule.yaml");
+ }
- private final SingleRuleConfigurationRepositoryTupleSwapper swapper = new SingleRuleConfigurationRepositoryTupleSwapper();
+ @Override
+ protected void assertYamlRootConfiguration(final YamlRootConfiguration actual) {
+ assertSingleRule((YamlSingleRuleConfiguration) actual.getRules().iterator().next());
+ }
- @Test
- void assertSwapToRepositoryTuples() {
- assertThat(swapper.swapToRepositoryTuples(new YamlSingleRuleConfiguration()).iterator().next().getKey(), is("tables"));
+ private void assertSingleRule(final YamlSingleRuleConfiguration actual) {
+ assertThat(actual.getTables(), is(Collections.singletonList("foo_tbl")));
+ assertThat(actual.getDefaultDataSource(), is("foo_ds"));
}
}
diff --git a/kernel/single/core/src/test/resources/yaml/single-rule.yaml b/kernel/single/core/src/test/resources/yaml/single-rule.yaml
new file mode 100644
index 00000000000..89c83612994
--- /dev/null
+++ b/kernel/single/core/src/test/resources/yaml/single-rule.yaml
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+rules:
+- !SINGLE
+ defaultDataSource: foo_ds
+ tables:
+ - foo_tbl