You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/08/11 06:21:36 UTC

[GitHub] [shardingsphere] sizzlecar commented on a change in pull request #11753: fix-10965

sizzlecar commented on a change in pull request #11753:
URL: https://github.com/apache/shardingsphere/pull/11753#discussion_r686531881



##########
File path: shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.distsql.handler.converter;
+
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
+import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+public final class ReadwriteSplittingRuleStatementConverterTest {
+
+    @Test
+    public void convertTest() {
+        ReadwriteSplittingRuleConfiguration emptyRuleSegmentConvertResult = ReadwriteSplittingRuleStatementConverter
+                .convert(Collections.emptyList());
+        assertEmptyRuleSegmentConvertResult(emptyRuleSegmentConvertResult);
+        Properties properties1 = new Properties();
+        properties1.setProperty("ping", "pong");
+        ReadwriteSplittingRuleSegment singleReadwriteSplittingRuleSegment = createReadwriteSplittingRuleSegment("name1", "write_ds_01", Arrays.asList("read_ds_01", "read_ds_02"), "lb01", properties1);
+        ReadwriteSplittingRuleConfiguration singleRuleSegmentConvertResult = ReadwriteSplittingRuleStatementConverter
+                .convert(Collections.singleton(singleReadwriteSplittingRuleSegment));
+        assertSingleRuleSegmentConvertResult(singleReadwriteSplittingRuleSegment, singleRuleSegmentConvertResult);
+        Properties properties2 = new Properties();
+        properties2.setProperty("ping1", "pong1");
+        Properties properties3 = new Properties();
+        properties3.setProperty("ping2", "pong2");
+        Properties properties4 = new Properties();
+        properties4.setProperty("ping3", "pong3");
+        properties4.setProperty("ping4", "pong4");
+        List<ReadwriteSplittingRuleSegment> multipleReadwriteSplittingRuleSegments = Arrays.asList(
+                createReadwriteSplittingRuleSegment("name2", "write_ds_02", Arrays.asList("read_ds_02", "read_ds_03"), "lb02", properties2),
+                createReadwriteSplittingRuleSegment("name3", "write_ds_03", Arrays.asList("read_ds_04", "read_ds_05"), "lb03", properties3),
+                createReadwriteSplittingRuleSegment("name4", "write_ds_04", Arrays.asList("read_ds_06", "read_ds_07"), "lb04", properties4));
+        ReadwriteSplittingRuleConfiguration multipleRuleSegmentConvertResult = ReadwriteSplittingRuleStatementConverter.convert(multipleReadwriteSplittingRuleSegments);
+        assertMultipleReadwriteSplittingRuleSegments(multipleReadwriteSplittingRuleSegments, multipleRuleSegmentConvertResult);
+    }
+
+    private ReadwriteSplittingRuleSegment createReadwriteSplittingRuleSegment(final String name,
+                                                                              final String writeDataSource,
+                                                                              final List<String> readDataSourceList,
+                                                                              final String loadBalancerTypeName,
+                                                                              final Properties properties) {
+        return new ReadwriteSplittingRuleSegment(name, writeDataSource, readDataSourceList, loadBalancerTypeName, properties);
+    }
+
+    private void assertEmptyRuleSegmentConvertResult(final ReadwriteSplittingRuleConfiguration emptyRuleSegmentConvertResult) {
+        assertTrue(emptyRuleSegmentConvertResult.getDataSources().isEmpty());
+        assertTrue(emptyRuleSegmentConvertResult.getLoadBalancers().isEmpty());
+    }
+
+    private void assertSingleRuleSegmentConvertResult(final ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment,
+                                                      final ReadwriteSplittingRuleConfiguration singleRuleSegmentConvertResult) {
+        Collection<ReadwriteSplittingDataSourceRuleConfiguration> singleRuleSegmentConvertResultDataSources = singleRuleSegmentConvertResult.getDataSources();
+        Map<String, ShardingSphereAlgorithmConfiguration> singleRuleSegmentConvertResultLoadBalancers = singleRuleSegmentConvertResult.getLoadBalancers();
+        assertEquals(1, singleRuleSegmentConvertResultDataSources.size());

Review comment:
       ok, already edited




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org