This is an automated email from the ASF dual-hosted git repository.

panjuan 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 3812930  Add sharding spring boot config for test case (#6928)
3812930 is described below

commit 38129308b3a5ade57205fb0ceaee3816448bd456
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Aug 19 14:46:08 2020 +0800

    Add sharding spring boot config for test case (#6928)
---
 .../MasterSlaveRuleSpringbootConfiguration.java    |  6 +--
 .../spring/boot/ShardingSpringBootStarterTest.java |  1 +
 .../test/resources/application-sharding.properties | 22 ++++++++-
 .../boot/type/SpringBootBroadcastTableTest.java    | 54 ----------------------
 .../application-broadcast-table.properties         | 26 -----------
 5 files changed, 25 insertions(+), 84 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveRuleSpringbootConfiguration.java
 
b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveRuleSpringbootConfiguration.java
index 3aca514..85386af 100644
--- 
a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveRuleSpringbootConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveRuleSpringbootConfiguration.java
@@ -66,10 +66,10 @@ public class MasterSlaveRuleSpringbootConfiguration {
     @Bean
     public RuleConfiguration masterSlaveRuleConfiguration(final 
YamlMasterSlaveRuleConfiguration yamlRuleConfiguration,
                                                           final 
ObjectProvider<Map<String, MasterSlaveLoadBalanceAlgorithm>> 
loadBalanceAlgorithms) {
-        AlgorithmProvidedMasterSlaveRuleConfiguration ruleConfiguration = 
swapper.swapToObject(yamlRuleConfiguration);
+        AlgorithmProvidedMasterSlaveRuleConfiguration result = 
swapper.swapToObject(yamlRuleConfiguration);
         Map<String, MasterSlaveLoadBalanceAlgorithm> balanceAlgorithmMap = 
Optional.ofNullable(loadBalanceAlgorithms.getIfAvailable()).orElse(Collections.emptyMap());
-        ruleConfiguration.setLoadBalanceAlgorithms(balanceAlgorithmMap);
-        return ruleConfiguration;
+        result.setLoadBalanceAlgorithms(balanceAlgorithmMap);
+        return result;
     }
     
     /**
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java
index c7203b0..7c84a60 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java
@@ -67,6 +67,7 @@ public class ShardingSpringBootStarterTest {
     
     @Test
     public void assertShardingConfiguration() {
+        assertThat(shardingRuleConfiguration.getTables().size(), is(2));
         // TODO assert sharding configuration
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/application-sharding.properties
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/application-sharding.properties
index c4eadf6..1324a26 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/application-sharding.properties
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/application-sharding.properties
@@ -27,4 +27,24 @@ 
spring.shardingsphere.rules.sharding.sharding-algorithms.orderItemTableShardingA
 spring.shardingsphere.rules.sharding.key-generators.keyGenerator.type=SNOWFLAKE
 
spring.shardingsphere.rules.sharding.key-generators.keyGenerator.props.worker.id=123
 
-# TODO add spring.shardingsphere.rules.sharding.xxx
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=databaseShardingAlgorithm
+
+spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds_$->{0..1}.t_order_$->{0..1}
+
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=orderTableShardingAlgorithm
+
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=keyGenerator
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds_$->{0..1}.t_order_item_$->{0..1}
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-algorithm-name=orderItemTableShardingAlgorithm
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=keyGenerator
+
+spring.shardingsphere.rules.sharding.binding-tables=t_order,t_order_item
+spring.shardingsphere.rules.sharding.broadcast-tables=t_config
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/type/SpringBootBroadcastTableTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/type/SpringBootBroadcastTableTest.java
deleted file mode 100644
index f8583b2..0000000
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/type/SpringBootBroadcastTableTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.spring.boot.type;
-
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import 
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import javax.annotation.Resource;
-import javax.sql.DataSource;
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest(classes = SpringBootBroadcastTableTest.class)
-@SpringBootApplication
-@ActiveProfiles("broadcast-table")
-public class SpringBootBroadcastTableTest {
-    
-    @Resource
-    private DataSource dataSource;
-    
-    @Test
-    public void assertBroadcastTable() {
-        assertThat(dataSource, instanceOf(ShardingSphereDataSource.class));
-        ShardingSphereDataSource shardingSphereDataSource = 
(ShardingSphereDataSource) dataSource;
-        ShardingRule shardingRule = (ShardingRule) 
shardingSphereDataSource.getSchemaContexts().getDefaultSchemaContext().getSchema().getRules().iterator().next();
-        assertThat(shardingRule.getBroadcastTables(), 
is(Collections.singletonList("t_config")));
-        assertThat(shardingRule.getDataSourceNames().size(), is(3));
-    }
-}
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-broadcast-table.properties
 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-broadcast-table.properties
deleted file mode 100644
index 50a8fa9..0000000
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-broadcast-table.properties
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# 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.
-#
-
-spring.shardingsphere.datasource.names=ds,ds_${0..1}
-spring.shardingsphere.datasource.ds.type=org.apache.shardingsphere.test.MockedDataSource
-spring.shardingsphere.datasource.ds_0.type=org.apache.shardingsphere.test.MockedDataSource
-spring.shardingsphere.datasource.ds_1.type=org.apache.shardingsphere.test.MockedDataSource
-
-spring.shardingsphere.rules.sharding.broadcast-tables=t_config
-
-spring.shardingsphere.props.sql.show=true
-spring.shardingsphere.props.executor.size=100

Reply via email to