use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project JavaSegundasQuintas by ecteruel.
the class StatementRegressionTest method testBug74998.
/**
* Tests fix for BUG#74998 - readRemainingMultiPackets not computed correctly for rows larger than 16 MB.
*
* This bug is observed only when a multipacket uses packets 127 and 128. It happens due to the transition from positive to negative values in a signed byte
* numeric value (127 + 1 == -128).
*
* The test case forces a multipacket to use packets 127, 128 and 129, where packet 129 is 0-length, this being another boundary case.
* Query (*1) generates the following MySQL protocol packets from the server:
* - Packets 1 to 4 contain protocol control data and results metadata info. (*2)
* - Packets 5 to 126 contain each row "X". (*3)
* - Packets 127 to 129 contain row "Y..." as a multipacket (size("Y...") = 32*1024*1024-15 requires 3 packets). (*4)
* - Packet 130 contains row "Z". (*5)
*
* @throws Exception
*/
@Test
public void testBug74998() throws Exception {
int maxAllowedPacketAtServer = Integer.parseInt(((JdbcConnection) this.conn).getSession().getServerSession().getServerVariable("max_allowed_packet"));
int maxAllowedPacketMinimumForTest = 32 * 1024 * 1024;
boolean changeMaxAllowedPacket = maxAllowedPacketAtServer < maxAllowedPacketMinimumForTest;
if (!versionMeetsMinimum(5, 7)) {
this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'innodb_log_file_size'");
this.rs.next();
long defaultInnodbLogFileSize = this.rs.getInt(2);
assumeFalse(defaultInnodbLogFileSize < maxAllowedPacketMinimumForTest * 10, "This test requires innodb_log_file_size > " + (maxAllowedPacketMinimumForTest * 10));
}
// (*2)
createTable("testBug74998", "(id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, data LONGBLOB)");
Connection con1 = null;
try {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + maxAllowedPacketMinimumForTest);
}
StringBuilder query = new StringBuilder("INSERT INTO testBug74998 (data) VALUES ('X')");
for (int i = 0; i < 121; i++) {
query.append(",('X')");
}
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
con1 = getConnectionWithProps(props);
Statement st = con1.createStatement();
// (*3)
assertEquals(122, st.executeUpdate(query.toString()));
// 32MB - 15Bytes causes an empty packet at the end of the multipacket sequence
int lengthOfRowForMultiPacket = maxAllowedPacketMinimumForTest - 15;
// (*4)
st.executeUpdate("INSERT INTO testBug74998 (data) VALUES (REPEAT('Y', " + lengthOfRowForMultiPacket + "))");
// (*5)
st.executeUpdate("INSERT INTO testBug74998 (data) VALUES ('Z')");
try {
// (*1)
this.rs = st.executeQuery("SELECT id, data FROM testBug74998 ORDER BY id");
} catch (CJCommunicationsException | CommunicationsException e) {
assertFalse(e.getCause() instanceof IOException && "Packets received out of order".compareTo(e.getCause().getMessage()) == 0, "Failed to correctly fetch all data from communications layer due to wrong processing of muli-packet number.");
}
// safety check
for (int i = 1; i <= 122; i++) {
assertTrue(this.rs.next());
assertEquals(i, this.rs.getInt(1));
assertEquals("X", this.rs.getString(2));
}
assertTrue(this.rs.next());
assertEquals(123, this.rs.getInt(1));
assertEquals("YYYYY", this.rs.getString(2).substring(0, 5));
assertEquals("YYYYY", this.rs.getString(2).substring(lengthOfRowForMultiPacket - 5));
assertTrue(this.rs.next());
assertEquals(124, this.rs.getInt(1));
assertEquals("Z", this.rs.getString(2));
assertFalse(this.rs.next());
} finally {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + maxAllowedPacketAtServer);
}
if (con1 != null) {
con1.close();
}
}
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project ABC by RuiPinto96274.
the class StatementRegressionTest method testBug74998.
/**
* Tests fix for BUG#74998 - readRemainingMultiPackets not computed correctly for rows larger than 16 MB.
*
* This bug is observed only when a multipacket uses packets 127 and 128. It happens due to the transition from positive to negative values in a signed byte
* numeric value (127 + 1 == -128).
*
* The test case forces a multipacket to use packets 127, 128 and 129, where packet 129 is 0-length, this being another boundary case.
* Query (*1) generates the following MySQL protocol packets from the server:
* - Packets 1 to 4 contain protocol control data and results metadata info. (*2)
* - Packets 5 to 126 contain each row "X". (*3)
* - Packets 127 to 129 contain row "Y..." as a multipacket (size("Y...") = 32*1024*1024-15 requires 3 packets). (*4)
* - Packet 130 contains row "Z". (*5)
*
* @throws Exception
*/
@Test
public void testBug74998() throws Exception {
int maxAllowedPacketAtServer = Integer.parseInt(((JdbcConnection) this.conn).getSession().getServerSession().getServerVariable("max_allowed_packet"));
int maxAllowedPacketMinimumForTest = 32 * 1024 * 1024;
boolean changeMaxAllowedPacket = maxAllowedPacketAtServer < maxAllowedPacketMinimumForTest;
if (!versionMeetsMinimum(5, 7)) {
this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'innodb_log_file_size'");
this.rs.next();
long defaultInnodbLogFileSize = this.rs.getInt(2);
assumeFalse(defaultInnodbLogFileSize < maxAllowedPacketMinimumForTest * 10, "This test requires innodb_log_file_size > " + (maxAllowedPacketMinimumForTest * 10));
}
// (*2)
createTable("testBug74998", "(id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, data LONGBLOB)");
Connection con1 = null;
try {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + maxAllowedPacketMinimumForTest);
}
StringBuilder query = new StringBuilder("INSERT INTO testBug74998 (data) VALUES ('X')");
for (int i = 0; i < 121; i++) {
query.append(",('X')");
}
Properties props = new Properties();
props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
con1 = getConnectionWithProps(props);
Statement st = con1.createStatement();
// (*3)
assertEquals(122, st.executeUpdate(query.toString()));
// 32MB - 15Bytes causes an empty packet at the end of the multipacket sequence
int lengthOfRowForMultiPacket = maxAllowedPacketMinimumForTest - 15;
// (*4)
st.executeUpdate("INSERT INTO testBug74998 (data) VALUES (REPEAT('Y', " + lengthOfRowForMultiPacket + "))");
// (*5)
st.executeUpdate("INSERT INTO testBug74998 (data) VALUES ('Z')");
try {
// (*1)
this.rs = st.executeQuery("SELECT id, data FROM testBug74998 ORDER BY id");
} catch (CJCommunicationsException | CommunicationsException e) {
assertFalse(e.getCause() instanceof IOException && "Packets received out of order".compareTo(e.getCause().getMessage()) == 0, "Failed to correctly fetch all data from communications layer due to wrong processing of muli-packet number.");
}
// safety check
for (int i = 1; i <= 122; i++) {
assertTrue(this.rs.next());
assertEquals(i, this.rs.getInt(1));
assertEquals("X", this.rs.getString(2));
}
assertTrue(this.rs.next());
assertEquals(123, this.rs.getInt(1));
assertEquals("YYYYY", this.rs.getString(2).substring(0, 5));
assertEquals("YYYYY", this.rs.getString(2).substring(lengthOfRowForMultiPacket - 5));
assertTrue(this.rs.next());
assertEquals(124, this.rs.getInt(1));
assertEquals("Z", this.rs.getString(2));
assertFalse(this.rs.next());
} finally {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + maxAllowedPacketAtServer);
}
if (con1 != null) {
con1.close();
}
}
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project aws-mysql-jdbc by awslabs.
the class ResultSetRegressionTest method testBug75309.
/**
* Tests fix for BUG#75309 - mysql connector/J driver in streaming mode will in the blocking state.
*
* @throws Exception
*/
@Test
public void testBug75309() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.socketTimeout.getKeyName(), "1000");
Connection testConn = getConnectionWithProps(props);
Statement testStmt = testConn.createStatement();
// turn on streaming results.
testStmt.setFetchSize(Integer.MIN_VALUE);
final ResultSet testRs1 = testStmt.executeQuery("SELECT 1 + 18446744073709551615");
assertThrows(SQLException.class, "Data truncation: BIGINT UNSIGNED value is out of range in '\\(1 \\+ 18446744073709551615\\)'", new Callable<Void>() {
public Void call() throws Exception {
testRs1.next();
return null;
}
});
try {
testRs1.close();
} catch (CJCommunicationsException | CommunicationsException ex) {
fail("ResultSet.close() locked while trying to read remaining, nonexistent, streamed data.");
}
try {
ResultSet testRs2 = testStmt.executeQuery("SELECT 1");
assertTrue(testRs2.next());
assertEquals(1, testRs2.getInt(1));
testRs2.close();
} catch (SQLException ex) {
if (ex.getMessage().startsWith("Streaming result set")) {
fail("There is a Streaming result set still active. No other statements can be issued on this connection.");
} else {
ex.printStackTrace();
fail(ex.getMessage());
}
}
testStmt.close();
testConn.close();
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project aws-mysql-jdbc by awslabs.
the class ExceptionsTest method testConstructors.
@Test
public void testConstructors() {
new CommunicationsException(TEST_MESSAGE, new Throwable());
new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new PacketReceivedTimeHolder() {
}, new Exception());
new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
}, new Exception());
new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
new MySQLQueryInterruptedException();
new MySQLQueryInterruptedException(TEST_MESSAGE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLStatementCancelledException();
new MySQLStatementCancelledException(TEST_MESSAGE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTimeoutException();
new MySQLTimeoutException(TEST_MESSAGE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new MySQLTransactionRollbackException();
new MySQLTransactionRollbackException(TEST_MESSAGE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
new NotUpdatable(TEST_MESSAGE);
new OperationNotSupportedException();
new OperationNotSupportedException(TEST_MESSAGE);
new PacketTooBigException(TEST_MESSAGE);
new PacketTooBigException(0, 100);
new SQLError();
}
use of com.mysql.cj.jdbc.exceptions.CommunicationsException in project aws-mysql-jdbc by awslabs.
the class StatementRegressionTest method testBug74998.
/**
* Tests fix for BUG#74998 - readRemainingMultiPackets not computed correctly for rows larger than 16 MB.
*
* This bug is observed only when a multipacket uses packets 127 and 128. It happens due to the transition from positive to negative values in a signed byte
* numeric value (127 + 1 == -128).
*
* The test case forces a multipacket to use packets 127, 128 and 129, where packet 129 is 0-length, this being another boundary case.
* Query (*1) generates the following MySQL protocol packets from the server:
* - Packets 1 to 4 contain protocol control data and results metadata info. (*2)
* - Packets 5 to 126 contain each row "X". (*3)
* - Packets 127 to 129 contain row "Y..." as a multipacket (size("Y...") = 32*1024*1024-15 requires 3 packets). (*4)
* - Packet 130 contains row "Z". (*5)
*
* @throws Exception
*/
@Test
public void testBug74998() throws Exception {
int maxAllowedPacketAtServer = Integer.parseInt(((JdbcConnection) this.conn).getSession().getServerSession().getServerVariable("max_allowed_packet"));
int maxAllowedPacketMinimumForTest = 32 * 1024 * 1024;
boolean changeMaxAllowedPacket = maxAllowedPacketAtServer < maxAllowedPacketMinimumForTest;
if (!versionMeetsMinimum(5, 7)) {
this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'innodb_log_file_size'");
this.rs.next();
long defaultInnodbLogFileSize = this.rs.getInt(2);
assumeFalse(defaultInnodbLogFileSize < maxAllowedPacketMinimumForTest * 10, "This test requires innodb_log_file_size > " + (maxAllowedPacketMinimumForTest * 10));
}
// (*2)
createTable("testBug74998", "(id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, data LONGBLOB)");
Connection con1 = null;
try {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + maxAllowedPacketMinimumForTest);
}
StringBuilder query = new StringBuilder("INSERT INTO testBug74998 (data) VALUES ('X')");
for (int i = 0; i < 121; i++) {
query.append(",('X')");
}
Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
con1 = getConnectionWithProps(props);
Statement st = con1.createStatement();
// (*3)
assertEquals(122, st.executeUpdate(query.toString()));
// 32MB - 15Bytes causes an empty packet at the end of the multipacket sequence
int lengthOfRowForMultiPacket = maxAllowedPacketMinimumForTest - 15;
// (*4)
st.executeUpdate("INSERT INTO testBug74998 (data) VALUES (REPEAT('Y', " + lengthOfRowForMultiPacket + "))");
// (*5)
st.executeUpdate("INSERT INTO testBug74998 (data) VALUES ('Z')");
try {
// (*1)
this.rs = st.executeQuery("SELECT id, data FROM testBug74998 ORDER BY id");
} catch (CJCommunicationsException | CommunicationsException e) {
assertFalse(e.getCause() instanceof IOException && "Packets received out of order".compareTo(e.getCause().getMessage()) == 0, "Failed to correctly fetch all data from communications layer due to wrong processing of muli-packet number.");
}
// safety check
for (int i = 1; i <= 122; i++) {
assertTrue(this.rs.next());
assertEquals(i, this.rs.getInt(1));
assertEquals("X", this.rs.getString(2));
}
assertTrue(this.rs.next());
assertEquals(123, this.rs.getInt(1));
assertEquals("YYYYY", this.rs.getString(2).substring(0, 5));
assertEquals("YYYYY", this.rs.getString(2).substring(lengthOfRowForMultiPacket - 5));
assertTrue(this.rs.next());
assertEquals(124, this.rs.getInt(1));
assertEquals("Z", this.rs.getString(2));
assertFalse(this.rs.next());
} finally {
if (changeMaxAllowedPacket) {
this.stmt.executeUpdate("SET GLOBAL max_allowed_packet=" + maxAllowedPacketAtServer);
}
if (con1 != null) {
con1.close();
}
}
}
Aggregations