This is an automated email from the ASF dual-hosted git repository.

totalo 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 6a3f86ece9c Simplify parameter of SessionVariableHandler (#19771)
6a3f86ece9c is described below

commit 6a3f86ece9cc2abf58c96f06c8bb0f18378f7637
Author: 吴伟杰 <[email protected]>
AuthorDate: Tue Aug 2 12:52:12 2022 +0800

    Simplify parameter of SessionVariableHandler (#19771)
---
 .../handler/admin/executor/SessionVariableHandler.java  |  8 ++++----
 .../admin/mysql/DefaultMySQLSessionVariableHandler.java | 10 ++--------
 .../admin/mysql/MySQLSessionVariableHandlerFactory.java | 17 +++++------------
 .../admin/mysql/MySQLSetVariableAdminExecutor.java      | 11 +++++------
 .../admin/mysql/executor/MySQLSetCharsetExecutor.java   |  4 ++--
 .../DefaultPostgreSQLSessionVariableHandler.java        |  6 ++----
 .../postgresql/PostgreSQLSetVariableAdminExecutor.java  | 13 +++++--------
 .../executor/PostgreSQLSetCharsetExecutor.java          |  9 +++------
 .../mysql/MySQLSessionVariableHandlerFactoryTest.java   |  9 +--------
 .../admin/mysql/TestFixtureSessionVariableHandler.java  |  7 ++-----
 .../DefaultPostgreSQLSessionVariableHandlerTest.java    |  3 +--
 .../PostgreSQLSetVariableAdminExecutorTest.java         | 12 ++++++++++--
 12 files changed, 42 insertions(+), 67 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/SessionVariableHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/SessionVariableHandler.java
index 0f309bc53a7..9f5d751ea27 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/SessionVariableHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/SessionVariableHandler.java
@@ -19,7 +19,6 @@ package 
org.apache.shardingsphere.proxy.backend.handler.admin.executor;
 
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.spi.type.typed.TypedSPI;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
 
 /**
  * Session variable handler.
@@ -27,10 +26,11 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatemen
 public interface SessionVariableHandler extends TypedSPI {
     
     /**
-     * Handle set statement for specific connection session.
+     * Handle session variable for specific connection session.
      *
      * @param connectionSession connection session
-     * @param setStatement set statement
+     * @param variableName variable name
+     * @param assignValue assign value
      */
-    void handle(ConnectionSession connectionSession, SetStatement 
setStatement);
+    void handle(ConnectionSession connectionSession, String variableName, 
String assignValue);
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java
index 6c8e698f09f..21bd448ac35 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java
@@ -19,9 +19,6 @@ package 
org.apache.shardingsphere.proxy.backend.handler.admin.mysql;
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
-
-import java.util.stream.Collectors;
 
 /**
  * Default session variable handler for MySQL.
@@ -30,10 +27,7 @@ import java.util.stream.Collectors;
 public final class DefaultMySQLSessionVariableHandler implements 
MySQLSessionVariableHandler {
     
     @Override
-    public void handle(final ConnectionSession connectionSession, final 
SetStatement setStatement) {
-        if (log.isDebugEnabled()) {
-            log.debug("Set statement {} was discarded.", 
setStatement.getVariableAssigns().stream()
-                    .map(segment -> String.format("%s %s = %s", 
segment.getVariable().getScope(), segment.getVariable().getVariable(), 
segment.getAssignValue())).collect(Collectors.joining(", ")));
-        }
+    public void handle(final ConnectionSession connectionSession, final String 
variableName, final String assignValue) {
+        log.debug("Set statement {} = {} was discarded.", variableName, 
assignValue);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactory.java
index a42eccc6452..5b4b0c39b86 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactory.java
@@ -20,9 +20,6 @@ package 
org.apache.shardingsphere.proxy.backend.handler.admin.mysql;
 import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * Factory for {@link MySQLSessionVariableHandler}.
  */
@@ -33,16 +30,12 @@ public final class MySQLSessionVariableHandlerFactory {
     }
     
     /**
-     * Get list of {@link MySQLSessionVariableHandler} for variables.
+     * Get instance of {@link MySQLSessionVariableHandler} for variable.
      *
-     * @param variableNames variable names
-     * @return {@link MySQLSessionVariableHandler} for variables
+     * @param variableName variable name
+     * @return {@link MySQLSessionVariableHandler} for variable
      */
-    public static List<MySQLSessionVariableHandler> getHandlers(final 
List<String> variableNames) {
-        List<MySQLSessionVariableHandler> result = new 
ArrayList<>(variableNames.size());
-        for (String each : variableNames) {
-            
result.add(TypedSPIRegistry.findRegisteredService(MySQLSessionVariableHandler.class,
 each).orElseGet(DefaultMySQLSessionVariableHandler::new));
-        }
-        return result;
+    public static MySQLSessionVariableHandler getHandler(final String 
variableName) {
+        return 
TypedSPIRegistry.findRegisteredService(MySQLSessionVariableHandler.class, 
variableName).orElseGet(DefaultMySQLSessionVariableHandler::new);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java
index 704ba9e588b..fcc66da752c 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java
@@ -26,19 +26,18 @@ import 
org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.parser.rule.SQLParserRule;
 import 
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
 import 
org.apache.shardingsphere.proxy.backend.handler.data.DatabaseBackendHandler;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
 
 import java.sql.SQLException;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -52,9 +51,9 @@ public final class MySQLSetVariableAdminExecutor implements 
DatabaseAdminExecuto
     @Override
     public void execute(final ConnectionSession connectionSession) throws 
SQLException {
         Map<String, String> sessionVariables = extractSessionVariables();
-        List<MySQLSessionVariableHandler> handlers = 
MySQLSessionVariableHandlerFactory.getHandlers(new 
ArrayList<>(sessionVariables.keySet()));
-        for (MySQLSessionVariableHandler each : handlers) {
-            each.handle(connectionSession, setStatement);
+        Map<String, MySQLSessionVariableHandler> handlers = 
sessionVariables.keySet().stream().collect(Collectors.toMap(Function.identity(),
 MySQLSessionVariableHandlerFactory::getHandler));
+        for (String each : handlers.keySet()) {
+            handlers.get(each).handle(connectionSession, each, 
sessionVariables.get(each));
         }
         executeSetGlobalVariablesIfPresent(connectionSession);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
index 3fd46415f5d..4618899e712 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
@@ -48,8 +48,8 @@ public final class MySQLSetCharsetExecutor implements 
MySQLSessionVariableHandle
     }
     
     @Override
-    public void handle(final ConnectionSession connectionSession, final 
SetStatement setStatement) {
-        String value = formatValue(getCharacterSetValue(setStatement));
+    public void handle(final ConnectionSession connectionSession, final String 
variableName, final String assignValue) {
+        String value = formatValue(assignValue);
         
connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(parseCharset(value));
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
index 5579fa6483b..8a7fda73950 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
@@ -19,7 +19,6 @@ package 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql;
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
 
 /**
  * Default session variable handler for PostgreSQL.
@@ -28,8 +27,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatemen
 public final class DefaultPostgreSQLSessionVariableHandler implements 
PostgreSQLSessionVariableHandler {
     
     @Override
-    public void handle(final ConnectionSession connectionSession, final 
SetStatement setStatement) {
-        log.debug("Set statement {} was discarded.", 
setStatement.getVariableAssigns().stream().findFirst()
-                .map(segment -> String.format("%s = %s", 
segment.getVariable().getVariable(), 
segment.getAssignValue())).orElseGet(setStatement::toString));
+    public void handle(final ConnectionSession connectionSession, final String 
variableName, final String assignValue) {
+        log.debug("Set statement {} = {} was discarded.", variableName, 
assignValue);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutor.java
index 1e48825bdf8..69bccf67426 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutor.java
@@ -18,13 +18,12 @@
 package org.apache.shardingsphere.proxy.backend.handler.admin.postgresql;
 
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
 
 import java.sql.SQLException;
-import java.util.Iterator;
 
 /**
  * Set variable admin executor for PostgreSQL.
@@ -36,11 +35,9 @@ public final class PostgreSQLSetVariableAdminExecutor 
implements DatabaseAdminEx
     
     @Override
     public void execute(final ConnectionSession connectionSession) throws 
SQLException {
-        
PostgreSQLSessionVariableHandlerFactory.getHandler(getSetConfigurationParameter(setStatement)).handle(connectionSession,
 setStatement);
-    }
-    
-    private String getSetConfigurationParameter(final SetStatement 
setStatement) {
-        Iterator<VariableAssignSegment> iterator = 
setStatement.getVariableAssigns().iterator();
-        return iterator.hasNext() ? 
iterator.next().getVariable().getVariable().toLowerCase() : "";
+        VariableAssignSegment variableAssignSegment = 
setStatement.getVariableAssigns().iterator().next();
+        String variableName = 
variableAssignSegment.getVariable().getVariable().toLowerCase();
+        String assignValue = variableAssignSegment.getAssignValue();
+        
PostgreSQLSessionVariableHandlerFactory.getHandler(variableName).handle(connectionSession,
 variableName, assignValue);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
index 5875a7d694f..8ba31a8bc44 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
@@ -19,11 +19,9 @@ package 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql.executo
 
 import org.apache.shardingsphere.db.protocol.CommonConstants;
 import 
org.apache.shardingsphere.proxy.backend.exception.InvalidParameterValueException;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql.PostgreSQLCharacterSets;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.postgresql.PostgreSQLSessionVariableHandler;
-import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
@@ -35,9 +33,8 @@ import java.util.Locale;
 public final class PostgreSQLSetCharsetExecutor implements 
PostgreSQLSessionVariableHandler {
     
     @Override
-    public void handle(final ConnectionSession connectionSession, final 
SetStatement setStatement) {
-        VariableAssignSegment segment = 
setStatement.getVariableAssigns().iterator().next();
-        String value = formatValue(segment.getAssignValue().trim());
+    public void handle(final ConnectionSession connectionSession, final String 
variableName, final String assignValue) {
+        String value = formatValue(assignValue.trim());
         
connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(parseCharset(value));
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactoryTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactoryTest.java
index cb8774fa272..076af1592c3 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactoryTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSessionVariableHandlerFactoryTest.java
@@ -19,20 +19,13 @@ package 
org.apache.shardingsphere.proxy.backend.handler.admin.mysql;
 
 import org.junit.Test;
 
-import java.util.Arrays;
-import java.util.List;
-
 import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 public final class MySQLSessionVariableHandlerFactoryTest {
     
     @Test
     public void assertGetHandlers() {
-        List<MySQLSessionVariableHandler> actual = 
MySQLSessionVariableHandlerFactory.getHandlers(Arrays.asList("test_fixture", 
"test_fixture"));
-        assertThat(actual.size(), is(2));
-        assertThat(actual.get(0), 
instanceOf(TestFixtureSessionVariableHandler.class));
-        assertThat(actual.get(1), 
instanceOf(TestFixtureSessionVariableHandler.class));
+        
assertThat(MySQLSessionVariableHandlerFactory.getHandler("test_fixture"), 
instanceOf(TestFixtureSessionVariableHandler.class));
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/TestFixtureSessionVariableHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/TestFixtureSessionVariableHandler.java
index c2c76570f6b..8cff6844308 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/TestFixtureSessionVariableHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/TestFixtureSessionVariableHandler.java
@@ -18,15 +18,12 @@
 package org.apache.shardingsphere.proxy.backend.handler.admin.mysql;
 
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
-import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
 
 public final class TestFixtureSessionVariableHandler implements 
MySQLSessionVariableHandler {
     
     @Override
-    public void handle(final ConnectionSession connectionSession, final 
SetStatement setStatement) {
-        
connectionSession.setCurrentDatabase(setStatement.getVariableAssigns().stream()
-                .filter(each -> 
getType().equals(each.getVariable().getVariable())).map(VariableAssignSegment::getAssignValue).findFirst().orElseThrow(IllegalArgumentException::new));
+    public void handle(final ConnectionSession connectionSession, final String 
variableName, final String assignValue) {
+        connectionSession.setCurrentDatabase(assignValue);
     }
     
     @Override
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
index 82dc6e2ae65..a1e78e45359 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.proxy.backend.handler.admin.postgresql;
 
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLSetStatement;
 import org.junit.Test;
 
 import static org.mockito.Mockito.mock;
@@ -29,7 +28,7 @@ public final class 
DefaultPostgreSQLSessionVariableHandlerTest {
     @Test
     public void assertHandle() {
         ConnectionSession connectionSession = mock(ConnectionSession.class);
-        new 
DefaultPostgreSQLSessionVariableHandler().handle(connectionSession, new 
PostgreSQLSetStatement());
+        new 
DefaultPostgreSQLSessionVariableHandler().handle(connectionSession, "", "");
         verifyNoInteractions(connectionSession);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutorTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutorTest.java
index 02b68c66b85..45045943b03 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutorTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/PostgreSQLSetVariableAdminExecutorTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.shardingsphere.proxy.backend.handler.admin.postgresql;
 
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLSetStatement;
 import org.junit.Test;
 import org.mockito.MockedStatic;
@@ -31,13 +33,19 @@ public final class PostgreSQLSetVariableAdminExecutorTest {
     
     @Test
     public void assertExecute() throws SQLException {
+        VariableAssignSegment variableAssignSegment = new 
VariableAssignSegment();
+        VariableSegment variable = new VariableSegment();
+        variable.setVariable("key");
+        variableAssignSegment.setVariable(variable);
+        variableAssignSegment.setAssignValue("value");
         PostgreSQLSetStatement setStatement = new PostgreSQLSetStatement();
+        setStatement.getVariableAssigns().add(variableAssignSegment);
         PostgreSQLSetVariableAdminExecutor executor = new 
PostgreSQLSetVariableAdminExecutor(setStatement);
         try (MockedStatic<PostgreSQLSessionVariableHandlerFactory> mockStatic 
= mockStatic(PostgreSQLSessionVariableHandlerFactory.class)) {
             PostgreSQLSessionVariableHandler mockHandler = 
mock(PostgreSQLSessionVariableHandler.class);
-            mockStatic.when(() -> 
PostgreSQLSessionVariableHandlerFactory.getHandler("")).thenReturn(mockHandler);
+            mockStatic.when(() -> 
PostgreSQLSessionVariableHandlerFactory.getHandler("key")).thenReturn(mockHandler);
             executor.execute(null);
-            verify(mockHandler).handle(null, setStatement);
+            verify(mockHandler).handle(null, "key", "value");
         }
     }
 }

Reply via email to