Skip to content

Commit

Permalink
Refactor StorageUnit to use CatalogSwitchableDataSource only necessary (
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jun 17, 2024
1 parent 9485f48 commit faf3f24
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public StorageUnit(final StorageNode storageNode, final DataSourcePoolProperties
storageType = DatabaseTypeFactory.get(url);
boolean isInstanceConnectionAvailable = new DatabaseTypeRegistry(DatabaseTypeFactory.get(url)).getDialectDatabaseMetaData().isInstanceConnectionAvailable();
catalog = isInstanceConnectionAvailable ? new StandardJdbcUrlParser().parse(url).getDatabase() : null;
this.dataSource = new CatalogSwitchableDataSource(dataSource, catalog, url);
this.dataSourcePoolProperties = dataSourcePoolProps;
this.dataSource = isInstanceConnectionAvailable ? new CatalogSwitchableDataSource(dataSource, catalog, url) : dataSource;
dataSourcePoolProperties = dataSourcePoolProps;
connectionProperties = createConnectionProperties(standardProps);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.config.database.impl;

import com.zaxxer.hikari.HikariDataSource;
import org.apache.shardingsphere.infra.datasource.pool.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;
Expand All @@ -43,8 +42,7 @@ class DataSourceGeneratedDatabaseConfigurationTest {
void assertGetDataSources() {
DataSourceGeneratedDatabaseConfiguration databaseConfig = createDataSourceGeneratedDatabaseConfiguration();
DataSource dataSource = databaseConfig.getStorageUnits().get("normal_db").getDataSource();
assertTrue(dataSource instanceof CatalogSwitchableDataSource);
assertTrue(((CatalogSwitchableDataSource) dataSource).getDataSource() instanceof HikariDataSource);
assertTrue(dataSource instanceof HikariDataSource);
}

@Test
Expand All @@ -60,8 +58,7 @@ void assertGetStorageNodes() {
void assertGetStorageUnits() {
DataSourceGeneratedDatabaseConfiguration databaseConfig = createDataSourceGeneratedDatabaseConfiguration();
DataSource dataSource = databaseConfig.getStorageUnits().get("normal_db").getDataSource();
assertTrue(dataSource instanceof CatalogSwitchableDataSource);
assertTrue(((CatalogSwitchableDataSource) dataSource).getDataSource() instanceof HikariDataSource);
assertTrue(dataSource instanceof HikariDataSource);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shardingsphere.infra.config.database.impl;

import org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource;
import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
Expand All @@ -38,8 +37,7 @@ class DataSourceProvidedDatabaseConfigurationTest {
void assertGetDataSources() {
DataSourceProvidedDatabaseConfiguration databaseConfig = createDataSourceProvidedDatabaseConfiguration();
DataSource dataSource = databaseConfig.getStorageUnits().get("foo_ds").getDataSource();
assertTrue(dataSource instanceof CatalogSwitchableDataSource);
assertTrue(((CatalogSwitchableDataSource) dataSource).getDataSource() instanceof MockedDataSource);
assertTrue(dataSource instanceof MockedDataSource);
}

@Test
Expand All @@ -55,8 +53,7 @@ void assertGetStorageNodes() {
void assertGetStorageUnits() {
DataSourceProvidedDatabaseConfiguration databaseConfig = createDataSourceProvidedDatabaseConfiguration();
DataSource dataSource = databaseConfig.getStorageUnits().get("foo_ds").getDataSource();
assertTrue(dataSource instanceof CatalogSwitchableDataSource);
assertTrue(((CatalogSwitchableDataSource) dataSource).getDataSource() instanceof MockedDataSource);
assertTrue(dataSource instanceof MockedDataSource);
}

@Test
Expand Down

0 comments on commit faf3f24

Please sign in to comment.