From d1bff24e9c627a7669c279d8c7b793d3eb85c1c2 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Thu, 5 Oct 2023 19:08:35 +0800 Subject: [PATCH 1/7] Remove databaseName on StorageUnit's constructor --- .../metadata/database/ShardingSphereDatabase.java | 6 +++--- .../database/resource/ResourceMetaData.java | 7 +++---- .../database/resource/unit/StorageUnit.java | 14 ++++---------- .../infra/metadata/ShardingSphereMetaDataTest.java | 2 +- .../single/route/SingleSQLRouterTest.java | 4 ++-- .../transaction/rule/TransactionRuleTest.java | 8 ++++---- .../context/ConfigurationContextManager.java | 2 +- .../mode/manager/ContextManagerTest.java | 5 ++--- .../YamlDatabaseConfigurationImportExecutor.java | 2 +- .../ral/updatable/ImportMetaDataUpdaterTest.java | 4 ++-- .../UnregisterStorageUnitBackendHandlerTest.java | 2 +- .../version/ShardingSphereProxyVersionTest.java | 2 +- 12 files changed, 25 insertions(+), 33 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java index 2af78880a553a..941f270b12ef1 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java @@ -121,13 +121,13 @@ public static ShardingSphereDatabase create(final String name, final DatabaseTyp */ public static ShardingSphereDatabase create(final String name, final DatabaseType protocolType, final DatabaseConfiguration databaseConfig, final Collection rules, final Map schemas) { - ResourceMetaData resourceMetaData = createResourceMetaData(name, databaseConfig.getStorageResource(), databaseConfig.getDataSourcePoolPropertiesMap()); + ResourceMetaData resourceMetaData = createResourceMetaData(databaseConfig.getStorageResource(), databaseConfig.getDataSourcePoolPropertiesMap()); RuleMetaData ruleMetaData = new RuleMetaData(rules); return new ShardingSphereDatabase(name, protocolType, resourceMetaData, ruleMetaData, schemas); } - private static ResourceMetaData createResourceMetaData(final String databaseName, final StorageResource storageResource, final Map propsMap) { - return new ResourceMetaData(databaseName, storageResource.getDataSources(), storageResource.getStorageUnitNodeMap(), propsMap); + private static ResourceMetaData createResourceMetaData(final StorageResource storageResource, final Map propsMap) { + return new ResourceMetaData(storageResource.getDataSources(), storageResource.getStorageUnitNodeMap(), propsMap); } /** 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 f2b2139c113ed..bd048bd62b70a 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 @@ -51,16 +51,15 @@ public ResourceMetaData(final Map dataSources) { Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); storageUnits = new LinkedHashMap<>(); for (Entry entry : storageNodes.entrySet()) { - storageUnits.put(entry.getKey(), new StorageUnit(null, entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSources.get(entry.getValue().getName().getName()))); + storageUnits.put(entry.getKey(), new StorageUnit(entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSources.get(entry.getValue().getName().getName()))); } } - public ResourceMetaData(final String databaseName, final Map dataSources, - final Map storageNodes, final Map dataSourcePoolPropsMap) { + public ResourceMetaData(final Map dataSources, final Map storageNodes, final Map dataSourcePoolPropsMap) { this.dataSources = dataSources; storageUnits = new LinkedHashMap<>(); for (Entry entry : storageNodes.entrySet()) { - storageUnits.put(entry.getKey(), new StorageUnit(databaseName, entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSources.get(entry.getValue().getName()))); + storageUnits.put(entry.getKey(), new StorageUnit(entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSources.get(entry.getValue().getName()))); } } 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 ebaec412936e1..202a391d91fa1 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 @@ -26,10 +26,8 @@ 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; -import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager; import javax.sql.DataSource; -import java.util.Collections; import java.util.Map; /** @@ -48,21 +46,17 @@ public final class StorageUnit { private final ConnectionProperties connectionProperties; - public StorageUnit(final String databaseName, final StorageNode storageNode, final DataSourcePoolProperties dataSourcePoolProperties, final DataSource dataSource) { + public StorageUnit(final StorageNode storageNode, final DataSourcePoolProperties dataSourcePoolProperties, final DataSource dataSource) { 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(); - connectionProperties = createConnectionProperties(isDataSourceEnabled, storageNode); + connectionProperties = createConnectionProperties(storageNode); } - private ConnectionProperties createConnectionProperties(final boolean isDataSourceEnabled, final StorageNode storageNode) { - if (!isDataSourceEnabled) { - return null; - } + private ConnectionProperties createConnectionProperties(final StorageNode storageNode) { Map standardProps = dataSourcePoolProperties.getConnectionPropertySynonyms().getStandardProperties(); ConnectionPropertiesParser parser = DatabaseTypedSPILoader.getService(ConnectionPropertiesParser.class, storageType); - return parser.parse(standardProps.getOrDefault("url", "").toString(), standardProps.getOrDefault("username", "").toString(), storageNode.getCatalog()); + return parser.parse(storageNode.getUrl(), standardProps.getOrDefault("username", "").toString(), storageNode.getCatalog()); } } 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 648a04dd11eaf..4a7105ba8cdec 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 @@ -92,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", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_ds"), dataSourcePoolProps, dataSource); + StorageUnit storageUnit = new StorageUnit(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/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 115a0b4796fe7..db5c95d2348e4 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 @@ -151,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", 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())); + storageUnits.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit(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/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 2119a6a44bff7..a03030c3e4a83 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 @@ -102,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", 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())); + storageUnits.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit(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; @@ -121,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", 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())); + storageUnits.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit(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/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java index bf51c6411a17b..2e38aeafa2706 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java @@ -283,7 +283,7 @@ public Map renewDatabase(final ShardingSphereDat Map propsMap = database.getResourceMetaData().getStorageUnits().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> currentValue, LinkedHashMap::new)); return Collections.singletonMap(database.getName().toLowerCase(), new ShardingSphereDatabase(database.getName(), database.getProtocolType(), - new ResourceMetaData(database.getName(), newStorageNodes, newStorageUnitNodeMap, propsMap), database.getRuleMetaData(), database.getSchemas())); + new ResourceMetaData(newStorageNodes, newStorageUnitNodeMap, propsMap), database.getRuleMetaData(), database.getSchemas())); } private Map getNewStorageNodes(final Map currentStorageNodes, final SwitchingResource resource) { 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 bd434f5ced700..dcae93b8f6c56 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", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, new MockedDataSource())); + new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, new MockedDataSource())); when(result.getResourceMetaData().getStorageUnits()).thenReturn(storageUnits); return result; } @@ -260,8 +260,7 @@ private ResourceMetaData createOriginalResource() { for (Entry entry : storageUnitNodeMap.entrySet()) { DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); - storageUnits.put(entry.getKey(), new StorageUnit( - "foo_db", storageUnitNodeMap.get(entry.getKey()), dataSourcePoolProps, storageNodeDataSourceMap.get(entry.getValue().getName()))); + storageUnits.put(entry.getKey(), new StorageUnit(storageUnitNodeMap.get(entry.getKey()), dataSourcePoolProps, storageNodeDataSourceMap.get(entry.getValue().getName()))); } ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); when(result.getStorageUnits()).thenReturn(storageUnits); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java index 9dc1f225d2466..a704756b65a48 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java @@ -164,7 +164,7 @@ private void addResources(final String databaseName, final Map toBeAddedStorageNode = StorageUnitNodeMapUtils.fromDataSourcePoolProperties(propsMap); for (Entry entry : propsMap.entrySet()) { - storageUnits.put(entry.getKey(), new StorageUnit(databaseName, toBeAddedStorageNode.get(entry.getKey()), entry.getValue(), DataSourcePoolCreator.create(entry.getValue()))); + storageUnits.put(entry.getKey(), new StorageUnit(toBeAddedStorageNode.get(entry.getKey()), entry.getValue(), DataSourcePoolCreator.create(entry.getValue()))); } } 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 e065e8f69537f..f5fd6da863809 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 @@ -123,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", 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())); + result.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); + result.put("ds_1", new StorageUnit(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 66a438fadff12..a5ecee1ea5ccc 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 @@ -88,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", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, new MockedDataSource()); + StorageUnit storageUnit = new StorageUnit(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 4e0e48e543c08..8847fefceb466 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 @@ -86,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", new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, dataSource); + StorageUnit storageUnit = new StorageUnit(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; } From e7a0ced89f7535fad6c4c3ce6032414210052c9f Mon Sep 17 00:00:00 2001 From: zhangliang Date: Thu, 5 Oct 2023 23:44:46 +0800 Subject: [PATCH 2/7] Fix test cases --- .../admin/executor/DefaultDatabaseMetaDataExecutorTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java index b8e3c5148483c..af7a432d0c1f2 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetaDataExecutorTest.java @@ -125,7 +125,6 @@ private ShardingSphereDatabase createDatabase(final Map expected private Connection mockConnection(final Map expectedResultSetMap) throws SQLException { Connection result = mock(Connection.class, RETURNS_DEEP_STUBS); - when(result.getMetaData().getURL()).thenReturn("jdbc:mysql://localhost:3306/foo_ds"); ResultSet resultSet = mockResultSet(expectedResultSetMap); when(result.prepareStatement(any(String.class)).executeQuery()).thenReturn(resultSet); return result; From fddfa13f71bb29f62994aef5c5e8bb58175e4ffc Mon Sep 17 00:00:00 2001 From: zhangliang Date: Fri, 6 Oct 2023 00:26:08 +0800 Subject: [PATCH 3/7] Fix test cases --- .../database/resource/unit/StorageUnitNodeMapUtils.java | 3 ++- .../information/SelectInformationSchemataExecutor.java | 2 +- .../fixture/database/DialectDatabaseMetaDataFixture.java | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java index 8217a4ca8486d..c76c414b957cc 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java @@ -55,7 +55,8 @@ public static Map fromDataSources(final Map getDatabaseNames(final ConnectionSession connection protected void preProcess(final String databaseName, final Map rows, final Map alias) { ResourceMetaData resourceMetaData = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabase(databaseName).getResourceMetaData(); Collection catalogs = resourceMetaData.getStorageUnits().keySet() - .stream().map(each -> resourceMetaData.getStorageUnits().get(each).getConnectionProperties().getCatalog()).collect(Collectors.toSet()); + .stream().map(each -> resourceMetaData.getStorageUnits().get(each).getStorageNode().getCatalog()).collect(Collectors.toSet()); schemaNameAlias = alias.getOrDefault(SCHEMA_NAME, ""); String rowValue = rows.getOrDefault(schemaNameAlias, "").toString(); queryDatabase = !rowValue.isEmpty(); diff --git a/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java b/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java index b233e640ceab8..dbef66def5aa0 100644 --- a/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java +++ b/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java @@ -33,6 +33,11 @@ public NullsOrderType getDefaultNullsOrderType() { return NullsOrderType.FIRST; } + @Override + public boolean isInstanceConnectionAvailable() { + return true; + } + @Override public String getDatabaseType() { return "FIXTURE"; From 27e7f01cc66494d25595d2f8a6e3cb341969918e Mon Sep 17 00:00:00 2001 From: zhangliang Date: Fri, 6 Oct 2023 00:50:18 +0800 Subject: [PATCH 4/7] Fix test cases --- ...SelectInformationSchemataExecutorTest.java | 35 ++++++++++++------- .../DialectDatabaseMetaDataFixture.java | 5 --- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutorTest.java index 79b4e1ff189c0..cdbb1ee04d400 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutorTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/information/SelectInformationSchemataExecutorTest.java @@ -20,7 +20,9 @@ import org.apache.shardingsphere.authority.provider.database.model.privilege.DatabasePermittedPrivileges; import org.apache.shardingsphere.authority.rule.AuthorityRule; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; @@ -43,6 +45,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.MockedConstruction; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; @@ -66,6 +69,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.when; @ExtendWith(AutoMockExtension.class) @@ -105,18 +109,25 @@ void assertExecuteWithAuthorizedDatabase() throws SQLException { Map expectedResultSetMap = new HashMap<>(2, 1F); expectedResultSetMap.put("SCHEMA_NAME", "foo_ds"); expectedResultSetMap.put("DEFAULT_COLLATION_NAME", "utf8mb4"); - ShardingSphereDatabase database = createDatabase(expectedResultSetMap); - ContextManager contextManager = mockContextManager(database); - when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); - when(ProxyContext.getInstance().getAllDatabaseNames()).thenReturn(Collections.singleton("auth_db")); - when(ProxyContext.getInstance().getDatabase("auth_db")).thenReturn(database); - SelectInformationSchemataExecutor executor = new SelectInformationSchemataExecutor(statement, sql, Collections.emptyList()); - executor.execute(connectionSession); - assertThat(executor.getQueryResultMetaData().getColumnCount(), is(2)); - assertTrue(executor.getMergedResult().next()); - assertThat(executor.getMergedResult().getValue(1, String.class), is("auth_db")); - assertThat(executor.getMergedResult().getValue(2, String.class), is("utf8mb4")); - assertFalse(executor.getMergedResult().next()); + try (MockedConstruction ignored = mockConstruction(DatabaseTypeRegistry.class, (mock, mockContext) -> { + DialectDatabaseMetaData dialectDatabaseMetaData = mock(DialectDatabaseMetaData.class); + when(dialectDatabaseMetaData.isInstanceConnectionAvailable()).thenReturn(true); + when(mock.getDialectDatabaseMetaData()).thenReturn(dialectDatabaseMetaData); + })) { + ShardingSphereDatabase database = createDatabase(expectedResultSetMap); + ContextManager contextManager = mockContextManager(database); + when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); + when(ProxyContext.getInstance().getAllDatabaseNames()).thenReturn(Collections.singleton("auth_db")); + when(ProxyContext.getInstance().getDatabase("auth_db")).thenReturn(database); + SelectInformationSchemataExecutor executor = new SelectInformationSchemataExecutor(statement, sql, Collections.emptyList()); + executor.execute(connectionSession); + assertThat(executor.getQueryResultMetaData().getColumnCount(), is(2)); + assertTrue(executor.getMergedResult().next()); + assertThat(executor.getMergedResult().getValue(1, String.class), is("auth_db")); + assertThat(executor.getMergedResult().getValue(2, String.class), is("utf8mb4")); + assertFalse(executor.getMergedResult().next()); + assertFalse(executor.getMergedResult().next()); + } } @Test diff --git a/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java b/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java index dbef66def5aa0..b233e640ceab8 100644 --- a/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java +++ b/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/database/DialectDatabaseMetaDataFixture.java @@ -33,11 +33,6 @@ public NullsOrderType getDefaultNullsOrderType() { return NullsOrderType.FIRST; } - @Override - public boolean isInstanceConnectionAvailable() { - return true; - } - @Override public String getDatabaseType() { return "FIXTURE"; From 89c88cbf9068c56e2946aec7eb90ffb210319868 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Fri, 6 Oct 2023 01:16:07 +0800 Subject: [PATCH 5/7] Refactor StorageNode --- .../metadata/database/resource/node/StorageNode.java | 4 ---- .../infra/metadata/ShardingSphereMetaDataTest.java | 2 +- .../shardingsphere/single/route/SingleSQLRouterTest.java | 4 ++-- .../transaction/rule/TransactionRuleTest.java | 8 ++++---- .../shardingsphere/mode/manager/ContextManagerTest.java | 2 +- .../distsql/ral/updatable/ImportMetaDataUpdaterTest.java | 4 ++-- .../unit/UnregisterStorageUnitBackendHandlerTest.java | 2 +- .../proxy/version/ShardingSphereProxyVersionTest.java | 2 +- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java index fa836f44b44f9..4e0ef8136b32d 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java @@ -32,8 +32,4 @@ public final class StorageNode { private final String url; private final String catalog; - - public StorageNode(final StorageNodeName name, final String url) { - this(name, url, null); - } } 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 4a7105ba8cdec..912db360b9ec9 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 @@ -92,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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_ds"), dataSourcePoolProps, dataSource); + StorageUnit storageUnit = new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_ds", null), 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/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 db5c95d2348e4..bbf9cd5c88ba0 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 @@ -151,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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); - storageUnits.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0", null), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1", null), 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/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 a03030c3e4a83..9a9459b1dc1ae 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 @@ -102,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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); - storageUnits.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0", null), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1", null), dataSourcePoolProps, new MockedDataSource())); ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); when(result.getStorageUnits()).thenReturn(storageUnits); return result; @@ -121,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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); - storageUnits.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0", null), dataSourcePoolProps, new MockedDataSource())); + storageUnits.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1", null), 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 dcae93b8f6c56..f1982c0f42892 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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, new MockedDataSource())); + new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db", null), 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 f5fd6da863809..e7ec23188daa5 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 @@ -123,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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0"), dataSourcePoolProps, new MockedDataSource())); - result.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1"), dataSourcePoolProps, new MockedDataSource())); + result.put("ds_0", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_0", null), dataSourcePoolProps, new MockedDataSource())); + result.put("ds_1", new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/ds_1", null), 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 a5ecee1ea5ccc..cc2fdfdc2cb8e 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 @@ -88,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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, new MockedDataSource()); + StorageUnit storageUnit = new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db", null), 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 8847fefceb466..ec052576440aa 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 @@ -86,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(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db"), dataSourcePoolProps, dataSource); + StorageUnit storageUnit = new StorageUnit(new StorageNode(mock(StorageNodeName.class), "jdbc:mock://127.0.0.1/foo_db", null), dataSourcePoolProps, dataSource); when(result.getStorageUnits()).thenReturn(Collections.singletonMap("foo_ds", storageUnit)); return result; } From c80215649e2af5bf893ed6480d31b50a90137d8a Mon Sep 17 00:00:00 2001 From: zhangliang Date: Fri, 6 Oct 2023 01:16:42 +0800 Subject: [PATCH 6/7] Refactor StorageNode --- .../database/resource/unit/StorageUnitNodeMapUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java index c76c414b957cc..6b65846163992 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java @@ -92,6 +92,6 @@ private static StorageNodeName getStorageNodeName(final String dataSourceName, f } private static StorageNode createStorageNode(final StorageNodeName storageNodeName, final String url, final boolean isInstanceConnectionAvailable) { - return isInstanceConnectionAvailable ? new StorageNode(storageNodeName, url, new StandardJdbcUrlParser().parse(url).getDatabase()) : new StorageNode(storageNodeName, url); + return isInstanceConnectionAvailable ? new StorageNode(storageNodeName, url, new StandardJdbcUrlParser().parse(url).getDatabase()) : new StorageNode(storageNodeName, url, null); } } From 6284e1283d1391e605d0b1dc7a98d70256214f8b Mon Sep 17 00:00:00 2001 From: zhangliang Date: Fri, 6 Oct 2023 01:17:33 +0800 Subject: [PATCH 7/7] Refactor StorageNode --- .../database/resource/unit/StorageUnitNodeMapUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java index 6b65846163992..67d885f668535 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapUtils.java @@ -92,6 +92,6 @@ private static StorageNodeName getStorageNodeName(final String dataSourceName, f } private static StorageNode createStorageNode(final StorageNodeName storageNodeName, final String url, final boolean isInstanceConnectionAvailable) { - return isInstanceConnectionAvailable ? new StorageNode(storageNodeName, url, new StandardJdbcUrlParser().parse(url).getDatabase()) : new StorageNode(storageNodeName, url, null); + return new StorageNode(storageNodeName, url, isInstanceConnectionAvailable ? new StandardJdbcUrlParser().parse(url).getDatabase() : null); } }