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 20bac385972 Add more test cases for ShowDistVariableExecutorTest and 
ShowDistVariablesExecutorTest (#38011)
20bac385972 is described below

commit 20bac3859729b842e3230074ea74a1744f5f3025
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 12 00:05:19 2026 +0800

    Add more test cases for ShowDistVariableExecutorTest and 
ShowDistVariablesExecutorTest (#38011)
---
 .../variable/ShowDistVariableExecutorTest.java     | 30 +++++++++++++---
 .../variable/ShowDistVariablesExecutorTest.java    | 42 +++++++++++++++++++---
 2 files changed, 63 insertions(+), 9 deletions(-)

diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
index 2527311eca9..afc34624cae 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.va
 
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import 
org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
+import 
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
 import 
org.apache.shardingsphere.distsql.statement.type.ral.queryable.show.ShowDistVariableStatement;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties;
@@ -27,12 +28,15 @@ import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConne
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.session.query.QueryContext;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -45,9 +49,19 @@ class ShowDistVariableExecutorTest {
     
     private final ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
     
+    private final ShowDistVariableExecutor executor = 
(ShowDistVariableExecutor) 
TypedSPILoader.getService(DistSQLQueryExecutor.class, 
ShowDistVariableStatement.class);
+    
+    @Test
+    void assertGetColumnNames() {
+        Collection<String> actual = executor.getColumnNames(new 
ShowDistVariableStatement("SQL_SHOW"));
+        assertThat(actual.size(), is(2));
+        Iterator<String> iterator = actual.iterator();
+        assertThat(iterator.next(), is("variable_name"));
+        assertThat(iterator.next(), is("variable_value"));
+    }
+    
     @Test
     void assertShowCachedConnections() {
-        ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
         executor.setConnectionContext(new 
DistSQLConnectionContext(mock(QueryContext.class), 1,
                 mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariableStatement("CACHED_CONNECTIONS"), contextManager);
@@ -60,7 +74,6 @@ class ShowDistVariableExecutorTest {
     @Test
     void assertShowPropsVariable() {
         
when(contextManager.getMetaDataContexts().getMetaData().getProps()).thenReturn(new
 ConfigurationProperties(PropertiesBuilder.build(new Property("sql-show", 
Boolean.TRUE.toString()))));
-        ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariableStatement("SQL_SHOW"), contextManager);
         assertThat(actual.size(), is(1));
         LocalDataQueryResultRow row = actual.iterator().next();
@@ -68,11 +81,20 @@ class ShowDistVariableExecutorTest {
         assertThat(row.getCell(2), is("true"));
     }
     
+    @Test
+    void assertShowPropsVariableWithNullValue() {
+        
when(contextManager.getMetaDataContexts().getMetaData().getProps()).thenReturn(new
 ConfigurationProperties(new Properties()));
+        Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariableStatement("PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE"), 
contextManager);
+        assertThat(actual.size(), is(1));
+        LocalDataQueryResultRow row = actual.iterator().next();
+        assertThat(row.getCell(1), 
is("proxy_frontend_database_protocol_type"));
+        assertThat(row.getCell(2), is(""));
+    }
+    
     @Test
     void assertShowPropsVariableForTypedSPI() {
         when(contextManager.getMetaDataContexts().getMetaData().getProps())
                 .thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-frontend-database-protocol-type", "MySQL"))));
-        ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariableStatement("PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE"), 
contextManager);
         assertThat(actual.size(), is(1));
         LocalDataQueryResultRow row = actual.iterator().next();
@@ -84,7 +106,6 @@ class ShowDistVariableExecutorTest {
     void assertShowTemporaryPropsVariable() {
         
when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps())
                 .thenReturn(new 
TemporaryConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-meta-data-collector-enabled", Boolean.FALSE.toString()))));
-        ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariableStatement("PROXY_META_DATA_COLLECTOR_ENABLED"), contextManager);
         assertThat(actual.size(), is(1));
         LocalDataQueryResultRow row = actual.iterator().next();
@@ -94,7 +115,6 @@ class ShowDistVariableExecutorTest {
     
     @Test
     void assertExecuteWithInvalidVariableName() {
-        ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
         assertThrows(UnsupportedVariableException.class, () -> 
executor.getRows(new ShowDistVariableStatement("wrong_name"), contextManager));
     }
 }
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
index 6b6664687e5..950482675f2 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.va
 
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import 
org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
+import 
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
 import 
org.apache.shardingsphere.distsql.statement.type.ral.queryable.show.ShowDistVariablesStatement;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties;
@@ -26,6 +27,7 @@ import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConne
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.session.query.QueryContext;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
 import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -45,10 +47,20 @@ class ShowDistVariablesExecutorTest {
     
     private final ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
     
+    private final ShowDistVariablesExecutor executor = 
(ShowDistVariablesExecutor) 
TypedSPILoader.getService(DistSQLQueryExecutor.class, 
ShowDistVariablesStatement.class);
+    
+    @Test
+    void assertGetColumnNames() {
+        Collection<String> actual = executor.getColumnNames(new 
ShowDistVariablesStatement(false, null));
+        assertThat(actual.size(), is(2));
+        Iterator<String> iterator = actual.iterator();
+        assertThat(iterator.next(), is("variable_name"));
+        assertThat(iterator.next(), is("variable_value"));
+    }
+    
     @Test
     void assertExecute() {
         
when(contextManager.getMetaDataContexts().getMetaData().getProps()).thenReturn(new
 ConfigurationProperties(PropertiesBuilder.build(new 
Property("agent-plugins-enabled", "false"))));
-        ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
         executor.setConnectionContext(new 
DistSQLConnectionContext(mock(QueryContext.class), 1,
                 mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
         Collection<LocalDataQueryResultRow> actual = 
executor.getRows(mock(ShowDistVariablesStatement.class), contextManager);
@@ -60,7 +72,6 @@ class ShowDistVariablesExecutorTest {
     
     @Test
     void assertExecuteWithLike() {
-        ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
         executor.setConnectionContext(new 
DistSQLConnectionContext(mock(QueryContext.class), 1,
                 mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariablesStatement(false, "sql_%"), contextManager);
@@ -70,10 +81,34 @@ class ShowDistVariablesExecutorTest {
         assertThat(iterator.next().getCell(1), is("sql_simple"));
     }
     
+    @Test
+    void assertExecuteWithTypedSPI() {
+        when(contextManager.getMetaDataContexts().getMetaData().getProps())
+                .thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-frontend-database-protocol-type", "MySQL"))));
+        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(QueryContext.class), 1,
+                mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
+        Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariablesStatement(false, "PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE"), 
contextManager);
+        assertThat(actual.size(), is(1));
+        LocalDataQueryResultRow row = actual.iterator().next();
+        assertThat(row.getCell(1), 
is("proxy_frontend_database_protocol_type"));
+        assertThat(row.getCell(2), is("MySQL"));
+    }
+    
+    @Test
+    void assertExecuteWithNullTypedSPI() {
+        
when(contextManager.getMetaDataContexts().getMetaData().getProps()).thenReturn(new
 ConfigurationProperties(new Properties()));
+        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(QueryContext.class), 1,
+                mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
+        Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariablesStatement(false, "proxy_frontend_database_protocol_type"), 
contextManager);
+        assertThat(actual.size(), is(1));
+        LocalDataQueryResultRow row = actual.iterator().next();
+        assertThat(row.getCell(1), 
is("proxy_frontend_database_protocol_type"));
+        assertThat(row.getCell(2), is(""));
+    }
+    
     @Test
     void assertExecuteTemporary() {
         
when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps()).thenReturn(new
 TemporaryConfigurationProperties(new Properties()));
-        ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
         ShowDistVariablesStatement sqlStatement = new 
ShowDistVariablesStatement(true, null);
         Collection<LocalDataQueryResultRow> actual = 
executor.getRows(sqlStatement, contextManager);
         assertThat(actual.size(), is(4));
@@ -84,7 +119,6 @@ class ShowDistVariablesExecutorTest {
     
     @Test
     void assertExecuteTemporaryWithLike() {
-        ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariablesStatement(true, "proxy_%"), contextManager);
         assertThat(actual.size(), is(2));
         Iterator<LocalDataQueryResultRow> iterator = actual.iterator();

Reply via email to