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 5e7787b  test cases added for MySQLErrPacketFactory (#7488)
5e7787b is described below

commit 5e7787ba93ca9465404e29ce05c11377978f8407
Author: sluk3r <[email protected]>
AuthorDate: Thu Sep 17 00:45:42 2020 +0800

    test cases added for MySQLErrPacketFactory (#7488)
    
    * assertNewInstanceWithDBCreateExistsException added
    
    * assertNewInstanceWithDBCreateExistsException, 
assertNewInstanceWithDBDropExistsException and 
assertNewInstanceWithTableExistsException added
    
    * 
assertNewInstanceWithCircuitBreakException,assertNewInstanceWithShardingSphereConfigurationException
 and assertNewInstanceWithSQLParsingException added
    
    * in-line variable refactor
    
    * changed for refactor of MySQLErrPacketFactory.newInstance
    
    * assertNewInstanceWithUnsupportedCommandException and 
assertNewInstanceWithUnsupportedPreparedStatementException added
    
    Co-authored-by: wangxichun <[email protected]>
---
 .../frontend/mysql/MySQLErrPacketFactoryTest.java  | 79 ++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
index 5f78bfd..37f83c3 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
@@ -18,11 +18,19 @@
 package org.apache.shardingsphere.proxy.frontend.mysql;
 
 import 
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
+import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
+import org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException;
+import 
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
+import org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
 import 
org.apache.shardingsphere.proxy.backend.exception.TableModifyInTransactionException;
 import 
org.apache.shardingsphere.proxy.backend.exception.UnknownDatabaseException;
 import 
org.apache.shardingsphere.proxy.backend.text.sctl.exception.InvalidShardingCTLFormatException;
 import 
org.apache.shardingsphere.proxy.backend.text.sctl.exception.UnsupportedShardingCTLTypeException;
+import 
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedCommandException;
+import 
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedPreparedStatementException;
+import 
org.apache.shardingsphere.sharding.route.engine.exception.TableExistsException;
+import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
 import org.junit.Test;
 
 import java.sql.SQLException;
@@ -115,4 +123,75 @@ public final class MySQLErrPacketFactoryTest {
         assertThat(actual.getSqlState(), is("C10002"));
         assertThat(actual.getErrorMessage(), is("Unknown exception: [No 
reason]"));
     }
+    
+    @Test
+    public void assertNewInstanceWithDBCreateExistsException() {
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
DBCreateExistsException("No reason"));
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(1007));
+        assertThat(actual.getSqlState(), is("HY000"));
+        assertThat(actual.getErrorMessage(), is("Can't create database 'No 
reason'; database exists"));
+    }
+    
+    @Test
+    public void assertNewInstanceWithDBDropExistsException() {
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
DBDropExistsException("No reason"));
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(1008));
+        assertThat(actual.getSqlState(), is("HY000"));
+        assertThat(actual.getErrorMessage(), is("Can't drop database 'No 
reason'; database doesn't exist"));
+    }
+    
+    @Test
+    public void assertNewInstanceWithTableExistsException() {
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
TableExistsException("table_name"));
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(1050));
+        assertThat(actual.getSqlState(), is("42S01"));
+        assertThat(actual.getErrorMessage(), is("Table 'table_name' already 
exists"));
+    }
+    
+    @Test
+    public void assertNewInstanceWithCircuitBreakException() {
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
CircuitBreakException());
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(10000));
+        assertThat(actual.getSqlState(), is("C10000"));
+        assertThat(actual.getErrorMessage(), is("Circuit break mode is ON."));
+    }
+    
+    @Test
+    public void assertNewInstanceWithShardingSphereConfigurationException() {
+        assertCommonException(MySQLErrPacketFactory.newInstance(new 
ShardingSphereConfigurationException("No reason")));
+    }
+    
+    @Test
+    public void assertNewInstanceWithSQLParsingException() {
+        assertCommonException(MySQLErrPacketFactory.newInstance(new 
SQLParsingException("No reason")));
+    }
+    
+    @Test
+    public void assertNewInstanceWithUnsupportedCommandException() {
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
UnsupportedCommandException("No reason"));
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(10001));
+        assertThat(actual.getSqlState(), is("C10001"));
+        assertThat(actual.getErrorMessage(), is("Unsupported command: [No 
reason]"));
+    }
+    
+    @Test
+    public void assertNewInstanceWithUnsupportedPreparedStatementException() {
+        MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
UnsupportedPreparedStatementException());
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(1295));
+        assertThat(actual.getSqlState(), is("HY000"));
+        assertThat(actual.getErrorMessage(), is("This command is not supported 
in the prepared statement protocol yet"));
+    }
+    
+    private void assertCommonException(final MySQLErrPacket actual) {
+        assertThat(actual.getSequenceId(), is(1));
+        assertThat(actual.getErrorCode(), is(1235));
+        assertThat(actual.getSqlState(), is("42000"));
+        assertThat(actual.getErrorMessage(), is("This version of ShardingProxy 
doesn't yet support this SQL. 'No reason'"));
+    }
 }

Reply via email to