You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/02/19 16:12:05 UTC

[shardingsphere] branch master updated: Rename ReplayRequiredSessionVariables to ReplayedSessionVariablesProvider (#24249)

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

sunnianjun 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 a8d415464ce Rename ReplayRequiredSessionVariables to ReplayedSessionVariablesProvider (#24249)
a8d415464ce is described below

commit a8d415464ce6db444d3d28db9b94c275871482a1
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Feb 20 00:11:56 2023 +0800

    Rename ReplayRequiredSessionVariables to ReplayedSessionVariablesProvider (#24249)
---
 ...ionVariables.java => ReplayedSessionVariablesProvider.java} | 10 +++++-----
 .../admin/mysql/DefaultMySQLSessionVariableHandler.java        |  7 +++----
 .../postgresql/DefaultPostgreSQLSessionVariableHandler.java    |  7 +++----
 .../admin/mysql/DefaultMySQLSessionVariableHandlerTest.java    |  8 ++++----
 .../DefaultPostgreSQLSessionVariableHandlerTest.java           |  8 ++++----
 5 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayRequiredSessionVariables.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayedSessionVariablesProvider.java
similarity index 78%
rename from proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayRequiredSessionVariables.java
rename to proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayedSessionVariablesProvider.java
index fc6e9f9f338..da6ca33b9d3 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayRequiredSessionVariables.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayedSessionVariablesProvider.java
@@ -23,15 +23,15 @@ import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
 import java.util.Collection;
 
 /**
- * Declaring variables need to be replayed on connections.
+ * Provide session variables need to be replayed on session connected.
  */
 @SingletonSPI
-public interface ReplayRequiredSessionVariables extends TypedSPI {
+public interface ReplayedSessionVariablesProvider extends TypedSPI {
     
     /**
-     * Get variables need to be replayed on connections.
+     * Get need to be replayed session variables.
      *
-     * @return variables need to be replayed on connections
+     * @return variables
      */
-    Collection<String> getReplayRequiredVariables();
+    Collection<String> getVariables();
 }
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java
index d09c54fd9de..12d2df47047 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandler.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.handler.admin.mysql;
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayRequiredSessionVariables;
+import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayedSessionVariablesProvider;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 
 import java.util.Collection;
@@ -31,12 +31,11 @@ import java.util.Collections;
 @Slf4j
 public final class DefaultMySQLSessionVariableHandler implements MySQLSessionVariableHandler {
     
-    private final Collection<String> replayRequiredSessionVariables = TypedSPILoader.findService(ReplayRequiredSessionVariables.class, "MySQL")
-            .orElseGet(() -> Collections::emptySet).getReplayRequiredVariables();
+    private final Collection<String> replayedSessionVariables = TypedSPILoader.findService(ReplayedSessionVariablesProvider.class, "MySQL").orElseGet(() -> Collections::emptySet).getVariables();
     
     @Override
     public void handle(final ConnectionSession connectionSession, final String variableName, final String assignValue) {
-        if (replayRequiredSessionVariables.contains(variableName)) {
+        if (replayedSessionVariables.contains(variableName)) {
             connectionSession.getRequiredSessionVariableRecorder().setVariable(variableName, assignValue);
         } else {
             log.debug("Set statement {} = {} was discarded.", variableName, assignValue);
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
index 2e4a86ad6da..2b1bfe4a0b1 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.handler.admin.postgresql;
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayRequiredSessionVariables;
+import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayedSessionVariablesProvider;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 
 import java.util.Collection;
@@ -31,12 +31,11 @@ import java.util.Collections;
 @Slf4j
 public final class DefaultPostgreSQLSessionVariableHandler implements PostgreSQLSessionVariableHandler {
     
-    private final Collection<String> replayRequiredSessionVariables = TypedSPILoader.findService(ReplayRequiredSessionVariables.class, "PostgreSQL")
-            .orElseGet(() -> Collections::emptySet).getReplayRequiredVariables();
+    private final Collection<String> replayedSessionVariables = TypedSPILoader.findService(ReplayedSessionVariablesProvider.class, "PostgreSQL").orElseGet(() -> Collections::emptySet).getVariables();
     
     @Override
     public void handle(final ConnectionSession connectionSession, final String variableName, final String assignValue) {
-        if (replayRequiredSessionVariables.contains(variableName)) {
+        if (replayedSessionVariables.contains(variableName)) {
             connectionSession.getRequiredSessionVariableRecorder().setVariable(variableName, assignValue);
         } else {
             log.debug("Set statement {} = {} was discarded.", variableName, assignValue);
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandlerTest.java
index e03c9a58f68..ad884b5eec6 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandlerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/DefaultMySQLSessionVariableHandlerTest.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.proxy.backend.handler.admin.mysql;
 
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayRequiredSessionVariables;
+import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayedSessionVariablesProvider;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.backend.session.RequiredSessionVariableRecorder;
 import org.junit.Test;
@@ -47,9 +47,9 @@ public final class DefaultMySQLSessionVariableHandlerTest {
         ConnectionSession connectionSession = mock(ConnectionSession.class);
         when(connectionSession.getRequiredSessionVariableRecorder()).thenReturn(mock(RequiredSessionVariableRecorder.class));
         try (MockedStatic<TypedSPILoader> typedSPILoader = mockStatic(TypedSPILoader.class)) {
-            ReplayRequiredSessionVariables replayRequiredSessionVariables = mock(ReplayRequiredSessionVariables.class);
-            when(replayRequiredSessionVariables.getReplayRequiredVariables()).thenReturn(Collections.singleton("sql_mode"));
-            typedSPILoader.when(() -> TypedSPILoader.findService(ReplayRequiredSessionVariables.class, "MySQL")).thenReturn(Optional.of(replayRequiredSessionVariables));
+            ReplayedSessionVariablesProvider variablesProvider = mock(ReplayedSessionVariablesProvider.class);
+            when(variablesProvider.getVariables()).thenReturn(Collections.singleton("sql_mode"));
+            typedSPILoader.when(() -> TypedSPILoader.findService(ReplayedSessionVariablesProvider.class, "MySQL")).thenReturn(Optional.of(variablesProvider));
             new DefaultMySQLSessionVariableHandler().handle(connectionSession, "sql_mode", "''");
             verify(connectionSession.getRequiredSessionVariableRecorder()).setVariable("sql_mode", "''");
         }
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
index f20d112cfc8..2b0bc705050 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.proxy.backend.handler.admin.postgresql;
 
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayRequiredSessionVariables;
+import org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayedSessionVariablesProvider;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.backend.session.RequiredSessionVariableRecorder;
 import org.junit.Test;
@@ -47,9 +47,9 @@ public final class DefaultPostgreSQLSessionVariableHandlerTest {
         ConnectionSession connectionSession = mock(ConnectionSession.class);
         when(connectionSession.getRequiredSessionVariableRecorder()).thenReturn(mock(RequiredSessionVariableRecorder.class));
         try (MockedStatic<TypedSPILoader> typedSPILoader = mockStatic(TypedSPILoader.class)) {
-            ReplayRequiredSessionVariables replayRequiredSessionVariables = mock(ReplayRequiredSessionVariables.class);
-            when(replayRequiredSessionVariables.getReplayRequiredVariables()).thenReturn(Collections.singleton("datestyle"));
-            typedSPILoader.when(() -> TypedSPILoader.findService(ReplayRequiredSessionVariables.class, "PostgreSQL")).thenReturn(Optional.of(replayRequiredSessionVariables));
+            ReplayedSessionVariablesProvider variablesProvider = mock(ReplayedSessionVariablesProvider.class);
+            when(variablesProvider.getVariables()).thenReturn(Collections.singleton("datestyle"));
+            typedSPILoader.when(() -> TypedSPILoader.findService(ReplayedSessionVariablesProvider.class, "PostgreSQL")).thenReturn(Optional.of(variablesProvider));
             new DefaultPostgreSQLSessionVariableHandler().handle(connectionSession, "datestyle", "postgres");
             verify(connectionSession.getRequiredSessionVariableRecorder()).setVariable("datestyle", "postgres");
         }