This is an automated email from the ASF dual-hosted git repository.
panjuan 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 3ded5df15de Reply error to Proxy's client if Error occurred (#19345)
3ded5df15de is described below
commit 3ded5df15de3774596d3ed1b44aadaed1e4c4cc5
Author: 吴伟杰 <[email protected]>
AuthorDate: Tue Jul 19 13:10:37 2022 +0800
Reply error to Proxy's client if Error occurred (#19345)
* Reply error to Proxy's client if Error occurred
* Fix checkstyle
* Complete CommandExecutorTaskTest
---
.../proxy/frontend/command/CommandExecutorTask.java | 4 ++++
.../frontend/command/CommandExecutorTaskTest.java | 19 ++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index a00983717ba..2866dd3fc4e 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -80,6 +80,10 @@ public final class CommandExecutorTask implements Runnable {
} catch (final Exception ex) {
// CHECKSTYLE:ON
processException(ex);
+ // CHECKSTYLE:OFF
+ } catch (final Error error) {
+ // CHECKSTYLE:ON
+ processException(new RuntimeException(error));
} finally {
// TODO optimize SQLStatementDatabaseHolder
SQLStatementDatabaseHolder.remove();
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 589e2ed6b92..84c1d19ae9e 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
@@ -51,6 +51,7 @@ import java.sql.SQLException;
import java.util.Collections;
import java.util.Optional;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -153,7 +154,7 @@ public final class CommandExecutorTaskTest extends
ProxyContextRestorer {
@SuppressWarnings("unchecked")
@Test
- public void assertRunWithError() throws BackendConnectionException,
SQLException {
+ public void assertRunWithException() throws BackendConnectionException,
SQLException {
RuntimeException mockException = new RuntimeException("mock");
doThrow(mockException).when(commandExecutor).execute();
when(engine.getCodecEngine().createPacketPayload(message,
StandardCharsets.UTF_8)).thenReturn(payload);
@@ -168,4 +169,20 @@ public final class CommandExecutorTaskTest extends
ProxyContextRestorer {
verify(handlerContext).flush();
verify(backendConnection).closeExecutionResources();
}
+
+ @Test
+ public void assertRunWithOOMError() throws BackendConnectionException,
SQLException {
+ doThrow(OutOfMemoryError.class).when(commandExecutor).execute();
+ when(engine.getCodecEngine().createPacketPayload(message,
StandardCharsets.UTF_8)).thenReturn(payload);
+ when(engine.getCommandExecuteEngine().getCommandPacket(payload,
commandPacketType, connectionSession)).thenReturn(commandPacket);
+
when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
+
when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType,
commandPacket, connectionSession)).thenReturn(commandExecutor);
+
when(engine.getCommandExecuteEngine().getErrorPacket(any(RuntimeException.class))).thenReturn(databasePacket);
+
when(engine.getCommandExecuteEngine().getOtherPacket(connectionSession)).thenReturn(Optional.of(databasePacket));
+ CommandExecutorTask actual = new CommandExecutorTask(engine,
connectionSession, handlerContext, message);
+ actual.run();
+ verify(handlerContext, times(2)).write(databasePacket);
+ verify(handlerContext).flush();
+ verify(backendConnection).closeExecutionResources();
+ }
}