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 3f0bc2b114d refactor(postgresql): Remove redundant PostgreSQLDatabaseType usage (#35327) 3f0bc2b114d is described below commit 3f0bc2b114da0afa6d1d91d62cd6a365c507d7b4 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Mon May 5 14:51:26 2025 +0800 refactor(postgresql): Remove redundant PostgreSQLDatabaseType usage (#35327) - Replace direct usage of PostgreSQLDatabaseType with a more generic DatabaseType - Use TypedSPILoader.getService to get the PostgreSQL DatabaseType instance - Update mockDatabase method to use the new DatabaseType instance - Adjust unit tests to use the new DatabaseType instance --- .../frontend/postgresql/command/query/extended/PortalTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java index f22a792248b..e4f2e7c6ab0 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java @@ -34,7 +34,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatem import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; @@ -97,6 +96,8 @@ import static org.mockito.Mockito.when; @MockitoSettings(strictness = Strictness.LENIENT) class PortalTest { + private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"); + @Mock private ProxyBackendHandler proxyBackendHandler; @@ -112,9 +113,9 @@ class PortalTest { when(connectionSession.getCurrentDatabaseName()).thenReturn("foo_db"); ConnectionContext connectionContext = mockConnectionContext(); when(connectionSession.getConnectionContext()).thenReturn(connectionContext); - when(ProxyBackendHandlerFactory.newInstance(any(PostgreSQLDatabaseType.class), anyString(), any(SQLStatement.class), eq(connectionSession), any(HintValueContext.class))) + when(ProxyBackendHandlerFactory.newInstance(eq(databaseType), anyString(), any(SQLStatement.class), eq(connectionSession), any(HintValueContext.class))) .thenReturn(proxyBackendHandler); - when(ProxyBackendHandlerFactory.newInstance(any(PostgreSQLDatabaseType.class), any(QueryContext.class), eq(connectionSession), anyBoolean())).thenReturn(proxyBackendHandler); + when(ProxyBackendHandlerFactory.newInstance(eq(databaseType), any(QueryContext.class), eq(connectionSession), anyBoolean())).thenReturn(proxyBackendHandler); when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession); } @@ -135,7 +136,7 @@ class PortalTest { private ShardingSphereDatabase mockDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class); - when(result.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); + when(result.getProtocolType()).thenReturn(databaseType); return result; }