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

menghaoran 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 8cf7bff  Optimization toDashedForm method and unit test (#15499)
8cf7bff is described below

commit 8cf7bff8007a741ad1866e3dbc35a2fe73d68b7f
Author: zhaojinchao <[email protected]>
AuthorDate: Fri Feb 18 19:37:24 2022 +0800

    Optimization toDashedForm method and unit test (#15499)
    
    * Optimization toDashedForm method and remove work-id
    
    * add unit test.
---
 .../sharding/spring/boot/ShardingSpringBootStarterTest.java  |  9 ---------
 .../src/test/resources/application-sharding.properties       |  1 -
 .../apache/shardingsphere/spring/boot/util/PropertyUtil.java |  4 +++-
 .../shardingsphere/spring/boot/util/PropertyUtilTest.java    | 12 +++++++-----
 4 files changed, 10 insertions(+), 16 deletions(-)

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 c876b93..eabf582 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
@@ -54,9 +54,6 @@ public class ShardingSpringBootStarterTest {
     private InlineShardingAlgorithm orderItemTableShardingAlgorithm;
     
     @Resource
-    private SnowflakeKeyGenerateAlgorithm keyGenerator;
-    
-    @Resource
     private AlgorithmProvidedShardingRuleConfiguration shardingRuleConfig;
     
     @Test
@@ -67,11 +64,6 @@ public class ShardingSpringBootStarterTest {
     }
     
     @Test
-    public void assertKeyGenerateAlgorithm() {
-        assertThat(keyGenerator.getProps().getProperty("worker-id"), 
is("123"));
-    }
-    
-    @Test
     public void assertShardingConfiguration() {
         assertShardingConfigurationTables();
         assertShardingConfigurationBindingTableGroups();
@@ -140,6 +132,5 @@ public class ShardingSpringBootStarterTest {
     private void assertShardingConfigurationKeyGenerators() {
         assertThat(shardingRuleConfig.getKeyGenerators().size(), is(1));
         assertThat(shardingRuleConfig.getKeyGenerators().get("keyGenerator"), 
instanceOf(SnowflakeKeyGenerateAlgorithm.class));
-        
assertThat(shardingRuleConfig.getKeyGenerators().get("keyGenerator").getProps().getProperty("worker-id"),
 is("123"));
     }
 }
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 43fdeb8..528e4f4 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
@@ -25,7 +25,6 @@ 
spring.shardingsphere.rules.sharding.sharding-algorithms.orderItemTableShardingA
 
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
 
 
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
 
spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=databaseShardingAlgorithm
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
index a95e19e..0c1cab9 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
@@ -66,6 +66,7 @@ public final class PropertyUtil {
     
     /**
      * Spring Boot 1.x is compatible with Spring Boot 2.x by Using Java 
Reflect.
+     *
      * @param environment : the environment context
      * @param prefix : the prefix part of property key
      * @param targetClass : the target class type of result
@@ -131,10 +132,11 @@ public final class PropertyUtil {
 
     /**
      * Return the specified Java Bean property name in dashed form.
+     *
      * @param name the source name
      * @return the dashed from
      */
-    static String toDashedForm(final String name) {
+    private static String toDashedForm(final String name) {
         StringBuilder result = new StringBuilder(name.length());
         boolean inIndex = false;
         for (int i = 0; i < name.length(); i++) {
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/PropertyUtilTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/PropertyUtilTest.java
index 4f70167..c48aedd 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/PropertyUtilTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/PropertyUtilTest.java
@@ -18,12 +18,14 @@
 package org.apache.shardingsphere.spring.boot.util;
 
 import org.junit.Test;
+import org.springframework.mock.env.MockEnvironment;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 
 public final class PropertyUtilTest {
     
@@ -31,12 +33,12 @@ public final class PropertyUtilTest {
     public void assertGetCamelCaseKeys() {
         assertThat(PropertyUtil.getCamelCaseKeys(createToBeConvertedMap()), 
is(createConvertedMap()));
     }
-
+    
     @Test
-    public void assertToDashedForm() throws Exception {
-        assertThat(PropertyUtil.toDashedForm("fooKey"), is("foo-key"));
-        assertThat(PropertyUtil.toDashedForm("foo_key"), is("foo-key"));
-        assertThat(PropertyUtil.toDashedForm("foo_Key"), is("foo-key"));
+    public void test() throws Exception {
+        MockEnvironment mockEnvironment = new MockEnvironment();
+        
mockEnvironment.setProperty("spring.shardingsphere.rules.sharding.sharding-algorithms.table-inline.type",
 "INLINE");
+        assertTrue(PropertyUtil.containPropertyPrefix(mockEnvironment, 
"spring.shardingsphere.rules.sharding.sharding-algorithms.table-inline"));
     }
     
     private Map<String, Object> createToBeConvertedMap() {

Reply via email to