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

chenjiahao 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 e9aa53dc4d4 Fix set dist variable for 
proxy_frontend_database_protocol_type (#29024)
e9aa53dc4d4 is described below

commit e9aa53dc4d4eac56bdf758faa8178a920858a62f
Author: Raigor <[email protected]>
AuthorDate: Mon Nov 13 16:15:08 2023 +0800

    Fix set dist variable for proxy_frontend_database_protocol_type (#29024)
---
 .../distsql/ral/updatable/SetDistVariableUpdater.java      |  6 +++++-
 .../distsql/ral/updatable/SetDistVariableUpdaterTest.java  | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdater.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdater.java
index f65f4468a9a..b3ccf4a83a5 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdater.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdater.java
@@ -26,6 +26,7 @@ import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigura
 import org.apache.shardingsphere.infra.props.TypedPropertyKey;
 import org.apache.shardingsphere.infra.props.TypedPropertyValue;
 import 
org.apache.shardingsphere.infra.props.exception.TypedPropertyValueException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
 import org.apache.shardingsphere.logging.constant.LoggingConstants;
 import org.apache.shardingsphere.logging.util.LoggingUtils;
 import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -82,7 +83,10 @@ public final class SetDistVariableUpdater implements 
ConnectionSessionRequiredRA
     private Object getValue(final TypedPropertyKey propertyKey, final String 
value) {
         try {
             Object propertyValue = new TypedPropertyValue(propertyKey, 
value).getValue();
-            return Enum.class.isAssignableFrom(propertyKey.getType()) ? 
propertyValue.toString() : propertyValue;
+            if (Enum.class.isAssignableFrom(propertyKey.getType())) {
+                return propertyValue.toString();
+            }
+            return TypedSPI.class.isAssignableFrom(propertyKey.getType()) ? 
((TypedSPI) propertyValue).getType().toString() : propertyValue;
         } catch (final TypedPropertyValueException ignored) {
             throw new InvalidValueException(value);
         }
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdaterTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdaterTest.java
index 9168951fcf3..4ff14fd8250 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdaterTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdaterTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.distsql.statement.ral.updatable.SetDistVariable
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
@@ -44,6 +45,7 @@ import org.slf4j.event.Level;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -79,6 +81,18 @@ class SetDistVariableUpdaterTest {
         
assertThat(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_ENABLED),
 is(false));
     }
     
+    @Test
+    void assertExecuteWithTypedSPI() {
+        SetDistVariableStatement statement = new 
SetDistVariableStatement("proxy_frontend_database_protocol_type", "MySQL");
+        SetDistVariableUpdater updater = new SetDistVariableUpdater();
+        ContextManager contextManager = mockContextManager();
+        
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
+        updater.executeUpdate(connectionSession, statement);
+        Object actualValue = 
contextManager.getMetaDataContexts().getMetaData().getProps().getProps().get("proxy-frontend-database-protocol-type");
+        assertThat(actualValue.toString(), is("MySQL"));
+        assertInstanceOf(MySQLDatabaseType.class, 
contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE));
+    }
+    
     @Test
     void assertExecuteWithSystemLogLevel() {
         SetDistVariableStatement statement = new 
SetDistVariableStatement("system_log_level", "debug");

Reply via email to