当前位置: 首页>>代码示例>>Java>>正文


Java CommunicationsException.getCause方法代码示例

本文整理汇总了Java中com.mysql.jdbc.CommunicationsException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java CommunicationsException.getCause方法的具体用法?Java CommunicationsException.getCause怎么用?Java CommunicationsException.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mysql.jdbc.CommunicationsException的用法示例。


在下文中一共展示了CommunicationsException.getCause方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBug74998

import com.mysql.jdbc.CommunicationsException; //导入方法依赖的package包/类
/**
 * 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
 *             if the test fails.
 */
public void testBug74998() throws Exception {
    int maxAllowedPacketAtServer = Integer.parseInt(((MySQLConnection) this.conn).getServerVariable("max_allowed_packet"));
    int maxAllowedPacketMinimumForTest = 32 * 1024 * 1024;
    if (maxAllowedPacketAtServer < maxAllowedPacketMinimumForTest) {
        fail("You need to increase max_allowed_packet to at least " + maxAllowedPacketMinimumForTest + " before running this test!");
    }

    createTable("testBug74998", "(id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, data LONGBLOB)"); // (*2)

    StringBuilder query = new StringBuilder("INSERT INTO testBug74998 (data) VALUES ('X')");
    for (int i = 0; i < 121; i++) {
        query.append(",('X')");
    }
    assertEquals(122, this.stmt.executeUpdate(query.toString())); // (*3)

    int lengthOfRowForMultiPacket = maxAllowedPacketMinimumForTest - 15; // 32MB - 15Bytes causes an empty packet at the end of the multipacket sequence

    this.stmt.executeUpdate("INSERT INTO testBug74998 (data) VALUES (REPEAT('Y', " + lengthOfRowForMultiPacket + "))"); // (*4)
    this.stmt.executeUpdate("INSERT INTO testBug74998 (data) VALUES ('Z')"); // (*5)

    try {
        this.rs = this.stmt.executeQuery("SELECT id, data FROM testBug74998 ORDER BY id"); // (*1)
    } catch (CommunicationsException e) {
        if (e.getCause() instanceof IOException && "Packets received out of order".compareTo(e.getCause().getMessage()) == 0) {
            fail("Failed to correctly fetch all data from communications layer due to wrong processing of muli-packet number.");
        } else {
            throw e;
        }
    }

    // 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());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:62,代码来源:StatementRegressionTest.java


注:本文中的com.mysql.jdbc.CommunicationsException.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。