diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java index 15ebbdf3ce7d9..4fcdd47cfe965 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java @@ -54,7 +54,12 @@ public final class DatabaseTypeEngine { * @return protocol type */ public static DatabaseType getProtocolType(final String databaseName, final DatabaseConfiguration databaseConfig, final ConfigurationProperties props) { - return findConfiguredDatabaseType(props).orElseGet(() -> getStorageType(DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, databaseConfig))); + Optional configuredDatabaseType = findConfiguredDatabaseType(props); + if (configuredDatabaseType.isPresent()) { + return configuredDatabaseType.get(); + } + Collection enabledDataSources = DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, databaseConfig); + return enabledDataSources.isEmpty() ? getDefaultStorageType() : getStorageType(enabledDataSources.iterator().next()); } /** @@ -66,7 +71,11 @@ public static DatabaseType getProtocolType(final String databaseName, final Data */ public static DatabaseType getProtocolType(final Map databaseConfigs, final ConfigurationProperties props) { Optional configuredDatabaseType = findConfiguredDatabaseType(props); - return configuredDatabaseType.orElseGet(() -> getStorageType(getEnabledDataSources(databaseConfigs).values())); + if (configuredDatabaseType.isPresent()) { + return configuredDatabaseType.get(); + } + Map enabledDataSources = getEnabledDataSources(databaseConfigs); + return enabledDataSources.isEmpty() ? getDefaultStorageType() : getStorageType(enabledDataSources.values().iterator().next()); } private static Optional findConfiguredDatabaseType(final ConfigurationProperties props) { @@ -101,18 +110,24 @@ public static Map getStorageTypes(final String databaseNam /** * Get storage type. * - * @param dataSources data sources + * @param dataSource data source * @return storage type + * @throws SQLWrapperException SQL wrapper exception */ - public static DatabaseType getStorageType(final Collection dataSources) { - return dataSources.isEmpty() ? TypedSPILoader.getService(DatabaseType.class, DEFAULT_DATABASE_TYPE) : getStorageType(dataSources.iterator().next()); - } - - private static DatabaseType getStorageType(final DataSource dataSource) { + public static DatabaseType getStorageType(final DataSource dataSource) { try (Connection connection = dataSource.getConnection()) { return DatabaseTypeFactory.get(connection.getMetaData().getURL()); } catch (final SQLException ex) { throw new SQLWrapperException(ex); } } + + /** + * Get default storage type. + * + * @return default storage type + */ + public static DatabaseType getDefaultStorageType() { + return TypedSPILoader.getService(DatabaseType.class, DEFAULT_DATABASE_TYPE); + } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java index 05c9be7e8b852..ebaec412936e1 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java @@ -18,11 +18,11 @@ package org.apache.shardingsphere.infra.metadata.database.resource.unit; import lombok.Getter; -import org.apache.shardingsphere.infra.database.DatabaseTypeEngine; import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser; import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory; import org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; @@ -52,15 +52,11 @@ public StorageUnit(final String databaseName, final StorageNode storageNode, fin this.storageNode = storageNode; this.dataSource = new CatalogSwitchableDataSource(dataSource, storageNode.getCatalog(), storageNode.getUrl()); this.dataSourcePoolProperties = dataSourcePoolProperties; + storageType = DatabaseTypeFactory.get(storageNode.getUrl()); boolean isDataSourceEnabled = !DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, Collections.singletonMap(storageNode.getName().getName(), dataSource)).isEmpty(); - storageType = createStorageType(isDataSourceEnabled); connectionProperties = createConnectionProperties(isDataSourceEnabled, storageNode); } - private DatabaseType createStorageType(final boolean isDataSourceEnabled) { - return DatabaseTypeEngine.getStorageType(isDataSourceEnabled ? Collections.singleton(dataSource) : Collections.emptyList()); - } - private ConnectionProperties createConnectionProperties(final boolean isDataSourceEnabled, final StorageNode storageNode) { if (!isDataSourceEnabled) { return null; diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java index b1709395bd3e2..6c62d5db1979a 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java @@ -24,8 +24,8 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType; import org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType; -import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException; +import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.util.PropertiesBuilder; @@ -35,8 +35,6 @@ import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Properties; @@ -76,29 +74,20 @@ void assertGetStorageTypes() throws SQLException { } @Test - void assertGetStorageTypeWithEmptyDataSources() { - assertThat(DatabaseTypeEngine.getStorageType(Collections.emptyList()).getType(), is("MySQL")); - } - - @Test - void assertGetStorageTypeWithDataSources() throws SQLException { - Collection dataSources = Arrays.asList(mockDataSource(TypedSPILoader.getService(DatabaseType.class, "H2")), - mockDataSource(TypedSPILoader.getService(DatabaseType.class, "H2"))); - assertThat(DatabaseTypeEngine.getStorageType(dataSources).getType(), is("H2")); - } - - @Test - void assertGetStorageTypeWithDifferentDataSourceTypes() throws SQLException { - Collection dataSources = Arrays.asList(mockDataSource(TypedSPILoader.getService(DatabaseType.class, "H2")), - mockDataSource(TypedSPILoader.getService(DatabaseType.class, "MySQL"))); - assertThat(DatabaseTypeEngine.getStorageType(dataSources).getType(), is("H2")); + void assertGetStorageType() throws SQLException { + assertThat(DatabaseTypeEngine.getStorageType(mockDataSource(TypedSPILoader.getService(DatabaseType.class, "H2"))).getType(), is("H2")); } @Test void assertGetStorageTypeWhenGetConnectionError() throws SQLException { DataSource dataSource = mock(DataSource.class); when(dataSource.getConnection()).thenThrow(SQLException.class); - assertThrows(SQLWrapperException.class, () -> DatabaseTypeEngine.getStorageType(Collections.singleton(dataSource))); + assertThrows(SQLWrapperException.class, () -> DatabaseTypeEngine.getStorageType(dataSource)); + } + + @Test + void assertGetDefaultStorageTypeWithEmptyDataSources() { + assertThat(DatabaseTypeEngine.getDefaultStorageType().getType(), is("MySQL")); } private DataSource mockDataSource(final DatabaseType databaseType) throws SQLException { diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java index 9ab0a33b43610..648a04dd11eaf 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.identifier.type.ResourceHeldRule; @@ -91,7 +92,7 @@ private ShardingSphereDatabase mockDatabase(final ResourceMetaData resourceMetaD when(result.getResourceMetaData()).thenReturn(resourceMetaData); DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - StorageUnit storageUnit = new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, dataSource); + StorageUnit storageUnit = new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_ds"), dataSourcePoolProps, dataSource); when(result.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("foo_db", storageUnit)); when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(databaseResourceHeldRule))); return result; diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java index 0e1e867ea3ebd..3da384338220d 100644 --- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java +++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java @@ -29,7 +29,6 @@ import org.apache.shardingsphere.transaction.spi.TransactionHook; import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -52,7 +51,7 @@ public GlobalClockRule(final GlobalClockRuleConfiguration ruleConfig, final Map< private Properties createProperties(final Map databases) { Properties result = new Properties(); - DatabaseType storageType = findStorageType(databases.values()).orElseGet(() -> DatabaseTypeEngine.getStorageType(Collections.emptyList())); + DatabaseType storageType = findStorageType(databases.values()).orElseGet(DatabaseTypeEngine::getDefaultStorageType); result.setProperty("trunkType", storageType.getTrunkDatabaseType().orElse(storageType).getType()); result.setProperty("enabled", String.valueOf(configuration.isEnabled())); result.setProperty("type", configuration.getType()); diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java index e0a596a443547..3f427d2d94bea 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java @@ -63,7 +63,7 @@ private Collection decorateTables(final String databaseName, final Map enabledDataSources = DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, dataSources); Map aggregatedDataSources = SingleTableLoadUtils.getAggregatedDataSourceMap(enabledDataSources, builtRules); - DatabaseType databaseType = DatabaseTypeEngine.getStorageType(enabledDataSources.values()); + DatabaseType databaseType = enabledDataSources.isEmpty() ? DatabaseTypeEngine.getDefaultStorageType() : DatabaseTypeEngine.getStorageType(enabledDataSources.values().iterator().next()); Collection excludedTables = SingleTableLoadUtils.getExcludedTables(builtRules); Map> actualDataNodes = SingleTableDataNodeLoader.load(databaseName, databaseType, aggregatedDataSources, excludedTables); Collection configuredDataNodes = SingleTableLoadUtils.convertToDataNodes(databaseName, databaseType, splitTables); diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java index 9394b796bcb16..871e2ce917274 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java @@ -79,7 +79,7 @@ public SingleRule(final SingleRuleConfiguration ruleConfig, final String databas Map enabledDataSources = DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, dataSourceMap); Map aggregateDataSourceMap = SingleTableLoadUtils.getAggregatedDataSourceMap(enabledDataSources, builtRules); dataSourceNames = aggregateDataSourceMap.keySet(); - databaseType = DatabaseTypeEngine.getStorageType(enabledDataSources.values()); + databaseType = enabledDataSources.isEmpty() ? DatabaseTypeEngine.getDefaultStorageType() : DatabaseTypeEngine.getStorageType(enabledDataSources.values().iterator().next()); singleTableDataNodes = SingleTableDataNodeLoader.load(databaseName, databaseType, aggregateDataSourceMap, builtRules, configuration.getTables()); singleTableDataNodes.forEach((key, value) -> tableNamesMapper.put(value.iterator().next().getTableName())); } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java index 89ab0a1c04e15..115a0b4796fe7 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; @@ -150,8 +151,8 @@ private ShardingSphereDatabase mockDatabaseWithMultipleResources() { Map storageUnits = new HashMap<>(2, 1F); DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - storageUnits.put("ds_0", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); - storageUnits.put("ds_1", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_0", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(result.getResourceMetaData().getStorageUnits()).thenReturn(storageUnits); when(result.getName()).thenReturn(DefaultDatabase.LOGIC_NAME); diff --git a/kernel/time-service/type/database/src/main/java/org/apache/shardingsphere/timeservice/type/database/DatabaseTimestampService.java b/kernel/time-service/type/database/src/main/java/org/apache/shardingsphere/timeservice/type/database/DatabaseTimestampService.java index 5dea456923c49..375f89607f1c5 100644 --- a/kernel/time-service/type/database/src/main/java/org/apache/shardingsphere/timeservice/type/database/DatabaseTimestampService.java +++ b/kernel/time-service/type/database/src/main/java/org/apache/shardingsphere/timeservice/type/database/DatabaseTimestampService.java @@ -17,10 +17,10 @@ package org.apache.shardingsphere.timeservice.type.database; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.database.DatabaseTypeEngine; -import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator; import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator; import org.apache.shardingsphere.infra.yaml.config.swapper.resource.YamlDataSourceConfigurationSwapper; import org.apache.shardingsphere.timeservice.spi.TimestampService; import org.apache.shardingsphere.timeservice.type.database.exception.DatetimeLoadingException; @@ -32,7 +32,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; -import java.util.Collections; import java.util.Map.Entry; import java.util.Properties; import java.util.stream.Collectors; @@ -50,7 +49,7 @@ public final class DatabaseTimestampService implements TimestampService { public void init(final Properties props) { dataSource = DataSourcePoolCreator.create(new YamlDataSourceConfigurationSwapper().swapToDataSourcePoolProperties( props.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().toString(), Entry::getValue)))); - storageType = DatabaseTypeEngine.getStorageType(Collections.singleton(dataSource)); + storageType = DatabaseTypeEngine.getStorageType(dataSource); } @Override diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java index 26c60d314a7dd..2119a6a44bff7 100644 --- a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java +++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.transaction.api.TransactionType; @@ -101,8 +102,8 @@ private ResourceMetaData createResourceMetaData() { Map storageUnits = new HashMap<>(2, 1F); DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - storageUnits.put("ds_0", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); - storageUnits.put("ds_1", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_0", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); when(result.getStorageUnits()).thenReturn(storageUnits); return result; @@ -120,8 +121,8 @@ private ResourceMetaData createAddResourceMetaData() { Map storageUnits = new HashMap<>(2, 1F); DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - storageUnits.put("ds_0", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); - storageUnits.put("ds_1", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_0", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); when(result.getStorageUnits()).thenReturn(storageUnits); return result; diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index 40618dfe302ab..bd434f5ced700 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -110,7 +110,7 @@ private ShardingSphereDatabase mockDatabase() { DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); Map storageUnits = Collections.singletonMap("foo_ds", - new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); + new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, new MockedDataSource())); when(result.getResourceMetaData().getStorageUnits()).thenReturn(storageUnits); return result; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java index cabea9fe30c61..e065e8f69537f 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataUpdaterTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex; @@ -122,8 +123,8 @@ private Map createStorageUnits() { Map result = new LinkedHashMap<>(2, 1F); DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - result.put("ds_0", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); - result.put("ds_1", new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); + result.put("ds_0", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + result.put("ds_1", new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); return result; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java index 595399d049a34..66a438fadff12 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -87,7 +88,7 @@ void setUp() { resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - StorageUnit storageUnit = new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource()); + StorageUnit storageUnit = new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, new MockedDataSource()); when(resourceMetaData.getStorageUnits()).thenReturn(Collections.singletonMap("foo_ds", storageUnit)); when(database.getResourceMetaData()).thenReturn(resourceMetaData); contextManager = mockContextManager(); diff --git a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java index af353c44f4bec..4e0e48e543c08 100644 --- a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java +++ b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; +import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeName; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -85,7 +86,7 @@ private ResourceMetaData mockResourceMetaData(final String databaseProductName, DataSource dataSource = createDataSource(databaseProductName, databaseProductVersion); DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - StorageUnit storageUnit = new StorageUnit("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, dataSource); + StorageUnit storageUnit = new StorageUnit("foo_db", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, dataSource); when(result.getStorageUnits()).thenReturn(Collections.singletonMap("foo_ds", storageUnit)); return result; }