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 ed0b8a51576 Add more test cases on OKProxyStateTest (#37878)
ed0b8a51576 is described below

commit ed0b8a51576be68d81e783ee67b080d526f85260
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 28 23:13:52 2026 +0800

    Add more test cases on OKProxyStateTest (#37878)
---
 .../frontend/state/impl/OKProxyStateTest.java      | 35 ++++++++++++++++++++--
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
index 16d533044b4..7c360e65a2a 100644
--- 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
+++ 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
@@ -36,6 +36,7 @@ import 
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
 import 
org.apache.shardingsphere.proxy.frontend.executor.ConnectionThreadExecutorGroup;
+import org.apache.shardingsphere.proxy.frontend.executor.UserExecutorGroup;
 import 
org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
 import 
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
 import 
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
@@ -47,8 +48,10 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.internal.configuration.plugins.Plugins;
 
+import java.lang.reflect.Field;
 import java.util.Collections;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ExecutorService;
 
 import static org.mockito.ArgumentMatchers.any;
@@ -76,7 +79,7 @@ class OKProxyStateTest {
     
     @Test
     void assertExecuteWithDistributedTransaction() {
-        ContextManager contextManager = mockContextManager();
+        ContextManager contextManager = mockContextManager(TransactionType.XA);
         
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
         ConnectionSession connectionSession = mock(ConnectionSession.class, 
RETURNS_DEEP_STUBS);
         when(connectionSession.getConnectionId()).thenReturn(1);
@@ -86,7 +89,20 @@ class OKProxyStateTest {
         
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(1);
     }
     
-    private ContextManager mockContextManager() {
+    @Test
+    void assertExecuteWithLocalTransaction() {
+        ContextManager contextManager = 
mockContextManager(TransactionType.LOCAL);
+        
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
+        ConnectionSession connectionSession = mock(ConnectionSession.class, 
RETURNS_DEEP_STUBS);
+        
when(connectionSession.getConnectionContext().getTransactionContext().getTransactionType()).thenReturn(Optional.empty());
+        ExecutorService userExecutorService = mock(ExecutorService.class);
+        ExecutorService originalUserExecutorService = 
replaceUserExecutorService(userExecutorService);
+        new OKProxyState().execute(context, null, 
mock(DatabaseProtocolFrontendEngine.class), connectionSession);
+        verify(userExecutorService).execute(any(CommandExecutorTask.class));
+        restoreUserExecutorService(originalUserExecutorService);
+    }
+    
+    private ContextManager mockContextManager(final TransactionType 
transactionType) {
         ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, 
RETURNS_DEEP_STUBS);
         
when(metaData.getDatabase("foo_db")).thenReturn(mock(ShardingSphereDatabase.class,
 RETURNS_DEEP_STUBS));
         
when(metaData.getAllDatabases()).thenReturn(Collections.singleton(mock(ShardingSphereDatabase.class,
 RETURNS_DEEP_STUBS)));
@@ -94,7 +110,7 @@ class OKProxyStateTest {
         
when(metaData.getProps().<Integer>getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(0);
         
when(metaData.getProps().<Boolean>getValue(ConfigurationPropertyKey.PERSIST_SCHEMAS_TO_REPOSITORY_ENABLED)).thenReturn(true);
         TransactionRule transactionRule = mock(TransactionRule.class);
-        when(transactionRule.getDefaultType()).thenReturn(TransactionType.XA);
+        when(transactionRule.getDefaultType()).thenReturn(transactionType);
         when(metaData.getGlobalRuleMetaData()).thenReturn(new 
RuleMetaData(Collections.singletonList(transactionRule)));
         ComputeNodeInstanceContext computeNodeInstanceContext = 
mock(ComputeNodeInstanceContext.class);
         
when(computeNodeInstanceContext.getModeConfiguration()).thenReturn(mock(ModeConfiguration.class));
@@ -110,4 +126,17 @@ class OKProxyStateTest {
         executorServices.put(connectionId, result);
         return result;
     }
+    
+    @SneakyThrows(ReflectiveOperationException.class)
+    private ExecutorService replaceUserExecutorService(final ExecutorService 
executorService) {
+        Field executorServiceField = 
UserExecutorGroup.class.getDeclaredField("executorService");
+        ExecutorService result = (ExecutorService) 
Plugins.getMemberAccessor().get(executorServiceField, 
UserExecutorGroup.getInstance());
+        Plugins.getMemberAccessor().set(executorServiceField, 
UserExecutorGroup.getInstance(), executorService);
+        return result;
+    }
+    
+    @SneakyThrows(ReflectiveOperationException.class)
+    private void restoreUserExecutorService(final ExecutorService 
executorService) {
+        
Plugins.getMemberAccessor().set(UserExecutorGroup.class.getDeclaredField("executorService"),
 UserExecutorGroup.getInstance(), executorService);
+    }
 }

Reply via email to