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 2019/11/24 07:42:09 UTC

[GitHub] [incubator-shardingsphere] wgy8283335 commented on a change in pull request #3568: Feature 3185 jdbc orchestration.

wgy8283335 commented on a change in pull request #3568: Feature 3185 jdbc orchestration.
URL: https://github.com/apache/incubator-shardingsphere/pull/3568#discussion_r349906796
 
 

 ##########
 File path: sharding-jdbc/sharding-jdbc-orchestration-new/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/api/yaml/sharding/YamlOrchestrationShardingWithMasterSlaveIntegrateTest.java
 ##########
 @@ -0,0 +1,89 @@
+/*
+ * 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.shardingjdbc.orchestration.api.yaml.sharding;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.AbstractYamlDataSourceTest;
+import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.YamlOrchestrationShardingDataSourceFactory;
+import org.apache.shardingsphere.shardingjdbc.orchestration.internal.datasource.OrchestrationShardingDataSource;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import javax.sql.DataSource;
+import java.io.File;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+@RunWith(Parameterized.class)
+@RequiredArgsConstructor
+public class YamlOrchestrationShardingWithMasterSlaveIntegrateTest extends AbstractYamlDataSourceTest {
+    
+    private final String filePath;
+    
+    private final boolean hasDataSource;
+    
+    @Parameters(name = "{index}:{0}-{1}")
+    public static Collection init() {
+        return Arrays.asList(new Object[][]{
+                {"/yaml/integrate/sharding_ms/configWithDataSourceWithoutProps.yaml", true},
+                {"/yaml/integrate/sharding_ms/configWithoutDataSourceWithoutProps.yaml", false},
+                {"/yaml/integrate/sharding_ms/configWithDataSourceWithProps.yaml", true},
+                {"/yaml/integrate/sharding_ms/configWithoutDataSourceWithProps.yaml", false},
+        });
+    }
+    
+    @Test
+    public void assertWithDataSource() throws Exception {
+        File yamlFile = new File(YamlOrchestrationShardingWithMasterSlaveIntegrateTest.class.getResource(filePath).toURI());
+        DataSource dataSource;
+        if (hasDataSource) {
+            dataSource = YamlOrchestrationShardingDataSourceFactory.createDataSource(yamlFile);
+        } else {
+            Map<String, DataSource> dataSourceMap = Maps.asMap(Sets.newHashSet("db0_master", "db0_slave", "db1_master", "db1_slave"), new Function<String, DataSource>() {
+                @Override
+                public DataSource apply(final String key) {
+                    return AbstractYamlDataSourceTest.createDataSource(key);
+                }
+            });
+            Map<String, DataSource> result = new HashMap<>();
+            for (Entry<String, DataSource> each : dataSourceMap.entrySet()) {
+                result.put(each.getKey(), each.getValue());
+            }
+            dataSource = YamlOrchestrationShardingDataSourceFactory.createDataSource(result, yamlFile);
+        }
+        try (Connection conn = dataSource.getConnection();
+             Statement stm = conn.createStatement()) {
+            stm.execute(String.format("INSERT INTO t_order(user_id,status) values(%d, %s)", 10, "'insert'"));
+            stm.executeQuery("SELECT * FROM t_order");
+            stm.executeQuery("SELECT * FROM t_order_item");
+            stm.executeQuery("SELECT * FROM config");
+        }
+
 
 Review comment:
   This line is empty.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services