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 29eda6016f9 Add test cases on 
ReadwriteSplittingExportableRuleAttribute (#33583)
29eda6016f9 is described below

commit 29eda6016f97eaa77dcb1eb18be343a888c187a1
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Nov 7 14:47:23 2024 +0800

    Add test cases on ReadwriteSplittingExportableRuleAttribute (#33583)
---
 ...dwriteSplittingExportableRuleAttributeTest.java | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingExportableRuleAttributeTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingExportableRuleAttributeTest.java
new file mode 100644
index 00000000000..b57875bfe63
--- /dev/null
+++ 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingExportableRuleAttributeTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.attribute;
+
+import 
org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableConstants;
+import 
org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableItemConstants;
+import 
org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration;
+import 
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule;
+import 
org.apache.shardingsphere.readwritesplitting.transaction.TransactionalReadQueryStrategy;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+
+class ReadwriteSplittingExportableRuleAttributeTest {
+    
+    @Test
+    void assertGetExportData() {
+        ReadwriteSplittingDataSourceGroupRuleConfiguration config = new 
ReadwriteSplittingDataSourceGroupRuleConfiguration("foo_group", "write_ds", 
Arrays.asList("read_ds0", "read_ds1"), "foo_algo");
+        Map<String, ReadwriteSplittingDataSourceGroupRule> 
dataSourceGroupRules = new HashMap<>(2, 1F);
+        dataSourceGroupRules.put("ignored_group", 
mock(ReadwriteSplittingDataSourceGroupRule.class));
+        dataSourceGroupRules.put("foo_group", new 
ReadwriteSplittingDataSourceGroupRule(config, 
TransactionalReadQueryStrategy.FIXED, null));
+        ReadwriteSplittingExportableRuleAttribute ruleAttribute = new 
ReadwriteSplittingExportableRuleAttribute(dataSourceGroupRules);
+        Map<String, Object> actual = ruleAttribute.getExportData();
+        assertThat(actual.size(), is(1));
+        assertStaticDataSources(actual);
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void assertStaticDataSources(final Map<String, Object> actual) {
+        Map<String, Map<String, String>> actualStaticDataSources = 
(Map<String, Map<String, String>>) 
actual.get(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE);
+        assertThat(actualStaticDataSources.size(), is(1));
+        assertThat(actualStaticDataSources.get("foo_group").size(), is(2));
+        
assertThat(actualStaticDataSources.get("foo_group").get(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME),
 is("write_ds"));
+        
assertThat(actualStaticDataSources.get("foo_group").get(ExportableItemConstants.REPLICA_DATA_SOURCE_NAMES),
 is("read_ds0,read_ds1"));
+    }
+}

Reply via email to