You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/05/18 03:03:03 UTC

[shardingsphere] branch master updated: Refactor ProxyContext.init() (#17765)

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

duanzhengqiang 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 b38152833d3 Refactor ProxyContext.init() (#17765)
b38152833d3 is described below

commit b38152833d3ff18d962d3d2a8e49d0599c4bd5f0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed May 18 11:02:57 2022 +0800

    Refactor ProxyContext.init() (#17765)
    
    * Refactor ProxyContext.init()
    
    * Refactor ProxyContext.init()
    
    * Refactor ProxyContext.init()
    
    * Fix test case
    
    * Fix test case
    
    * Fix test case
    
    * Fix test cases
    
    * Fix test cases
    
    * Fix test cases
    
    * Fix test cases
---
 .../frontend/command/CommandExecutorTaskTest.java     | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
index 1f20aa0bd9a..81c25935f71 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
@@ -24,13 +24,19 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
 import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
 import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
 import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
 import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
 import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
 import org.apache.shardingsphere.proxy.frontend.context.FrontendContext;
 import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -44,11 +50,11 @@ import java.util.Collections;
 import java.util.Optional;
 
 import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-@SuppressWarnings("unchecked")
 @RunWith(MockitoJUnitRunner.class)
 public final class CommandExecutorTaskTest {
     
@@ -82,6 +88,7 @@ public final class CommandExecutorTaskTest {
     @Mock
     private CommandExecutor commandExecutor;
     
+    @SuppressWarnings("rawtypes")
     @Mock
     private DatabasePacket databasePacket;
     
@@ -90,6 +97,9 @@ public final class CommandExecutorTaskTest {
     
     @Before
     public void setup() {
+        ContextManager contextManager = new ContextManager();
+        contextManager.init(new MetaDataContexts(mock(MetaDataPersistService.class)), mock(TransactionContexts.class), mock(InstanceContext.class));
+        ProxyContext.init(contextManager);
         when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
         when(handlerContext.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get()).thenReturn(StandardCharsets.UTF_8);
     }
@@ -107,9 +117,10 @@ public final class CommandExecutorTaskTest {
         verify(backendConnection).closeExecutionResources();
     }
     
+    @SuppressWarnings("unchecked")
     @Test
     public void assertRunNeedFlushByTrue() throws SQLException, BackendConnectionException {
-        when(queryCommandExecutor.execute()).thenReturn(Collections.singletonList(databasePacket));
+        when(queryCommandExecutor.execute()).thenReturn(Collections.singleton(databasePacket));
         when(engine.getCommandExecuteEngine().getCommandPacket(payload, commandPacketType, connectionSession)).thenReturn(commandPacket);
         when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, commandPacket, connectionSession)).thenReturn(queryCommandExecutor);
         when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
@@ -123,10 +134,11 @@ public final class CommandExecutorTaskTest {
         verify(backendConnection).closeExecutionResources();
     }
     
+    @SuppressWarnings("unchecked")
     @Test
     public void assertRunByCommandExecutor() throws SQLException, BackendConnectionException {
         when(engine.getFrontendContext()).thenReturn(frontendContext);
-        when(commandExecutor.execute()).thenReturn(Collections.singletonList(databasePacket));
+        when(commandExecutor.execute()).thenReturn(Collections.singleton(databasePacket));
         when(engine.getCommandExecuteEngine().getCommandPacket(payload, commandPacketType, connectionSession)).thenReturn(commandPacket);
         when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, commandPacket, connectionSession)).thenReturn(commandExecutor);
         when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
@@ -139,6 +151,7 @@ public final class CommandExecutorTaskTest {
         verify(backendConnection).closeExecutionResources();
     }
     
+    @SuppressWarnings("unchecked")
     @Test
     public void assertRunWithError() throws BackendConnectionException {
         RuntimeException mockException = new RuntimeException("mock");