This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 a4241b37e19 Add ReadwriteSplittingDataSourceMapperRuleTest (#30373)
a4241b37e19 is described below
commit a4241b37e19a99d9e8a2c2cd20e6a1efc6854850
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Mar 2 17:05:24 2024 +0800
Add ReadwriteSplittingDataSourceMapperRuleTest (#30373)
* Add ReadwriteSplittingDataSourceMapperRuleTest
* Add ReadwriteSplittingDataSourceMapperRuleTest
---
...ReadwriteSplittingDataSourceMapperRuleTest.java | 44 ++++++++++++++++++++++
.../rule/ReadwriteSplittingRuleTest.java | 14 +------
2 files changed, 46 insertions(+), 12 deletions(-)
diff --git
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleTest.java
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleTest.java
new file mode 100644
index 00000000000..e1eea05db91
--- /dev/null
+++
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.readwritesplitting.rule;
+
+import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class ReadwriteSplittingDataSourceMapperRuleTest {
+
+ @Test
+ void assertGetDataSourceMapper() {
+ Map<String, Collection<String>> actual = new
ReadwriteSplittingDataSourceMapperRule(Collections.singleton(createReadwriteSplittingRule())).getDataSourceMapper();
+ Map<String, Collection<String>> expected =
Collections.singletonMap("readwrite", Arrays.asList("write_ds", "read_ds_0",
"read_ds_1"));
+ assertThat(actual, is(expected));
+ }
+
+ private ReadwriteSplittingDataSourceRule createReadwriteSplittingRule() {
+ return new ReadwriteSplittingDataSourceRule(
+ new ReadwriteSplittingDataSourceRuleConfiguration("readwrite",
"write_ds", Arrays.asList("read_ds_0", "read_ds_1"), "random"), null, null);
+ }
+}
diff --git
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
index 86d1fe50954..5b9bed5209e 100644
---
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
+++
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
@@ -18,20 +18,18 @@
package org.apache.shardingsphere.readwritesplitting.rule;
import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
+import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource;
-import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import
org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent;
+import org.apache.shardingsphere.mode.event.storage.StorageNodeRole;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
-import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -95,14 +93,6 @@ class ReadwriteSplittingRuleTest {
assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(),
is(Collections.emptySet()));
}
- @Test
- void assertGetDataSourceMapper() {
- ReadwriteSplittingRule readwriteSplittingRule =
createReadwriteSplittingRule();
- Map<String, Collection<String>> actual =
readwriteSplittingRule.getDataSourceMapperRule().getDataSourceMapper();
- Map<String, Collection<String>> expected =
Collections.singletonMap("readwrite", Arrays.asList("write_ds", "read_ds_0",
"read_ds_1"));
- assertThat(actual, is(expected));
- }
-
@Test
void assertCreateReadwriteSplittingRuleWithRowValueExpressionImpl() {
ReadwriteSplittingDataSourceRuleConfiguration config = new
ReadwriteSplittingDataSourceRuleConfiguration(