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 6c862b8 Replace mock data source to spring boot integrate tests (#6925) 6c862b8 is described below commit 6c862b8f815e9b66480b879bc244595fda20f7cb Author: Liang Zhang <terrym...@163.com> AuthorDate: Wed Aug 19 14:25:32 2020 +0800 Replace mock data source to spring boot integrate tests (#6925) * Use mocked data source on spring boot test * Remove useless fixture of sharding spring boot test * Move ShardingSpringBootConditionTest package * Remove useless javadoc * Rename ShadowSpringBootConditionTest * Rename MasterSlaveSpringBootStarterTest * Rename EncryptSpringBootStarterTest --- ...Test.java => EncryptSpringBootStarterTest.java} | 29 ++++--- .../EncryptSpringBootConditionTest.java | 3 +- .../spring/boot/fixture/TestEncryptAlgorithm.java | 54 ------------- ...che.shardingsphere.encrypt.spi.EncryptAlgorithm | 18 ----- .../test/resources/application-encrypt.properties | 7 +- ....java => MasterSlaveSpringBootStarterTest.java} | 29 +++---- .../MasterSlaveSpringBootConditionTest.java | 3 +- ...ndomMasterSlaveLoadBalanceAlgorithmFixture.java | 47 ----------- ...masterslave.spi.MasterSlaveLoadBalanceAlgorithm | 18 ----- .../resources/application-masterslave.properties | 6 +- .../boot/ShadowRuleSpringBootConfiguration.java | 6 +- ...nTest.java => ShadowSpringBootStarterTest.java} | 20 ++--- .../ShadowSpringBootConditionTest.java | 3 +- .../test/resources/application-shadow.properties | 1 - .../ShardingAlgorithmProvidedBeanRegistry.java | 8 +- .../boot/ShardingRuleSpringBootConfiguration.java | 23 +++--- ...hardingSpringBootAlgorithmProviderBeanTest.java | 55 ------------- .../spring/boot/ShardingSpringBootStarterTest.java | 72 +++++++++++++++++ .../ShardingSpringBootConditionTest.java | 3 +- .../ExtendInlineShardingAlgorithmFixture.java | 90 ---------------------- .../IncrementKeyGenerateAlgorithmFixture.java | 53 ------------- ...hardingsphere.sharding.spi.KeyGenerateAlgorithm | 18 ----- ...e.shardingsphere.sharding.spi.ShardingAlgorithm | 19 ----- .../test/resources/application-sharding.properties | 19 +++-- .../pom.xml | 7 ++ .../spring/boot/type/SpringBootEncryptTest.java | 4 +- .../boot/type/SpringBootMasterSlaveTest.java | 5 +- .../spring/boot/type/SpringBootShardingTest.java | 5 +- .../application-broadcast-table.properties | 23 +----- .../test/resources/application-encrypt.properties | 7 +- .../resources/application-masterslave.properties | 23 +----- .../test/resources/application-shadow.properties | 15 +--- .../test/resources/application-sharding.properties | 22 +----- 33 files changed, 174 insertions(+), 541 deletions(-) diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootAlgorithmProviderBeanTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java similarity index 66% rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootAlgorithmProviderBeanTest.java rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java index c29cda8..6aab00b 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootAlgorithmProviderBeanTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java @@ -17,34 +17,39 @@ package org.apache.shardingsphere.encrypt.spring.boot; -import javax.annotation.Resource; -import org.apache.shardingsphere.encrypt.spring.boot.fixture.TestEncryptAlgorithm; +import org.apache.shardingsphere.encrypt.algorithm.AESEncryptAlgorithm; +import org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration; 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.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import javax.annotation.Resource; + import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = EncryptSpringBootAlgorithmProviderBeanTest.class) +@SpringBootTest(classes = EncryptSpringBootStarterTest.class) @SpringBootApplication @ActiveProfiles("encrypt") -public class EncryptSpringBootAlgorithmProviderBeanTest { +public class EncryptSpringBootStarterTest { + + @Resource + private AESEncryptAlgorithm aesEncryptor; @Resource - private ApplicationContext applicationContext; + private AlgorithmProvidedEncryptRuleConfiguration encryptRuleConfiguration; + + @Test + public void assertAesEncryptor() { + assertThat(aesEncryptor.getProps().getProperty("aes.key.value"), is("123456")); + } @Test - public void assertAlgorithmProviderBean() { - Object algorithmBean = applicationContext.getBean("aes_encryptor"); - assertThat(algorithmBean.getClass().getName(), is(TestEncryptAlgorithm.class.getName())); - TestEncryptAlgorithm algorithmFixture = (TestEncryptAlgorithm) algorithmBean; - assertNotNull(algorithmFixture.getEnvironment()); + public void assertEncryptRuleConfiguration() { + // TODO assert Encrypt Rule Configuration } } diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootConditionTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/condition/EncryptSpringBootConditionTest.java similarity index 94% rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootConditionTest.java rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/condition/EncryptSpringBootConditionTest.java index b6d6919..5dcf986 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootConditionTest.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/condition/EncryptSpringBootConditionTest.java @@ -15,9 +15,8 @@ * limitations under the License. */ -package org.apache.shardingsphere.encrypt.spring.boot; +package org.apache.shardingsphere.encrypt.spring.boot.condition; -import org.apache.shardingsphere.encrypt.spring.boot.condition.EncryptSpringBootCondition; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/fixture/TestEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/fixture/TestEncryptAlgorithm.java deleted file mode 100644 index 66f70bf..0000000 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/fixture/TestEncryptAlgorithm.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.encrypt.spring.boot.fixture; - -import java.util.Properties; -import javax.annotation.Resource; -import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm; -import org.springframework.core.env.Environment; - -@Getter -@Setter -public final class TestEncryptAlgorithm implements EncryptAlgorithm { - - private Properties props = new Properties(); - - @Resource - private Environment environment; - - @Override - public void init() { - } - - @Override - public String encrypt(final Object plaintext) { - return "encryptValue"; - } - - @Override - public Object decrypt(final String ciphertext) { - return "decryptValue"; - } - - @Override - public String getType() { - return "test"; - } -} diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm deleted file mode 100644 index 0f2ce36..0000000 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm +++ /dev/null @@ -1,18 +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. -# - -org.apache.shardingsphere.encrypt.spring.boot.fixture.TestEncryptAlgorithm diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties index 58220d2..4510be5 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties @@ -15,6 +15,9 @@ # limitations under the License. # -spring.shardingsphere.rules.encrypt.encryptors.aes_encryptor.type=test -spring.shardingsphere.rules.encrypt.encryptors.aes_encryptor.props.aes.key.value=123456 +spring.shardingsphere.rules.encrypt.encryptors.aesEncryptor.type=AES +spring.shardingsphere.rules.encrypt.encryptors.aesEncryptor.props.aes.key.value=123456 +spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.cipher-column=pwd_cipher +spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.plain-column=pwd_plain +spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.encryptor-name=aesEncryptor diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootAlgorithmProviderBeanTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootStarter [...] similarity index 59% rename from shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootAlgorithmProviderBeanTest.java rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootStarterTest.java index fb1ff84..59e8f08 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootAlgorithmProviderBeanTest.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootStarterTest.java @@ -17,35 +17,38 @@ package org.apache.shardingsphere.masterslave.spring.boot; -import org.apache.shardingsphere.masterslave.spring.boot.fixture.RandomMasterSlaveLoadBalanceAlgorithmFixture; +import org.apache.shardingsphere.masterslave.algorithm.RandomMasterSlaveLoadBalanceAlgorithm; +import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration; 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.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = MasterSlaveSpringBootAlgorithmProviderBeanTest.class) +@SpringBootTest(classes = MasterSlaveSpringBootStarterTest.class) @SpringBootApplication @ActiveProfiles("masterslave") -public class MasterSlaveSpringBootAlgorithmProviderBeanTest { +public class MasterSlaveSpringBootStarterTest { @Resource - private ApplicationContext applicationContext; + private RandomMasterSlaveLoadBalanceAlgorithm random; + + @Resource + private MasterSlaveRuleConfiguration masterSlaveRuleConfiguration; + + @Test + public void assertLoadBalanceAlgorithm() { + assertTrue(random.getProps().isEmpty()); + } @Test - public void assertAlgorithmProviderBean() { - Object algorithmBean = applicationContext.getBean("fixture"); - assertThat(algorithmBean.getClass().getName(), is(RandomMasterSlaveLoadBalanceAlgorithmFixture.class.getName())); - RandomMasterSlaveLoadBalanceAlgorithmFixture algorithmFixture = (RandomMasterSlaveLoadBalanceAlgorithmFixture) algorithmBean; - assertNotNull(algorithmFixture.getEnvironment()); + public void assertMasterSlaveRuleConfiguration() { + // TODO assert MasterSlave Rule Configuration } } diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootConditionTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootCondition [...] similarity index 94% rename from shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootConditionTest.java rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootConditionTest.java index cb5d53d..3a7d43a 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootConditionTest.java +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootConditionTest.java @@ -15,9 +15,8 @@ * limitations under the License. */ -package org.apache.shardingsphere.masterslave.spring.boot; +package org.apache.shardingsphere.masterslave.spring.boot.condition; -import org.apache.shardingsphere.masterslave.spring.boot.condition.MasterSlaveSpringBootCondition; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/fixture/RandomMasterSlaveLoadBalanceAlgorithmFixture.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/fixture/RandomMasterSl [...] deleted file mode 100644 index 82246e4..0000000 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/fixture/RandomMasterSlaveLoadBalanceAlgorithmFixture.java +++ /dev/null @@ -1,47 +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.masterslave.spring.boot.fixture; - -import java.util.List; -import java.util.Properties; -import java.util.concurrent.ThreadLocalRandom; -import javax.annotation.Resource; -import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm; -import org.springframework.core.env.Environment; - -@Getter -@Setter -public final class RandomMasterSlaveLoadBalanceAlgorithmFixture implements MasterSlaveLoadBalanceAlgorithm { - - private Properties props = new Properties(); - - @Resource - private Environment environment; - - @Override - public String getDataSource(final String name, final String masterDataSourceName, final List<String> slaveDataSourceNames) { - return slaveDataSourceNames.get(ThreadLocalRandom.current().nextInt(slaveDataSourceNames.size())); - } - - @Override - public String getType() { - return "FIXTURE"; - } -} diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBal [...] deleted file mode 100644 index 7ec3ec8..0000000 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm +++ /dev/null @@ -1,18 +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. -# - -org.apache.shardingsphere.masterslave.spring.boot.fixture.RandomMasterSlaveLoadBalanceAlgorithmFixture diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/application-masterslave.properties b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/application-masterslave.properties index 85a1888..067dd1f 100644 --- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/application-masterslave.properties +++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/application-masterslave.properties @@ -15,6 +15,8 @@ # limitations under the License. # +spring.shardingsphere.rules.master-slave.load-balancers.random.type=RANDOM -spring.shardingsphere.rules.master-slave.load-balancers.fixture.type=FIXTURE - +spring.shardingsphere.rules.master-slave.data-sources.ds_ms.master-data-source-name=ds_master +spring.shardingsphere.rules.master-slave.data-sources.ds_ms.slave-data-source-names=ds_slave_0,ds_slave_1 +spring.shardingsphere.rules.master-slave.data-sources.ds_ms.load-balancer-name=random diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/main/java/org/apache/shardingsphere/shadow/spring/boot/ShadowRuleSpringBootConfiguration.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/main/java/org/apache/shardingsphere/shadow/spring/boot/ShadowRuleSpringBootConfiguration.java index b8aa9a0..6253720 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/main/java/org/apache/shardingsphere/shadow/spring/boot/ShadowRuleSpringBootConfiguration.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/main/java/org/apache/shardingsphere/shadow/spring/boot/ShadowRuleSpringBootConfiguration.java @@ -51,11 +51,11 @@ public class ShadowRuleSpringBootConfiguration { /** * Shadow rule configuration. * - * @param yamlShadowRuleConfiguration YAML shadow rule configuration + * @param yamlShadowRuleConfig YAML shadow rule configuration * @return shadow rule configuration */ @Bean - public RuleConfiguration shadowRuleConfiguration(final YamlShadowRuleConfiguration yamlShadowRuleConfiguration) { - return swapper.swapToObject(yamlShadowRuleConfiguration); + public RuleConfiguration shadowRuleConfiguration(final YamlShadowRuleConfiguration yamlShadowRuleConfig) { + return swapper.swapToObject(yamlShadowRuleConfig); } } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootAlgorithmProviderBeanTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootStarterTest.java similarity index 63% rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootAlgorithmProviderBeanTest.java rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootStarterTest.java index a41d68c..25b29ce 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootAlgorithmProviderBeanTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootStarterTest.java @@ -17,38 +17,32 @@ package org.apache.shardingsphere.shadow.spring.boot; -import org.apache.shardingsphere.shadow.yaml.config.YamlShadowRuleConfiguration; +import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; 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.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; - import java.util.Collections; -import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = ShadowSpringBootAlgorithmProviderBeanTest.class) +@SpringBootTest(classes = ShadowSpringBootStarterTest.class) @SpringBootApplication @ActiveProfiles("shadow") -public class ShadowSpringBootAlgorithmProviderBeanTest { +public class ShadowSpringBootStarterTest { @Resource - private ApplicationContext applicationContext; + private ShadowRuleConfiguration shadowRuleConfiguration; @Test - public void assertAlgorithmProviderBean() { - Object algorithmBean = applicationContext.getBean("shadow"); - assertThat(algorithmBean.getClass(), equalTo(YamlShadowRuleConfiguration.class)); - YamlShadowRuleConfiguration actual = YamlShadowRuleConfiguration.class.cast(algorithmBean); - assertThat(actual.getColumn(), is("shadow")); - assertThat(actual.getShadowMappings(), is(Collections.singletonMap("ds", "shadow_ds"))); + public void assertShadowRuleConfiguration() { + assertThat(shadowRuleConfiguration.getColumn(), is("shadow")); + assertThat(shadowRuleConfiguration.getShadowMappings(), is(Collections.singletonMap("ds", "shadow_ds"))); } } diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootConditionTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/condition/ShadowSpringBootConditionTest.java similarity index 94% rename from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootConditionTest.java rename to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/condition/ShadowSpringBootConditionTest.java index 0b767b1..4858bc9 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/ShadowSpringBootConditionTest.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/java/org/apache/shardingsphere/shadow/spring/boot/condition/ShadowSpringBootConditionTest.java @@ -15,9 +15,8 @@ * limitations under the License. */ -package org.apache.shardingsphere.shadow.spring.boot; +package org.apache.shardingsphere.shadow.spring.boot.condition; -import org.apache.shardingsphere.shadow.spring.boot.condition.ShadowSpringBootCondition; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow.properties b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow.properties index 6d3b4d3..bb667e3 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow.properties +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-spring/shardingsphere-shadow-spring-boot-starter/src/test/resources/application-shadow.properties @@ -17,4 +17,3 @@ spring.shardingsphere.rules.shadow.column=shadow spring.shardingsphere.rules.shadow.shadowMappings.ds=shadow_ds - diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingAlgorithmProvidedBeanRegistry.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingAlgorithmProvidedBeanRegistry.java index d2ff180..01d963f 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingAlgorithmProvidedBeanRegistry.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingAlgorithmProvidedBeanRegistry.java @@ -20,7 +20,6 @@ package org.apache.shardingsphere.sharding.spring.boot; import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm; import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm; import org.apache.shardingsphere.spring.boot.registry.AbstractAlgorithmProvidedBeanRegistry; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.core.env.Environment; @@ -33,17 +32,12 @@ public final class ShardingAlgorithmProvidedBeanRegistry extends AbstractAlgorit private static final String KEY_GENERATORS = "spring.shardingsphere.rules.sharding.key-generators."; - /** - * Instantiates a new Sharding algorithm provided bean registry. - * - * @param environment environment - */ public ShardingAlgorithmProvidedBeanRegistry(final Environment environment) { super(environment); } @Override - public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) throws BeansException { + public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) { registerBean(SHARDING_ALGORITHMS, ShardingAlgorithm.class, registry); registerBean(KEY_GENERATORS, KeyGenerateAlgorithm.class, registry); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingRuleSpringBootConfiguration.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingRuleSpringBootConfiguration.java index a8f3f60..118c84c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingRuleSpringBootConfiguration.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/main/java/org/apache/shardingsphere/sharding/spring/boot/ShardingRuleSpringBootConfiguration.java @@ -17,9 +17,6 @@ package org.apache.shardingsphere.sharding.spring.boot; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; import org.apache.shardingsphere.infra.config.RuleConfiguration; import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration; import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm; @@ -35,6 +32,10 @@ import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; + /** * Sharding rule configuration for spring boot. */ @@ -46,7 +47,7 @@ public class ShardingRuleSpringBootConfiguration { private final ShardingRuleAlgorithmProviderConfigurationYamlSwapper swapper = new ShardingRuleAlgorithmProviderConfigurationYamlSwapper(); /** - * Sharding YAML rule spring boot configuration. + * Create sharding YAML rule spring boot configuration bean. * * @return YAML rule configuration */ @@ -57,12 +58,12 @@ public class ShardingRuleSpringBootConfiguration { } /** - * Sharding rule configuration. + * Create sharding rule configuration bean. * * @param yamlShardingRuleConfiguration YAML sharding rule configuration * @param shardingAlgorithmProvider sharding algorithm provider * @param keyGenerateAlgorithmProvider key generate algorithm provider - * @return the rule configuration + * @return sharding rule configuration */ @Bean public RuleConfiguration shardingRuleConfiguration(final YamlShardingRuleConfiguration yamlShardingRuleConfiguration, @@ -70,14 +71,14 @@ public class ShardingRuleSpringBootConfiguration { final ObjectProvider<Map<String, KeyGenerateAlgorithm>> keyGenerateAlgorithmProvider) { Map<String, ShardingAlgorithm> shardingAlgorithmMap = Optional.ofNullable(shardingAlgorithmProvider.getIfAvailable()).orElse(Collections.emptyMap()); Map<String, KeyGenerateAlgorithm> keyGenerateAlgorithmMap = Optional.ofNullable(keyGenerateAlgorithmProvider.getIfAvailable()).orElse(Collections.emptyMap()); - AlgorithmProvidedShardingRuleConfiguration ruleConfiguration = swapper.swapToObject(yamlShardingRuleConfiguration); - ruleConfiguration.setShardingAlgorithms(shardingAlgorithmMap); - ruleConfiguration.setKeyGenerators(keyGenerateAlgorithmMap); - return ruleConfiguration; + AlgorithmProvidedShardingRuleConfiguration result = swapper.swapToObject(yamlShardingRuleConfiguration); + result.setShardingAlgorithms(shardingAlgorithmMap); + result.setKeyGenerators(keyGenerateAlgorithmMap); + return result; } /** - * Sharding algorithm provided bean registry. + * Create sharding algorithm provided bean registry. * * @param environment environment * @return sharding algorithm provided bean registry diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootAlgorithmProviderBeanTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootAlgorithmProviderBeanTest.java deleted file mode 100644 index 73fc229..0000000 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootAlgorithmProviderBeanTest.java +++ /dev/null @@ -1,55 +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.sharding.spring.boot; - -import javax.annotation.Resource; -import org.apache.shardingsphere.sharding.spring.boot.fixture.ExtendInlineShardingAlgorithmFixture; -import org.apache.shardingsphere.sharding.spring.boot.fixture.IncrementKeyGenerateAlgorithmFixture; -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.context.ApplicationContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = ShardingSpringBootAlgorithmProviderBeanTest.class) -@SpringBootApplication -@ActiveProfiles("sharding") -public class ShardingSpringBootAlgorithmProviderBeanTest { - - @Resource - private ApplicationContext applicationContext; - - @Test - public void assertAlgorithmProviderBean() { - Object algorithmBean = applicationContext.getBean("database_inline"); - assertThat(algorithmBean.getClass().getName(), is(ExtendInlineShardingAlgorithmFixture.class.getName())); - ExtendInlineShardingAlgorithmFixture algorithmFixture = (ExtendInlineShardingAlgorithmFixture) algorithmBean; - assertNotNull(algorithmFixture.getEnvironment()); - Object incrementKeyBean = applicationContext.getBean("incrementKey"); - assertThat(incrementKeyBean.getClass().getName(), is(IncrementKeyGenerateAlgorithmFixture.class.getName())); - IncrementKeyGenerateAlgorithmFixture keyGenerateAlgorithmFixture = (IncrementKeyGenerateAlgorithmFixture) incrementKeyBean; - assertNotNull(keyGenerateAlgorithmFixture.getEnvironment()); - } -} 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 new file mode 100644 index 0000000..c7203b0 --- /dev/null +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootStarterTest.java @@ -0,0 +1,72 @@ +/* + * 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.sharding.spring.boot; + +import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration; +import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm; +import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm; +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 static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = ShardingSpringBootStarterTest.class) +@SpringBootApplication +@ActiveProfiles("sharding") +public class ShardingSpringBootStarterTest { + + @Resource + private InlineShardingAlgorithm databaseShardingAlgorithm; + + @Resource + private InlineShardingAlgorithm orderTableShardingAlgorithm; + + @Resource + private InlineShardingAlgorithm orderItemTableShardingAlgorithm; + + @Resource + private SnowflakeKeyGenerateAlgorithm keyGenerator; + + @Resource + private AlgorithmProvidedShardingRuleConfiguration shardingRuleConfiguration; + + @Test + public void assertShardingAlgorithm() { + assertThat(databaseShardingAlgorithm.getProps().getProperty("algorithm.expression"), is("ds_$->{user_id % 2}")); + assertThat(orderTableShardingAlgorithm.getProps().getProperty("algorithm.expression"), is("t_order_$->{order_id % 2}")); + assertThat(orderItemTableShardingAlgorithm.getProps().getProperty("algorithm.expression"), is("t_order_item_$->{order_id % 2}")); + } + + @Test + public void assertKeyGenerateAlgorithm() { + assertThat(keyGenerator.getProps().getProperty("worker.id"), is("123")); + } + + @Test + public void assertShardingConfiguration() { + // TODO assert sharding configuration + } +} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootConditionTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/condition/ShardingSpringBootConditionTest.java similarity index 94% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootConditionTest.java rename to shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/condition/ShardingSpringBootConditionTest.java index 72364a0..73d8985 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/ShardingSpringBootConditionTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/condition/ShardingSpringBootConditionTest.java @@ -15,9 +15,8 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.spring.boot; +package org.apache.shardingsphere.sharding.spring.boot.condition; -import org.apache.shardingsphere.sharding.spring.boot.condition.ShardingSpringBootCondition; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/fixture/ExtendInlineShardingAlgorithmFixture.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/fixture/ExtendInlineShardingAlgorithmFixture.java deleted file mode 100644 index e8c1b84..0000000 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/fixture/ExtendInlineShardingAlgorithmFixture.java +++ /dev/null @@ -1,90 +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.sharding.spring.boot.fixture; - -import com.google.common.base.Preconditions; -import groovy.lang.Closure; -import groovy.util.Expando; -import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineExpressionParser; -import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue; -import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue; -import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm; -import org.springframework.core.env.Environment; - -import javax.annotation.Resource; -import java.util.Collection; -import java.util.Properties; - -public final class ExtendInlineShardingAlgorithmFixture implements StandardShardingAlgorithm<Comparable<?>> { - - private static final String ALGORITHM_EXPRESSION_KEY = "algorithm.expression"; - - private static final String ALLOW_RANGE_QUERY_KEY = "allow.range.query.with.inline.sharding"; - - private Closure<?> closure; - - private boolean allowRangeQuery; - - @Resource - @Getter - private Environment environment; - - @Getter - @Setter - private Properties props = new Properties(); - - @Override - public void init() { - closure = createClosure(); - allowRangeQuery = isAllowRangeQuery(); - } - - private Closure<?> createClosure() { - String expression = props.getProperty(ALGORITHM_EXPRESSION_KEY); - Preconditions.checkNotNull(expression, "Inline sharding algorithm expression cannot be null."); - String algorithmExpression = InlineExpressionParser.handlePlaceHolder(expression.trim()); - Closure<?> result = new InlineExpressionParser(algorithmExpression).evaluateClosure().rehydrate(new Expando(), null, null); - result.setResolveStrategy(Closure.DELEGATE_ONLY); - return result; - } - - private boolean isAllowRangeQuery() { - return Boolean.parseBoolean(props.getOrDefault(ALLOW_RANGE_QUERY_KEY, Boolean.FALSE.toString()).toString()); - } - - @Override - public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Comparable<?>> shardingValue) { - closure.setProperty(shardingValue.getColumnName(), shardingValue.getValue()); - return closure.call().toString(); - } - - @Override - public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Comparable<?>> shardingValue) { - if (allowRangeQuery) { - return availableTargetNames; - } - throw new UnsupportedOperationException("Since the property of `allow.range.query.with.inline.sharding` is false, inline sharding algorithm can not tackle with range query."); - } - - @Override - public String getType() { - return "EXTEND_INLINE"; - } -} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/fixture/IncrementKeyGenerateAlgorithmFixture.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/fixture/IncrementKeyGenerateAlgorithmFixture.java deleted file mode 100644 index ef1a640..0000000 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/java/org/apache/shardingsphere/sharding/spring/boot/fixture/IncrementKeyGenerateAlgorithmFixture.java +++ /dev/null @@ -1,53 +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.sharding.spring.boot.fixture; - -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; -import javax.annotation.Resource; -import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm; -import org.springframework.core.env.Environment; - -public final class IncrementKeyGenerateAlgorithmFixture implements KeyGenerateAlgorithm { - - private final AtomicInteger count = new AtomicInteger(); - - @Getter - @Setter - private Properties props = new Properties(); - - @Resource - @Getter - private Environment environment; - - @Override - public void init() { - } - - @Override - public Comparable<?> generateKey() { - return count.incrementAndGet(); - } - - @Override - public String getType() { - return "EXTEND_INCREMENT"; - } -} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm deleted file mode 100644 index b02c23a..0000000 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm +++ /dev/null @@ -1,18 +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. -# - -org.apache.shardingsphere.sharding.spring.boot.fixture.IncrementKeyGenerateAlgorithmFixture diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm deleted file mode 100644 index 39b5bff..0000000 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-boot-starter/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm +++ /dev/null @@ -1,19 +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. -# - -org.apache.shardingsphere.sharding.spring.boot.fixture.ExtendInlineShardingAlgorithmFixture - 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 773e5a9..c4eadf6 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 @@ -15,13 +15,16 @@ # limitations under the License. # -spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.type=EXTEND_INLINE -spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.props.algorithm.expression=ds_$->{user_id % 2} -spring.shardingsphere.rules.sharding.sharding-algorithms.t_order_inline.type=EXTEND_INLINE -spring.shardingsphere.rules.sharding.sharding-algorithms.t_order_inline.props.algorithm.expression=t_order_$->{order_id % 2} -spring.shardingsphere.rules.sharding.sharding-algorithms.t_order_item_inline.type=EXTEND_INLINE -spring.shardingsphere.rules.sharding.sharding-algorithms.t_order_item_inline.props.algorithm.expression=t_order_item_$->{order_id % 2} +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseShardingAlgorithm.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.databaseShardingAlgorithm.props.algorithm.expression=ds_$->{user_id % 2} -spring.shardingsphere.rules.sharding.key-generators.incrementKey.type=EXTEND_INCREMENT -spring.shardingsphere.rules.sharding.key-generators.incrementKey.props.worker.id=123 +spring.shardingsphere.rules.sharding.sharding-algorithms.orderTableShardingAlgorithm.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.orderTableShardingAlgorithm.props.algorithm.expression=t_order_$->{order_id % 2} +spring.shardingsphere.rules.sharding.sharding-algorithms.orderItemTableShardingAlgorithm.type=INLINE +spring.shardingsphere.rules.sharding.sharding-algorithms.orderItemTableShardingAlgorithm.props.algorithm.expression=t_order_item_$->{order_id % 2} + +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 diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml index dab72bf..2f26129 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml @@ -59,6 +59,13 @@ </dependency> <dependency> + <groupId>org.apache.shardingsphere</groupId> + <artifactId>shardingsphere-test</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> 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/SpringBootEncryptTest.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/SpringBootEncryptTest.java index 600f11c..d3b052c 100644 --- 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/SpringBootEncryptTest.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/SpringBootEncryptTest.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.spring.boot.type; -import org.apache.commons.dbcp2.BasicDataSource; import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; import org.apache.shardingsphere.encrypt.rule.EncryptRule; import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey; @@ -53,8 +52,7 @@ public class SpringBootEncryptTest { @Test public void assertWithEncryptDataSource() { assertTrue(dataSource instanceof ShardingSphereDataSource); - BasicDataSource basicDataSource = (BasicDataSource) ((ShardingSphereDataSource) dataSource).getDataSourceMap().values().iterator().next(); - assertThat(basicDataSource.getMaxTotal(), is(100)); + assertThat(((ShardingSphereDataSource) dataSource).getDataSourceMap().size(), is(1)); } @Test 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/SpringBootMasterSlaveTest.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/SpringBootMasterSlaveTest.java index 0bdaa28..3fe2756 100644 --- 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/SpringBootMasterSlaveTest.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/SpringBootMasterSlaveTest.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.spring.boot.type; -import org.apache.commons.dbcp2.BasicDataSource; import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.masterslave.rule.MasterSlaveDataSourceRule; @@ -49,9 +48,7 @@ public class SpringBootMasterSlaveTest { @Test public void assertDataSource() { assertTrue(dataSource instanceof ShardingSphereDataSource); - for (DataSource each : ((ShardingSphereDataSource) dataSource).getDataSourceMap().values()) { - assertThat(((BasicDataSource) each).getMaxTotal(), is(100)); - } + assertThat(((ShardingSphereDataSource) dataSource).getDataSourceMap().size(), is(3)); Collection<ShardingSphereRule> rules = ((ShardingSphereDataSource) dataSource).getSchemaContexts().getDefaultSchemaContext().getSchema().getRules(); assertThat(rules.size(), is(1)); assertMasterSlaveRule((MasterSlaveRule) rules.iterator().next()); 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/SpringBootShardingTest.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/SpringBootShardingTest.java index 3b8deea..2994c3f 100644 --- 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/SpringBootShardingTest.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/SpringBootShardingTest.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.spring.boot.type; -import org.apache.commons.dbcp2.BasicDataSource; import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.datanode.DataNode; @@ -53,9 +52,7 @@ public class SpringBootShardingTest { public void assertWithShardingSphereDataSource() { assertThat(dataSource, instanceOf(ShardingSphereDataSource.class)); SchemaContexts schemaContexts = ((ShardingSphereDataSource) dataSource).getSchemaContexts(); - for (DataSource each : ((ShardingSphereDataSource) dataSource).getDataSourceMap().values()) { - assertThat(((BasicDataSource) each).getMaxTotal(), is(100)); - } + assertThat(((ShardingSphereDataSource) dataSource).getDataSourceMap().size(), is(3)); assertTrue(schemaContexts.getProps().<Boolean>getValue(ConfigurationPropertyKey.SQL_SHOW)); assertTrue(schemaContexts.getProps().getValue(ConfigurationPropertyKey.SQL_SHOW)); assertThat(schemaContexts.getProps().getValue(ConfigurationPropertyKey.EXECUTOR_SIZE), is(100)); 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 index 45d54d8..50a8fa9 100644 --- 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 @@ -16,26 +16,9 @@ # spring.shardingsphere.datasource.names=ds,ds_${0..1} -spring.shardingsphere.datasource.ds.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds.url=jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds.username=sa -spring.shardingsphere.datasource.ds.password= -spring.shardingsphere.datasource.ds.max-total=100 - -spring.shardingsphere.datasource.ds_0.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds_0.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds_0.url=jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds_0.username=sa -spring.shardingsphere.datasource.ds_0.password= -spring.shardingsphere.datasource.ds_0.max-total=100 - -spring.shardingsphere.datasource.ds_1.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds_1.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds_1.url=jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds_1.username=sa -spring.shardingsphere.datasource.ds_1.password= -spring.shardingsphere.datasource.ds_1.max-total=100 +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 diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-encrypt.properties b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-encrypt.properties index 4d2dc6d..340c349 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-encrypt.properties +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-encrypt.properties @@ -17,12 +17,7 @@ spring.shardingsphere.datasource.name=ds -spring.shardingsphere.datasource.ds.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds.url=jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds.username=sa -spring.shardingsphere.datasource.ds.password= -spring.shardingsphere.datasource.ds.max-total=100 +spring.shardingsphere.datasource.ds.type=org.apache.shardingsphere.test.MockedDataSource spring.shardingsphere.rules.encrypt.tables.t_order.columns.user_id.cipher-column=user_encrypt spring.shardingsphere.rules.encrypt.tables.t_order.columns.user_id.assisted-query-column=user_assisted diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-masterslave.properties b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-masterslave.properties index 31b4162..142bedf 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-masterslave.properties +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-masterslave.properties @@ -18,26 +18,9 @@ spring.example.datasource.name=ds_master spring.shardingsphere.datasource.names=${spring.example.datasource.name},ds_slave_${0..1} -spring.shardingsphere.datasource.ds_master.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds_master.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds_master.url=jdbc:h2:mem:ds_master;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds_master.username=root -spring.shardingsphere.datasource.ds_master.password= -spring.shardingsphere.datasource.ds_master.max-total=100 - -spring.shardingsphere.datasource.ds_slave_0.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds_slave_0.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds_slave_0.url=jdbc:h2:mem:demo_ds_slave_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds_slave_0.username=root -spring.shardingsphere.datasource.ds_slave_0.password= -spring.shardingsphere.datasource.ds_slave_0.max-total=100 - -spring.shardingsphere.datasource.ds_slave_1.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds_slave_1.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds_slave_1.url=jdbc:h2:mem:demo_ds_slave_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds_slave_1.username=root -spring.shardingsphere.datasource.ds_slave_1.password= -spring.shardingsphere.datasource.ds_slave_1.max-total=100 +spring.shardingsphere.datasource.ds_master.type=org.apache.shardingsphere.test.MockedDataSource +spring.shardingsphere.datasource.ds_slave_0.type=org.apache.shardingsphere.test.MockedDataSource +spring.shardingsphere.datasource.ds_slave_1.type=org.apache.shardingsphere.test.MockedDataSource spring.shardingsphere.rules.master-slave.data-sources.ds_ms.master-data-source-name=ds_master spring.shardingsphere.rules.master-slave.data-sources.ds_ms.slave-data-source-names=ds_slave_0,ds_slave_1 diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-shadow.properties b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-shadow.properties index 00c3b98..894a141 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-shadow.properties +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-shadow.properties @@ -17,19 +17,8 @@ spring.shardingsphere.datasource.names=ds,shadow_ds -spring.shardingsphere.datasource.ds.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds.url=jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds.username=sa -spring.shardingsphere.datasource.ds.password= -spring.shardingsphere.datasource.ds.max-total=100 - -spring.shardingsphere.datasource.shadow_ds.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.shadow_ds.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.shadow_ds.url=jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.shadow_ds.username=sa -spring.shardingsphere.datasource.shadow_ds.password= -spring.shardingsphere.datasource.shadow_ds.max-total=99 +spring.shardingsphere.datasource.ds.type=org.apache.shardingsphere.test.MockedDataSource +spring.shardingsphere.datasource.shadow_ds.type=org.apache.shardingsphere.test.MockedDataSource spring.shardingsphere.rules.shadow.column=is_shadow spring.shardingsphere.rules.shadow.shadow-mappings.ds=shadow_ds diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-sharding.properties b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-sharding.properties index 9716c80..e4acfb6 100644 --- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-sharding.properties +++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/resources/application-sharding.properties @@ -16,26 +16,10 @@ # spring.shardingsphere.datasource.names=ds,ds_${0..1} -spring.shardingsphere.datasource.ds.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds.url=jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds.username=sa -spring.shardingsphere.datasource.ds.password= -spring.shardingsphere.datasource.ds.max-total=100 -spring.shardingsphere.datasource.ds_0.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds_0.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds_0.url=jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds_0.username=sa -spring.shardingsphere.datasource.ds_0.password= -spring.shardingsphere.datasource.ds_0.max-total=100 - -spring.shardingsphere.datasource.ds_1.type=org.apache.commons.dbcp2.BasicDataSource -spring.shardingsphere.datasource.ds_1.driver-class-name=org.h2.Driver -spring.shardingsphere.datasource.ds_1.url=jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL -spring.shardingsphere.datasource.ds_1.username=sa -spring.shardingsphere.datasource.ds_1.password= -spring.shardingsphere.datasource.ds_1.max-total=100 +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.default-database-strategy.standard.sharding-column=user_id spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=database_inline