This is an automated email from the ASF dual-hosted git repository.
yx9o 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 fd5fcdcc2c2 Reuse PropertiesBuilder (#36260)
fd5fcdcc2c2 is described below
commit fd5fcdcc2c29116c48041258cb668f5aaa966334
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Aug 12 09:03:03 2025 +0800
Reuse PropertiesBuilder (#36260)
* Reuse PropertiesBuilder
* Reuse PropertiesBuilder
* Reuse PropertiesBuilder
---
.../YamlPluginsConfigurationSwapperTest.java | 2 +-
.../ClassBasedShardingAlgorithmFactory.java | 7 +++---
.../DataMatchTableDataConsistencyCheckerTest.java | 25 ++++++----------------
.../ImportDatabaseConfigurationExecutorTest.java | 12 ++++-------
4 files changed, 15 insertions(+), 31 deletions(-)
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
index 6a9bc2332bf..c8289490e49 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
@@ -123,7 +123,7 @@ class YamlPluginsConfigurationSwapperTest {
private Properties createProperties() {
Properties result = new Properties();
- result.put("key", "value");
+ result.setProperty("key", "value");
return result;
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java
index 83a9beb35a1..89c0bc8f48a 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java
@@ -65,11 +65,10 @@ public final class ClassBasedShardingAlgorithmFactory {
ClassBasedShardingAlgorithmFactory.class.getClassLoader(),
ClassLoader.getSystemClassLoader()
};
-
- for (ClassLoader cl : classLoaders) {
- if (null != cl) {
+ for (ClassLoader each : classLoaders) {
+ if (null != each) {
try {
- return Class.forName(className, true, cl);
+ return Class.forName(className, true, each);
} catch (final ClassNotFoundException ex) {
// Try next classloader
}
diff --git
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/DataMatchTableDataConsistencyCheckerTest.java
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/DataMatchTableDataConsistencyCheckerTest.java
index 7857bfdcd17..80fa678a5af 100644
---
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/DataMatchTableDataConsistencyCheckerTest.java
+++
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/DataMatchTableDataConsistencyCheckerTest.java
@@ -19,11 +19,12 @@ package
org.apache.shardingsphere.data.pipeline.core.consistencycheck.table;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.data.pipeline.core.exception.param.PipelineInvalidParameterException;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import org.mockito.internal.configuration.plugins.Plugins;
import java.util.Arrays;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -36,7 +37,7 @@ class DataMatchTableDataConsistencyCheckerTest {
void assertChunkSizeInitSuccess() {
for (String each : Arrays.asList("1", "1000")) {
DataMatchTableDataConsistencyChecker checker = new
DataMatchTableDataConsistencyChecker();
- checker.init(buildChunkSizeProperties(each));
+ checker.init(PropertiesBuilder.build(new Property("chunk-size",
each)));
String actual =
Plugins.getMemberAccessor().get(DataMatchTableDataConsistencyChecker.class.getDeclaredField("chunkSize"),
checker).toString();
assertThat(actual, is(each));
}
@@ -44,9 +45,9 @@ class DataMatchTableDataConsistencyCheckerTest {
@Test
void assertChunkSizeInitFailure() {
- assertThrows(PipelineInvalidParameterException.class, () -> new
DataMatchTableDataConsistencyChecker().init(buildChunkSizeProperties("xyz")));
+ assertThrows(PipelineInvalidParameterException.class, () -> new
DataMatchTableDataConsistencyChecker().init(PropertiesBuilder.build(new
Property("chunk-size", "xyz"))));
for (String each : Arrays.asList("0", "-1")) {
- assertThrows(PipelineInvalidParameterException.class, () -> new
DataMatchTableDataConsistencyChecker().init(buildChunkSizeProperties(each)));
+ assertThrows(PipelineInvalidParameterException.class, () -> new
DataMatchTableDataConsistencyChecker().init(PropertiesBuilder.build(new
Property("chunk-size", each))));
}
}
@@ -55,7 +56,7 @@ class DataMatchTableDataConsistencyCheckerTest {
void assertStreamingRangeTypeInitSuccess() {
for (String each : Arrays.asList("small", "large", "SMALL", "LARGE")) {
DataMatchTableDataConsistencyChecker checker = new
DataMatchTableDataConsistencyChecker();
- checker.init(buildStreamingRangeTypeProperties(each));
+ checker.init(PropertiesBuilder.build(new
Property("streaming-range-type", each)));
String actual =
Plugins.getMemberAccessor().get(DataMatchTableDataConsistencyChecker.class.getDeclaredField("streamingRangeType"),
checker).toString();
assertThat(actual, is(each.toUpperCase()));
}
@@ -63,18 +64,6 @@ class DataMatchTableDataConsistencyCheckerTest {
@Test
void assertStreamingRangeTypeInitFailure() {
- assertThrows(PipelineInvalidParameterException.class, () -> new
DataMatchTableDataConsistencyChecker().init(buildStreamingRangeTypeProperties("xyz")));
- }
-
- private Properties buildChunkSizeProperties(final String chunkSize) {
- Properties result = new Properties();
- result.put("chunk-size", chunkSize);
- return result;
- }
-
- private Properties buildStreamingRangeTypeProperties(final String
streamingRangeType) {
- Properties result = new Properties();
- result.put("streaming-range-type", streamingRangeType);
- return result;
+ assertThrows(PipelineInvalidParameterException.class, () -> new
DataMatchTableDataConsistencyChecker().init(PropertiesBuilder.build(new
Property("streaming-range-type", "xyz"))));
}
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportDatabaseConfigurationExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportDatabaseConfigurationExecutorTest.java
index 51c38a7835c..e8660c7f3e8 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportDatabaseConfigurationExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/imports/ImportDatabaseConfigurationExecutorTest.java
@@ -30,6 +30,8 @@ import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUn
import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
import
org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.test.infra.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.Test;
@@ -40,7 +42,6 @@ import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
-import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -128,13 +129,8 @@ class ImportDatabaseConfigurationExecutorTest {
when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.emptyList());
when(result.getMetaDataContexts().getMetaData().getAllDatabases()).thenReturn(Collections.singleton(database));
when(result.getMetaDataContexts().getMetaData().getDatabase(databaseName)).thenReturn(database);
-
when(result.getMetaDataContexts().getMetaData().getProps()).thenReturn(new
ConfigurationProperties(createProperties()));
- return result;
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
-
result.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(),
"MySQL");
+ when(result.getMetaDataContexts().getMetaData().getProps()).thenReturn(
+ new ConfigurationProperties(PropertiesBuilder.build(new
Property(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(),
"MySQL"))));
return result;
}
}