未验证 提交 5e7787ba 编写于 作者: S sluk3r 提交者: GitHub

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: Nwangxichun <wangxichun@jd.com>
上级 fe11a3e9
......@@ -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'"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册