This is an automated email from the ASF dual-hosted git repository. zhangliang 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 f53b7835b06 Refactor PostgreSQLMetaDataLoaderTest to use DatabaseType (#35326) f53b7835b06 is described below commit f53b7835b0610a0b1eeead244f72700afda7c929 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Mon May 5 14:45:17 2025 +0800 Refactor PostgreSQLMetaDataLoaderTest to use DatabaseType (#35326) - Remove direct usage of PostgreSQLDatabaseType - Use TypedSPILoader to get DatabaseType instance for PostgreSQL - Update test methods to use the new DatabaseType instance - Add JDBCResourceOpenedButNotSafelyClosed suppression to relevant test methods --- .../metadata/data/loader/PostgreSQLMetaDataLoaderTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java index 6f9ae19805f..73ffcb0b5e7 100644 --- a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java +++ b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java @@ -27,7 +27,6 @@ import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMe import org.apache.shardingsphere.infra.database.core.metadata.database.datatype.DataTypeRegistry; import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.junit.jupiter.api.Test; @@ -75,6 +74,9 @@ class PostgreSQLMetaDataLoaderTest { private static final String LOAD_ALL_ROLE_TABLE_GRANTS_SQL = "SELECT table_name FROM information_schema.role_table_grants"; + private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"); + + @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed") @Test void assertLoadWithoutTables() throws SQLException { DataSource dataSource = mockDataSource(); @@ -93,7 +95,7 @@ class PostgreSQLMetaDataLoaderTest { ResultSet roleTableGrantsResultSet = mockRoleTableGrantsResultSet(); when(dataSource.getConnection().prepareStatement(startsWith(LOAD_ALL_ROLE_TABLE_GRANTS_SQL)).executeQuery()).thenReturn(roleTableGrantsResultSet); DataTypeRegistry.load(dataSource, "PostgreSQL"); - assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new MetaDataLoaderMaterial(Collections.emptyList(), "foo_ds", dataSource, new PostgreSQLDatabaseType(), "sharding_db"))); + assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new MetaDataLoaderMaterial(Collections.emptyList(), "foo_ds", dataSource, databaseType, "sharding_db"))); } private ResultSet mockSchemaMetaDataResultSet() throws SQLException { @@ -103,6 +105,7 @@ class PostgreSQLMetaDataLoaderTest { return result; } + @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed") @Test void assertLoadWithTables() throws SQLException { DataSource dataSource = mockDataSource(); @@ -121,7 +124,7 @@ class PostgreSQLMetaDataLoaderTest { ResultSet roleTableGrantsResultSet = mockRoleTableGrantsResultSet(); when(dataSource.getConnection().prepareStatement(startsWith(LOAD_ALL_ROLE_TABLE_GRANTS_SQL)).executeQuery()).thenReturn(roleTableGrantsResultSet); DataTypeRegistry.load(dataSource, "PostgreSQL"); - assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new MetaDataLoaderMaterial(Collections.singletonList("tbl"), "foo_ds", dataSource, new PostgreSQLDatabaseType(), "sharding_db"))); + assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new MetaDataLoaderMaterial(Collections.singletonList("tbl"), "foo_ds", dataSource, databaseType, "sharding_db"))); } private ResultSet mockRoleTableGrantsResultSet() throws SQLException { @@ -131,6 +134,7 @@ class PostgreSQLMetaDataLoaderTest { return result; } + @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed") private DataSource mockDataSource() throws SQLException { DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS); ResultSet typeInfoResultSet = mockTypeInfoResultSet();