提交 70bc6569 编写于 作者: C cherrylzhao

fix UnicastBackendHandler execute error while switching multi-schema.

上级 7b53cc9c
......@@ -23,6 +23,7 @@ import org.apache.shardingsphere.shardingproxy.backend.communication.DatabaseCom
import org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.shardingproxy.backend.response.BackendResponse;
import org.apache.shardingsphere.shardingproxy.backend.response.query.QueryData;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchema;
import org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchemas;
import org.apache.shardingsphere.shardingproxy.backend.text.TextProtocolBackendHandler;
......@@ -46,7 +47,12 @@ public final class UnicastBackendHandler implements TextProtocolBackendHandler {
@Override
public BackendResponse execute() {
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(LogicSchemas.getInstance().getLogicSchemas().values().iterator().next(), sql, backendConnection);
LogicSchema logicSchema = backendConnection.getLogicSchema();
if (null == logicSchema) {
logicSchema = LogicSchemas.getInstance().getLogicSchemas().values().iterator().next();
backendConnection.setCurrentSchema(logicSchema.getName());
}
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(logicSchema, sql, backendConnection);
return databaseCommunicationEngine.execute();
}
......
......@@ -30,6 +30,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
......@@ -39,11 +40,13 @@ import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class UnicastBackendHandlerTest {
@Spy
private BackendConnection backendConnection = new BackendConnection(TransactionType.LOCAL);
@Mock
......@@ -61,6 +64,7 @@ public final class UnicastBackendHandlerTest {
setDatabaseCommunicationEngine(backendHandler);
BackendResponse actual = backendHandler.execute();
assertThat(actual, instanceOf(UpdateResponse.class));
verify(backendConnection).setCurrentSchema(null);
backendHandler.execute();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册