You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/02/06 06:21:46 UTC

[shardingsphere] branch master updated: Fix SET DIST VARIABLE system-log-level (#24016)

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

jianglongtao 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 74085d11055 Fix SET DIST VARIABLE system-log-level (#24016)
74085d11055 is described below

commit 74085d110550614bbb9aba7c80bfbe5e252ba7b7
Author: ChenJiaHao <Pa...@163.com>
AuthorDate: Mon Feb 6 14:21:37 2023 +0800

    Fix SET DIST VARIABLE system-log-level (#24016)
    
    * Fix get Enum from props value
    
    * Add SET DIST VARIABLE test cases for system-log-level
    
    * Optimize unit test
---
 .../infra/util/props/TypedPropertyValue.java       |  2 +-
 .../ral/updatable/SetDistVariableExecutorTest.java | 40 ++++++++++++++++++----
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java
index 10304df210e..348595b00b0 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValue.java
@@ -58,7 +58,7 @@ public final class TypedPropertyValue {
     
     private Enum<?> getEnumValue(final TypedPropertyKey key, final String value) throws TypedPropertyValueException {
         try {
-            return (Enum<?>) key.getType().getMethod("valueOf", String.class).invoke(null, value);
+            return (Enum<?>) key.getType().getMethod("valueOf", String.class).invoke(null, value.toUpperCase());
         } catch (final ReflectiveOperationException | IllegalArgumentException ex) {
             throw new TypedPropertyValueException(key, value);
         }
diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java
index 61c2e511ad9..538bf1b966c 100644
--- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java
+++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutorTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
 import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.SetDistVariableStatement;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.config.props.LoggerLevel;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
@@ -32,6 +33,7 @@ import org.apache.shardingsphere.mode.manager.standalone.StandaloneModeContextMa
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.exception.InvalidValueException;
 import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
@@ -78,12 +80,7 @@ public final class SetDistVariableExecutorTest extends ProxyContextRestorer {
     
     @Test
     public void assertExecuteWithConfigurationKey() throws SQLException {
-        StandaloneModeContextManager standaloneModeContextManager = new StandaloneModeContextManager();
-        ContextManager contextManager = new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()),
-                new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class),
-                        new ModeConfiguration("Standalone", null), standaloneModeContextManager, mock(LockContext.class), new EventBusContext()));
-        standaloneModeContextManager.setContextManagerAware(contextManager);
-        ProxyContext.init(contextManager);
+        ContextManager contextManager = mockContextManager();
         SetDistVariableStatement statement = new SetDistVariableStatement("proxy_frontend_flush_threshold", "1024");
         SetDistVariableHandler handler = new SetDistVariableHandler();
         handler.init(statement, connectionSession);
@@ -92,4 +89,35 @@ public final class SetDistVariableExecutorTest extends ProxyContextRestorer {
         assertThat(actualValue.toString(), is("1024"));
         assertThat(contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD), is(1024));
     }
+    
+    @Test
+    public void assertExecuteWithSystemLogLevel() throws SQLException {
+        ContextManager contextManager = mockContextManager();
+        SetDistVariableStatement statement = new SetDistVariableStatement("system_log_level", "debug");
+        SetDistVariableHandler handler = new SetDistVariableHandler();
+        handler.init(statement, connectionSession);
+        handler.execute();
+        Object actualValue = contextManager.getMetaDataContexts().getMetaData().getProps().getProps().get("system-log-level");
+        assertThat(actualValue.toString(), is("DEBUG"));
+        assertThat(contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.SYSTEM_LOG_LEVEL), is(LoggerLevel.DEBUG));
+    }
+    
+    @Test(expected = InvalidValueException.class)
+    public void assertExecuteWithWrongSystemLogLevel() throws SQLException {
+        mockContextManager();
+        SetDistVariableStatement statement = new SetDistVariableStatement("system_log_level", "invalid");
+        SetDistVariableHandler handler = new SetDistVariableHandler();
+        handler.init(statement, connectionSession);
+        handler.execute();
+    }
+    
+    private ContextManager mockContextManager() {
+        StandaloneModeContextManager standaloneModeContextManager = new StandaloneModeContextManager();
+        ContextManager contextManager = new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()),
+                new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(WorkerIdGenerator.class),
+                        new ModeConfiguration("Standalone", null), standaloneModeContextManager, mock(LockContext.class), new EventBusContext()));
+        standaloneModeContextManager.setContextManagerAware(contextManager);
+        ProxyContext.init(contextManager);
+        return contextManager;
+    }
 }