Java源码示例:com.mysql.jdbc.PacketTooBigException

示例1
/**
 * Property value has priority
 */
@Test public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() {
  System.setProperty( DatabaseLogExceptionFactory.HOP_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE );

  DatabaseMeta databaseMeta = new DatabaseMeta();
  databaseMeta.setIDatabase(new MySqlDatabaseMeta());
  PacketTooBigException e = new PacketTooBigException();

  when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta );


  ILogExceptionBehaviour
    exceptionStrategy =
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new HopDatabaseException( e ) );
  String strategyName = exceptionStrategy.getClass().getName();
  assertEquals( THROWABLE, strategyName );
}
 
示例2
private boolean shoudlSkip(Exception e) {
	if (e instanceof InvocationTargetException) {
		InvocationTargetException ite = (InvocationTargetException) e;
		if (ite.getTargetException() instanceof DalException) {
			DalException de = (DalException) ite.getTargetException();
			if (de.getCause() instanceof BatchUpdateException) {
				BatchUpdateException bue = (BatchUpdateException) de.getCause();
				if (bue.getCause() instanceof PacketTooBigException) {
					return true;
				}
			}
		}
	}

	return false;
}
 
示例3
/**
 * Property value has priority
 */
@Test public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() {
  System.setProperty( DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE );

  DatabaseMeta databaseMeta = mock( DatabaseMeta.class );
  DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
  PacketTooBigException e = new PacketTooBigException();

  when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta );
  when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface );

  LogExceptionBehaviourInterface
    exceptionStrategy =
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) );
  String strategyName = exceptionStrategy.getClass().getName();
  assertEquals( THROWABLE, strategyName );
}
 
示例4
@Test public void testExceptionStrategyWithPacketTooBigExceptionPropSetY80driver() {
  System.setProperty( DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE );

  DatabaseMeta databaseMeta = mock( DatabaseMeta.class );
  DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
  com.mysql.cj.jdbc.exceptions.PacketTooBigException e = new com.mysql.cj.jdbc.exceptions.PacketTooBigException();

  when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta );
  when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface );

  LogExceptionBehaviourInterface
    exceptionStrategy =
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) );
  String strategyName = exceptionStrategy.getClass().getName();
  assertEquals( THROWABLE, strategyName );
}
 
示例5
/**
 * PDI-5153
 * Test that in case of PacketTooBigException exception there will be no stack trace in log
 */
@Test
public void testExceptionStrategyWithPacketTooBigException() {
  DatabaseMeta databaseMeta = new DatabaseMeta();
  databaseMeta.setIDatabase(new MySqlDatabaseMeta());
  PacketTooBigException e = new PacketTooBigException();

  when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta );

  ILogExceptionBehaviour
    exceptionStrategy =
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new HopDatabaseException( e ) );
  String strategyName = exceptionStrategy.getClass().getName();
  assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName );
}
 
示例6
/**
 * Tests that PacketTooLargeException doesn't clober the connection.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testPacketTooLargeException() throws Exception {
    final ConnectionEventListener conListener = new ConnectionListener();
    PooledConnection pc = null;

    pc = this.cpds.getPooledConnection();

    pc.addConnectionEventListener(conListener);

    createTable("testPacketTooLarge", "(field1 LONGBLOB)");

    Connection connFromPool = pc.getConnection();
    PreparedStatement pstmtFromPool = ((ConnectionWrapper) connFromPool).clientPrepare("INSERT INTO testPacketTooLarge VALUES (?)");

    this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
    this.rs.next();

    int maxAllowedPacket = this.rs.getInt(2);

    int numChars = (int) (maxAllowedPacket * 1.2);

    pstmtFromPool.setBinaryStream(1, new BufferedInputStream(new FileInputStream(newTempBinaryFile("testPacketTooLargeException", numChars))), numChars);

    try {
        pstmtFromPool.executeUpdate();
        fail("Expecting PacketTooLargeException");
    } catch (PacketTooBigException ptbe) {
        // We're expecting this one...
    }

    // This should still work okay, even though the last query on the same connection didn't...
    this.rs = connFromPool.createStatement().executeQuery("SELECT 1");

    assertTrue(this.connectionErrorEventCount == 0);
    assertTrue(this.closeEventCount == 0);
}
 
示例7
/**
 * Tests that PacketTooLargeException doesn't clober the connection.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testPacketTooLargeException() throws Exception {
    final ConnectionEventListener conListener = new ConnectionListener();
    PooledConnection pc = null;

    pc = this.cpds.getPooledConnection();

    pc.addConnectionEventListener(conListener);

    createTable("testPacketTooLarge", "(field1 LONGBLOB)");

    Connection connFromPool = pc.getConnection();
    PreparedStatement pstmtFromPool = ((ConnectionWrapper) connFromPool).clientPrepare("INSERT INTO testPacketTooLarge VALUES (?)");

    this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
    this.rs.next();

    int maxAllowedPacket = this.rs.getInt(2);

    int numChars = (int) (maxAllowedPacket * 1.2);

    pstmtFromPool.setBinaryStream(1, new BufferedInputStream(new FileInputStream(newTempBinaryFile("testPacketTooLargeException", numChars))), numChars);

    try {
        pstmtFromPool.executeUpdate();
        fail("Expecting PacketTooLargeException");
    } catch (PacketTooBigException ptbe) {
        // We're expecting this one...
    }

    // This should still work okay, even though the last query on the same connection didn't...
    this.rs = connFromPool.createStatement().executeQuery("SELECT 1");

    assertTrue(this.connectionErrorEventCount == 0);
    assertTrue(this.closeEventCount == 0);
}
 
示例8
/**
 * PDI-5153
 * Test that in case of PacketTooBigException exception there will be no stack trace in log
 */
@Test public void testExceptionStrategyWithPacketTooBigException() {
  DatabaseMeta databaseMeta = mock( DatabaseMeta.class );
  DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
  PacketTooBigException e = new PacketTooBigException();

  when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta );
  when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface );

  LogExceptionBehaviourInterface
    exceptionStrategy =
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) );
  String strategyName = exceptionStrategy.getClass().getName();
  assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName );
}
 
示例9
@Test public void testExceptionStrategyWithPacketTooBigException80driver() {
  DatabaseMeta databaseMeta = mock( DatabaseMeta.class );
  DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
  com.mysql.cj.jdbc.exceptions.PacketTooBigException e = new com.mysql.cj.jdbc.exceptions.PacketTooBigException();

  when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta );
  when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface );

  LogExceptionBehaviourInterface
    exceptionStrategy =
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) );
  String strategyName = exceptionStrategy.getClass().getName();
  assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName );
}