com.mysql.jdbc.PacketTooBigException Java Examples

The following examples show how to use com.mysql.jdbc.PacketTooBigException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MySqlDatabaseLogExceptionFactoryTest.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * 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 );
}
 
Example #2
Source File: DefaultMessageQueueFlusher.java    From hermes with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: DatabaseLogExceptionFactoryTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * 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 );
}
 
Example #4
Source File: DatabaseLogExceptionFactoryTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@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 );
}
 
Example #5
Source File: MySqlDatabaseLogExceptionFactoryTest.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * 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 );
}
 
Example #6
Source File: PooledConnectionRegressionTest.java    From r-course with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: PooledConnectionRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source File: DatabaseLogExceptionFactoryTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * 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 );
}
 
Example #9
Source File: DatabaseLogExceptionFactoryTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@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 );
}