This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 c7b7e4df9a6 Remove
DataSourcePoolPropertiesCreator.createFromConfiguration() (#28051)
c7b7e4df9a6 is described below
commit c7b7e4df9a603513e8f7a98179013a9e54b0ef74
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 12 16:23:16 2023 +0800
Remove DataSourcePoolPropertiesCreator.createFromConfiguration() (#28051)
* Remove DataSourcePoolPropertiesCreator.createFromConfiguration()
* Remove DataSourcePoolPropertiesCreator.createFromConfiguration()
* Remove DataSourcePoolPropertiesCreator.createFromConfiguration()
* Remove DataSourcePoolPropertiesCreator.createFromConfiguration()
* Remove DataSourcePoolPropertiesCreator.createFromConfiguration()
* Remove DataSourcePoolPropertiesCreator.createFromConfiguration()
---
.../DataSourceGeneratedDatabaseConfiguration.java | 6 ++-
.../database/resource/ResourceMetaData.java | 5 +-
.../props/DataSourcePoolPropertiesCreator.java | 23 +-------
.../props/DataSourcePoolPropertiesCreatorTest.java | 62 +++++++++++++---------
.../swapper/YamlProxyConfigurationSwapper.java | 6 ++-
.../ExportDatabaseConfigurationExecutorTest.java | 7 ++-
.../ral/queryable/ExportMetaDataExecutorTest.java | 8 ++-
7 files changed, 63 insertions(+), 54 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java
index 5430af71127..f8019f62f85 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfiguration.java
@@ -28,7 +28,10 @@ import
org.apache.shardingsphere.infra.datasource.storage.StorageResource;
import javax.sql.DataSource;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
/**
* Data source generated database configuration.
@@ -44,7 +47,8 @@ public final class DataSourceGeneratedDatabaseConfiguration
implements DatabaseC
public DataSourceGeneratedDatabaseConfiguration(final Map<String,
DataSourceConfiguration> dataSourceConfigs, final Collection<RuleConfiguration>
ruleConfigs) {
ruleConfigurations = ruleConfigs;
- dataSourcePoolPropertiesMap =
DataSourcePoolPropertiesCreator.createFromConfiguration(dataSourceConfigs);
+ dataSourcePoolPropertiesMap = dataSourceConfigs.entrySet().stream()
+ .collect(Collectors.toMap(Entry::getKey, entry ->
DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue,
currentValue) -> oldValue, LinkedHashMap::new));
this.storageResource =
DataSourcePoolCreator.createStorageResource(dataSourcePoolPropertiesMap);
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
index a4fd7a9f57e..ca302d2b80e 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
@@ -29,6 +29,7 @@ import
org.apache.shardingsphere.infra.datasource.storage.StorageResourceUtils;
import javax.sql.DataSource;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
@@ -51,7 +52,9 @@ public final class ResourceMetaData {
public ResourceMetaData(final String databaseName, final Map<String,
DataSource> dataSources) {
storageNodeDataSources =
StorageResourceUtils.getStorageNodeDataSources(dataSources);
storageUnitMetaData = new StorageUnitMetaData(databaseName,
storageNodeDataSources,
- DataSourcePoolPropertiesCreator.create(dataSources),
StorageResourceUtils.getStorageUnitNodeMappers(dataSources));
+ dataSources.entrySet().stream()
+ .collect(Collectors.toMap(Entry::getKey, entry ->
DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue,
currentValue) -> oldValue, LinkedHashMap::new)),
+ StorageResourceUtils.getStorageUnitNodeMappers(dataSources));
}
public ResourceMetaData(final String databaseName, final StorageResource
storageResource, final Map<String, DataSourcePoolProperties> propsMap) {
diff --git
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreator.java
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreator.java
index a1130c4df38..2346f374ab5 100644
---
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreator.java
+++
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreator.java
@@ -19,10 +19,10 @@ package
org.apache.shardingsphere.infra.datasource.pool.props;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.datasource.CatalogSwitchableDataSource;
import
org.apache.shardingsphere.infra.datasource.pool.config.ConnectionConfiguration;
import
org.apache.shardingsphere.infra.datasource.pool.config.DataSourceConfiguration;
import
org.apache.shardingsphere.infra.datasource.pool.config.PoolConfiguration;
-import org.apache.shardingsphere.infra.datasource.CatalogSwitchableDataSource;
import
org.apache.shardingsphere.infra.datasource.pool.creator.DataSourceReflection;
import
org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
import
org.apache.shardingsphere.infra.datasource.pool.props.custom.CustomDataSourcePoolProperties;
@@ -36,7 +36,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Properties;
-import java.util.stream.Collectors;
/**
* Data source pool properties creator.
@@ -44,16 +43,6 @@ import java.util.stream.Collectors;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DataSourcePoolPropertiesCreator {
- /**
- * Create data source pool properties.
- *
- * @param configs data source configurations
- * @return created data source pool properties
- */
- public static Map<String, DataSourcePoolProperties>
createFromConfiguration(final Map<String, DataSourceConfiguration> configs) {
- return
configs.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry ->
create(entry.getValue()), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new));
- }
-
/**
* Create data source properties.
*
@@ -64,16 +53,6 @@ public final class DataSourcePoolPropertiesCreator {
return new
DataSourcePoolProperties(config.getConnection().getDataSourceClassName(),
createProperties(config));
}
- /**
- * Create data source properties.
- *
- * @param dataSources data sources
- * @return created data source properties
- */
- public static Map<String, DataSourcePoolProperties> create(final
Map<String, DataSource> dataSources) {
- return
dataSources.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry
-> create(entry.getValue()), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new));
- }
-
/**
* Create data source properties.
*
diff --git
a/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreatorTest.java
b/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreatorTest.java
index 14b5ce5ef07..ab816f8274d 100644
---
a/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreatorTest.java
+++
b/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesCreatorTest.java
@@ -43,11 +43,11 @@ class DataSourcePoolPropertiesCreatorTest {
@Test
void assertCreateWithDataSourceConfiguration() {
-
assertParameter(DataSourcePoolPropertiesCreator.create(createResourceConfiguration()));
+
assertParameter(DataSourcePoolPropertiesCreator.create(createDataSourceConfiguration()));
}
- private DataSourceConfiguration createResourceConfiguration() {
- ConnectionConfiguration connectionConfig = new
ConnectionConfiguration("com.zaxxer.hikari.HikariDataSource",
"jdbc:mysql://localhost:3306/demo_ds", "root", "root");
+ private DataSourceConfiguration createDataSourceConfiguration() {
+ ConnectionConfiguration connectionConfig = new
ConnectionConfiguration(MockedDataSource.class.getName(),
"jdbc:mock://127.0.0.1/foo_ds", "root", "root");
PoolConfiguration poolConfig = new PoolConfiguration(null, null, null,
null, null, null, null);
return new DataSourceConfiguration(connectionConfig, poolConfig);
}
@@ -55,8 +55,8 @@ class DataSourcePoolPropertiesCreatorTest {
private void assertParameter(final DataSourcePoolProperties actual) {
Map<String, Object> props = actual.getAllLocalProperties();
assertThat(props.size(), is(10));
- assertThat(props.get("dataSourceClassName"),
is("com.zaxxer.hikari.HikariDataSource"));
- assertThat(props.get("url"),
is("jdbc:mysql://localhost:3306/demo_ds"));
+ assertThat(props.get("dataSourceClassName"),
is(MockedDataSource.class.getName()));
+ assertThat(props.get("url"), is("jdbc:mock://127.0.0.1/foo_ds"));
assertThat(props.get("username"), is("root"));
assertThat(props.get("password"), is("root"));
assertNull(props.get("maximumPoolSize"));
@@ -71,19 +71,6 @@ class DataSourcePoolPropertiesCreatorTest {
assertThat(DataSourcePoolPropertiesCreator.create(createDataSource()),
is(new DataSourcePoolProperties(MockedDataSource.class.getName(),
createProperties())));
}
- @Test
- void assertCreateConfiguration() {
- DataSourcePoolProperties dataSourcePoolProperties =
mock(DataSourcePoolProperties.class);
- ConnectionPropertySynonyms connectionPropertySynonyms = new
ConnectionPropertySynonyms(createStandardProperties(),
createPropertySynonyms());
- PoolPropertySynonyms poolPropertySynonyms = new
PoolPropertySynonyms(createStandardProperties(), createPropertySynonyms());
- CustomDataSourcePoolProperties customDataSourcePoolProperties = new
CustomDataSourcePoolProperties(createProperties(),
- Arrays.asList("username", "password", "closed"),
Collections.singletonList("closed"), Collections.singletonMap("username",
"user"));
-
when(dataSourcePoolProperties.getConnectionPropertySynonyms()).thenReturn(connectionPropertySynonyms);
-
when(dataSourcePoolProperties.getPoolPropertySynonyms()).thenReturn(poolPropertySynonyms);
-
when(dataSourcePoolProperties.getCustomProperties()).thenReturn(customDataSourcePoolProperties);
-
DataSourcePoolPropertiesCreator.createConfiguration(dataSourcePoolProperties);
- }
-
private DataSource createDataSource() {
MockedDataSource result = new MockedDataSource();
result.setDriverClassName(MockedDataSource.class.getName());
@@ -93,14 +80,17 @@ class DataSourcePoolPropertiesCreatorTest {
return result;
}
- private Map<String, Object> createProperties() {
- Map<String, Object> result = new HashMap<>();
- result.put("driverClassName", MockedDataSource.class.getName());
- result.put("url", "jdbc:mock://127.0.0.1/foo_ds");
- result.put("username", "root");
- result.put("password", "root");
- result.put("maximumPoolSize", "-1");
- return result;
+ @Test
+ void assertCreateConfiguration() {
+ DataSourcePoolProperties props = mock(DataSourcePoolProperties.class);
+ ConnectionPropertySynonyms connectionPropSynonyms = new
ConnectionPropertySynonyms(createStandardProperties(),
createPropertySynonyms());
+ PoolPropertySynonyms poolPropSynonyms = new
PoolPropertySynonyms(createStandardProperties(), createPropertySynonyms());
+ CustomDataSourcePoolProperties customProps = new
CustomDataSourcePoolProperties(createProperties(),
+ Arrays.asList("username", "password", "closed"),
Collections.singletonList("closed"), Collections.singletonMap("username",
"user"));
+
when(props.getConnectionPropertySynonyms()).thenReturn(connectionPropSynonyms);
+ when(props.getPoolPropertySynonyms()).thenReturn(poolPropSynonyms);
+ when(props.getCustomProperties()).thenReturn(customProps);
+
assertPoolConfiguration(DataSourcePoolPropertiesCreator.createConfiguration(props).getPool());
}
private Map<String, Object> createStandardProperties() {
@@ -123,4 +113,24 @@ class DataSourcePoolPropertiesCreatorTest {
result.put("minPoolSize", "minimumIdle");
return result;
}
+
+ private Map<String, Object> createProperties() {
+ Map<String, Object> result = new HashMap<>();
+ result.put("driverClassName", MockedDataSource.class.getName());
+ result.put("url", "jdbc:mock://127.0.0.1/foo_ds");
+ result.put("username", "root");
+ result.put("password", "root");
+ result.put("maximumPoolSize", "-1");
+ return result;
+ }
+
+ private static void assertPoolConfiguration(final PoolConfiguration
actual) {
+ assertThat(actual.getIdleTimeoutMilliseconds(), is(180000L));
+ assertThat(actual.getMaxLifetimeMilliseconds(), is(180000L));
+ assertThat(actual.getMaxPoolSize(), is(30));
+ assertThat(actual.getMinPoolSize(), is(10));
+ assertThat(actual.getCustomProperties().get("driverClassName"),
is(MockedDataSource.class.getName()));
+ assertThat(actual.getCustomProperties().get("url"),
is("jdbc:mock://127.0.0.1/foo_ds"));
+ assertThat(actual.getCustomProperties().get("maximumPoolSize"),
is("-1"));
+ }
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapper.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapper.java
index 1be11bde6b5..e1e8594cddf 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapper.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapper.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.config.database.impl.DataSourceGeneratedD
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.datasource.pool.config.DataSourceConfiguration;
import
org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
+import
org.apache.shardingsphere.infra.datasource.pool.props.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.datasource.pool.props.DataSourcePoolPropertiesCreator;
import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.backend.config.ProxyConfiguration;
@@ -36,6 +37,7 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.stream.Collectors;
/**
* YAML proxy configuration swapper.
@@ -66,7 +68,9 @@ public final class YamlProxyConfigurationSwapper {
private Map<String, DataSource> swapDataSources(final Map<String,
YamlProxyDataSourceConfiguration> yamlDataSourceConfigs) {
Map<String, DataSourceConfiguration> dataSourceConfigs =
swapDataSourceConfigurations(yamlDataSourceConfigs);
- return
DataSourcePoolCreator.create(DataSourcePoolPropertiesCreator.createFromConfiguration(dataSourceConfigs));
+ Map<String, DataSourcePoolProperties> propsMap =
dataSourceConfigs.entrySet().stream()
+ .collect(Collectors.toMap(Entry::getKey, entry ->
DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue,
currentValue) -> oldValue, LinkedHashMap::new));
+ return DataSourcePoolCreator.create(propsMap);
}
private Map<String, DatabaseConfiguration>
swapDatabaseConfigurations(final Map<String, YamlProxyDatabaseConfiguration>
databaseConfigurations) {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
index 9bde4ffd498..bc890c625a5 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ExportDatabaseConfigurationStatement;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import
org.apache.shardingsphere.infra.datasource.pool.props.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.datasource.pool.props.DataSourcePoolPropertiesCreator;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -43,8 +44,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
+import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -66,7 +69,9 @@ class ExportDatabaseConfigurationExecutorTest {
@Test
void assertExecute() {
when(database.getName()).thenReturn("normal_db");
-
when(database.getResourceMetaData().getStorageUnitMetaData().getDataSourcePoolPropertiesMap()).thenReturn(DataSourcePoolPropertiesCreator.create(createDataSourceMap()));
+ Map<String, DataSourcePoolProperties> propsMap =
createDataSourceMap().entrySet().stream()
+ .collect(Collectors.toMap(Entry::getKey, entry ->
DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue,
currentValue) -> oldValue, LinkedHashMap::new));
+
when(database.getResourceMetaData().getStorageUnitMetaData().getDataSourcePoolPropertiesMap()).thenReturn(propsMap);
when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createShardingRuleConfiguration()));
Collection<LocalDataQueryResultRow> actual = new
ExportDatabaseConfigurationExecutor().getRows(database, new
ExportDatabaseConfigurationStatement(mock(DatabaseSegment.class), null));
assertThat(actual.size(), is(1));
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java
index 5005b20fa27..13f0dc6c51b 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutorTest.java
@@ -27,6 +27,7 @@ import
org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import
org.apache.shardingsphere.infra.datasource.pool.props.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.datasource.pool.props.DataSourcePoolPropertiesCreator;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -67,8 +68,10 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
+import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -130,8 +133,9 @@ class ExportMetaDataExecutorTest {
void assertExecute() {
when(database.getName()).thenReturn("normal_db");
when(database.getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singleton("empty_metadata"));
- Map<String, DataSource> dataSourceMap = createDataSourceMap();
-
when(database.getResourceMetaData().getStorageUnitMetaData().getDataSourcePoolPropertiesMap()).thenReturn(DataSourcePoolPropertiesCreator.create(dataSourceMap));
+ Map<String, DataSourcePoolProperties> propsMap =
createDataSourceMap().entrySet().stream()
+ .collect(Collectors.toMap(Entry::getKey, entry ->
DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue,
currentValue) -> oldValue, LinkedHashMap::new));
+
when(database.getResourceMetaData().getStorageUnitMetaData().getDataSourcePoolPropertiesMap()).thenReturn(propsMap);
when(database.getRuleMetaData().getConfigurations()).thenReturn(Collections.emptyList());
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);