This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 2e9057f707a Add comprehensive test cases for TypedProperties
implementations (#36954)
2e9057f707a is described below
commit 2e9057f707a09dfa59a55948be6d15d8e3f895bc
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Oct 28 17:22:53 2025 +0800
Add comprehensive test cases for TypedProperties implementations (#36954)
* Add comprehensive test cases for TypedProperties implementations
- Create JDBCRepositoryPropertiesTest with 100% property coverage
- Enhance EtcdPropertiesTest to cover CONNECTION_TIMEOUT_SECONDS property
- Complete ConfigurationPropertiesTest with missing SSL and metadata
properties
- Ensure all TypedProperties implementations have full test coverage
- Follow elegant test patterns: minimal methods, no duplication, clean
assertions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Refactor SingleTableDataNodeLoader
---------
Co-authored-by: Claude <[email protected]>
---
.../config/props/ConfigurationPropertiesTest.java | 20 +++++++-
.../cluster/etcd/props/EtcdPropertiesTest.java | 14 +++++-
.../jdbc/props/JDBCRepositoryPropertiesTest.java | 56 ++++++++++++++++++++++
3 files changed, 87 insertions(+), 3 deletions(-)
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java
index 301a0d37c14..1311933928d 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java
@@ -41,6 +41,7 @@ class ConfigurationPropertiesTest {
assertThat(actual.getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE),
is(20));
assertThat(actual.getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY),
is(20));
assertTrue((Boolean)
actual.getValue(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED));
+
assertThat(actual.getValue(ConfigurationPropertyKey.LOAD_TABLE_METADATA_BATCH_SIZE),
is(500));
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE),
is(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")));
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD),
is(20));
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_BACKEND_QUERY_FETCH_SIZE),
is(20));
@@ -49,6 +50,11 @@ class ConfigurationPropertiesTest {
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_DEFAULT_PORT),
is(3308));
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG),
is(1024));
assertThat(actual.getValue(ConfigurationPropertyKey.CDC_SERVER_PORT),
is(33071));
+ assertTrue((Boolean)
actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_ENABLED));
+
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_VERSION),
is("TLSv1.3"));
+
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_CIPHER),
is("ECDHE"));
+ assertTrue((Boolean)
actual.getValue(ConfigurationPropertyKey.AGENT_PLUGINS_ENABLED));
+ assertTrue((Boolean)
actual.getValue(ConfigurationPropertyKey.PERSIST_SCHEMAS_TO_REPOSITORY_ENABLED));
}
private Properties createProperties() {
@@ -58,6 +64,7 @@ class ConfigurationPropertiesTest {
new
Property(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE.getKey(), "20"),
new
Property(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY.getKey(),
"20"),
new
Property(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED.getKey(),
Boolean.TRUE.toString()),
+ new
Property(ConfigurationPropertyKey.LOAD_TABLE_METADATA_BATCH_SIZE.getKey(),
"500"),
new
Property(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(),
"PostgreSQL"),
new
Property(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD.getKey(),
"20"),
new
Property(ConfigurationPropertyKey.PROXY_BACKEND_QUERY_FETCH_SIZE.getKey(),
"20"),
@@ -65,7 +72,12 @@ class ConfigurationPropertiesTest {
new
Property(ConfigurationPropertyKey.PROXY_FRONTEND_MAX_CONNECTIONS.getKey(),
"20"),
new
Property(ConfigurationPropertyKey.PROXY_DEFAULT_PORT.getKey(), "3308"),
new
Property(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG.getKey(), "1024"),
- new
Property(ConfigurationPropertyKey.CDC_SERVER_PORT.getKey(), "33071"));
+ new
Property(ConfigurationPropertyKey.CDC_SERVER_PORT.getKey(), "33071"),
+ new
Property(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_ENABLED.getKey(),
Boolean.TRUE.toString()),
+ new
Property(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_VERSION.getKey(),
"TLSv1.3"),
+ new
Property(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_CIPHER.getKey(), "ECDHE"),
+ new
Property(ConfigurationPropertyKey.AGENT_PLUGINS_ENABLED.getKey(),
Boolean.TRUE.toString()),
+ new
Property(ConfigurationPropertyKey.PERSIST_SCHEMAS_TO_REPOSITORY_ENABLED.getKey(),
Boolean.TRUE.toString()));
}
@Test
@@ -76,6 +88,7 @@ class ConfigurationPropertiesTest {
assertThat(actual.getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE),
is(0));
assertThat(actual.getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY),
is(1));
assertFalse((Boolean)
actual.getValue(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED));
+
assertThat(actual.getValue(ConfigurationPropertyKey.LOAD_TABLE_METADATA_BATCH_SIZE),
is(1000));
assertNull(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE));
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD),
is(128));
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_BACKEND_QUERY_FETCH_SIZE),
is(-1));
@@ -84,5 +97,10 @@ class ConfigurationPropertiesTest {
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_DEFAULT_PORT),
is(3307));
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG),
is(1024));
assertThat(actual.getValue(ConfigurationPropertyKey.CDC_SERVER_PORT),
is(33071));
+ assertFalse((Boolean)
actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_ENABLED));
+
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_VERSION),
is("TLSv1.2,TLSv1.3"));
+
assertThat(actual.getValue(ConfigurationPropertyKey.PROXY_FRONTEND_SSL_CIPHER),
is(""));
+ assertTrue((Boolean)
actual.getValue(ConfigurationPropertyKey.AGENT_PLUGINS_ENABLED));
+ assertTrue((Boolean)
actual.getValue(ConfigurationPropertyKey.PERSIST_SCHEMAS_TO_REPOSITORY_ENABLED));
}
}
diff --git
a/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java
b/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java
index f5e0428aa87..a2b0ed5764c 100644
---
a/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java
+++
b/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java
@@ -30,11 +30,21 @@ class EtcdPropertiesTest {
@Test
void assertGetValue() {
- assertThat(new EtcdProperties(PropertiesBuilder.build(new
Property(EtcdPropertyKey.TIME_TO_LIVE_SECONDS.getKey(),
"50"))).getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS), is(50L));
+ EtcdProperties actual = new EtcdProperties(createProperties());
+ assertThat(actual.getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS),
is(50L));
+
assertThat(actual.getValue(EtcdPropertyKey.CONNECTION_TIMEOUT_SECONDS),
is(60L));
+ }
+
+ private Properties createProperties() {
+ return PropertiesBuilder.build(
+ new Property(EtcdPropertyKey.TIME_TO_LIVE_SECONDS.getKey(),
"50"),
+ new
Property(EtcdPropertyKey.CONNECTION_TIMEOUT_SECONDS.getKey(), "60"));
}
@Test
void assertGetDefaultValue() {
- assertThat(new EtcdProperties(new
Properties()).getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS), is(30L));
+ EtcdProperties actual = new EtcdProperties(new Properties());
+ assertThat(actual.getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS),
is(30L));
+
assertThat(actual.getValue(EtcdPropertyKey.CONNECTION_TIMEOUT_SECONDS),
is(30L));
}
}
diff --git
a/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/props/JDBCRepositoryPropertiesTest.java
b/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/props/JDBCRepositoryPropertiesTest.java
new file mode 100644
index 00000000000..5f8ad5e9661
--- /dev/null
+++
b/mode/type/standalone/repository/provider/jdbc/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/props/JDBCRepositoryPropertiesTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.mode.repository.standalone.jdbc.props;
+
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
+import org.junit.jupiter.api.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class JDBCRepositoryPropertiesTest {
+
+ @Test
+ void assertGetValue() {
+ JDBCRepositoryProperties actual = new
JDBCRepositoryProperties(createProperties());
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.PROVIDER),
is("MySQL"));
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.JDBC_URL),
is("jdbc:mysql://localhost:3306/config"));
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.USERNAME),
is("root"));
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.PASSWORD),
is("secret"));
+ }
+
+ private Properties createProperties() {
+ return PropertiesBuilder.build(
+ new Property(JDBCRepositoryPropertyKey.PROVIDER.getKey(),
"MySQL"),
+ new Property(JDBCRepositoryPropertyKey.JDBC_URL.getKey(),
"jdbc:mysql://localhost:3306/config"),
+ new Property(JDBCRepositoryPropertyKey.USERNAME.getKey(),
"root"),
+ new Property(JDBCRepositoryPropertyKey.PASSWORD.getKey(),
"secret"));
+ }
+
+ @Test
+ void assertGetDefaultValue() {
+ JDBCRepositoryProperties actual = new JDBCRepositoryProperties(new
Properties());
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.PROVIDER),
is("H2"));
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.JDBC_URL),
is("jdbc:h2:mem:config;DB_CLOSE_DELAY=0;DATABASE_TO_UPPER=false;MODE=MYSQL"));
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.USERNAME),
is("sa"));
+ assertThat(actual.getValue(JDBCRepositoryPropertyKey.PASSWORD),
is(""));
+ }
+}