Search in sources :

Example 36 with SQLTimeoutException

use of java.sql.SQLTimeoutException in project jdk8u_jdk by JetBrains.

the class SQLTimeoutExceptionTests method test1.

/**
     * Create SQLTimeoutException with no-arg constructor
     */
@Test
public void test1() {
    SQLTimeoutException ex = new SQLTimeoutException();
    assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0);
}
Also used : SQLTimeoutException(java.sql.SQLTimeoutException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 37 with SQLTimeoutException

use of java.sql.SQLTimeoutException in project jdk8u_jdk by JetBrains.

the class SQLTimeoutExceptionTests method test7.

/**
     * Create SQLTimeoutException with message, and Throwable
     */
@Test
public void test7() {
    SQLTimeoutException ex = new SQLTimeoutException(reason, t);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
Also used : SQLTimeoutException(java.sql.SQLTimeoutException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 38 with SQLTimeoutException

use of java.sql.SQLTimeoutException in project jdk8u_jdk by JetBrains.

the class SQLTimeoutExceptionTests method test12.

/**
     * Validate that the ordering of the returned Exceptions is correct
     * using traditional while loop
     */
@Test
public void test12() {
    SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
    SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
    SQLTimeoutException ex2 = new SQLTimeoutException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
Also used : SQLException(java.sql.SQLException) SQLTimeoutException(java.sql.SQLTimeoutException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 39 with SQLTimeoutException

use of java.sql.SQLTimeoutException in project jaybird by FirebirdSQL.

the class WireDatabaseConnectionTest method testConnectTimeout_noResponse.

/**
 * Tests the connect timeout if the server does not respond.
 */
@Test
public void testConnectTimeout_noResponse() throws Exception {
    BlackholeServer server = new BlackholeServer();
    Thread thread = new Thread(server);
    thread.start();
    long startTime = System.currentTimeMillis();
    try {
        connectionInfo.setPortNumber(server.getPort());
        connectionInfo.setDatabaseName("somedb");
        connectionInfo.setConnectTimeout(2);
        WireDatabaseConnection gdsConnection = new WireDatabaseConnection(connectionInfo);
        gdsConnection.socketConnect();
        gdsConnection.identify();
        fail("Expected connection to fail");
    } catch (SQLTimeoutException e) {
        long endTime = System.currentTimeMillis();
        long difference = endTime - startTime;
        assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode());
        assertEquals("Unexpected timeout duration (in ms)", 2000, difference, TIMEOUT_DELTA_MS);
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Expected SQLTimeoutException to be thrown");
    } finally {
        server.stop();
        thread.join();
    }
}
Also used : SQLException(java.sql.SQLException) SQLTimeoutException(java.sql.SQLTimeoutException) BlackholeServer(org.firebirdsql.common.BlackholeServer) Test(org.junit.Test)

Example 40 with SQLTimeoutException

use of java.sql.SQLTimeoutException in project derby by apache.

the class SQLExceptionFactory method getSQLException.

/**
 * <p>
 * method to construct SQLException
 * version specific drivers can overload this method to create
 * version specific exceptions
 * </p>
 *
 * <p>
 * This implementation creates JDBC 4 exceptions.
 * </p>
 *
 * <pre>
 * SQLSTATE CLASS (prefix)     Exception
 * 0A                          java.sql.SQLFeatureNotSupportedException
 * 08                          java.sql.SQLNonTransientConnectionException
 * 22                          java.sql.SQLDataException
 * 28                          java.sql.SQLInvalidAuthorizationSpecException
 * 40                          java.sql.SQLTransactionRollbackException
 * 42                          java.sql.SQLSyntaxErrorException
 * </pre>
 */
@Override
public SQLException getSQLException(String message, String messageId, SQLException next, int severity, Throwable t, Object... args) {
    String sqlState = StandardException.getSQLStateFromIdentifier(messageId);
    // 
    // Create dummy exception which ferries arguments needed to serialize
    // SQLExceptions across the DRDA network layer.
    // 
    StandardException ferry = wrapArgsForTransportAcrossDRDA(messageId, t, args);
    final SQLException ex;
    if (sqlState.startsWith(SQLState.CONNECTIVITY_PREFIX)) {
        // no derby sqlstate belongs to
        // TransientConnectionException DERBY-3074
        ex = new SQLNonTransientConnectionException(message, sqlState, severity, ferry);
    } else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
        ex = new SQLDataException(message, sqlState, severity, ferry);
    } else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
        if (sqlState.equals(SQLState.LANG_NULL_INTO_NON_NULL))
            ex = new SQLIntegrityConstraintViolationException(message, sqlState, severity, ferry);
        else if (sqlState.equals(SQLState.LANG_CHECK_CONSTRAINT_VIOLATED))
            ex = new DerbySQLIntegrityConstraintViolationException(message, sqlState, severity, ferry, args[1], args[0]);
        else
            ex = new DerbySQLIntegrityConstraintViolationException(message, sqlState, severity, ferry, args[0], args[1]);
    } else if (sqlState.startsWith(SQLState.AUTHORIZATION_SPEC_PREFIX)) {
        ex = new SQLInvalidAuthorizationSpecException(message, sqlState, severity, ferry);
    } else if (sqlState.startsWith(SQLState.TRANSACTION_PREFIX)) {
        ex = new SQLTransactionRollbackException(message, sqlState, severity, ferry);
    } else if (sqlState.startsWith(SQLState.LSE_COMPILATION_PREFIX)) {
        ex = new SQLSyntaxErrorException(message, sqlState, severity, ferry);
    } else if (sqlState.startsWith(SQLState.UNSUPPORTED_PREFIX)) {
        ex = new SQLFeatureNotSupportedException(message, sqlState, severity, ferry);
    } else if (sqlState.equals(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT.substring(0, 5)) || sqlState.equals(SQLState.LOGIN_TIMEOUT.substring(0, 5))) {
        ex = new SQLTimeoutException(message, sqlState, severity, ferry);
    } else {
        ex = new SQLException(message, sqlState, severity, ferry);
    }
    // If the argument ferry has recorded any extra next exceptions,
    // graft them into the parent exception.
    SQLException ferriedExceptions = ferry.getNextException();
    if (ferriedExceptions != null) {
        ex.setNextException(ferriedExceptions);
    }
    if (next != null) {
        ex.setNextException(next);
    }
    return ex;
}
Also used : SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) StandardException(org.apache.derby.shared.common.error.StandardException) SQLTransactionRollbackException(java.sql.SQLTransactionRollbackException) SQLDataException(java.sql.SQLDataException) SQLException(java.sql.SQLException) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) DerbySQLIntegrityConstraintViolationException(org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) SQLTimeoutException(java.sql.SQLTimeoutException) SQLInvalidAuthorizationSpecException(java.sql.SQLInvalidAuthorizationSpecException) DerbySQLIntegrityConstraintViolationException(org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException)

Aggregations

SQLTimeoutException (java.sql.SQLTimeoutException)53 SQLException (java.sql.SQLException)36 ResultSet (java.sql.ResultSet)20 Statement (java.sql.Statement)17 Test (org.testng.annotations.Test)15 Test (org.junit.Test)14 BaseTest (util.BaseTest)14 Connection (java.sql.Connection)12 PreparedStatement (java.sql.PreparedStatement)10 JdbcTest (org.apache.drill.categories.JdbcTest)8 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)7 ArrayList (java.util.ArrayList)7 HadoopException (org.apache.ranger.plugin.client.HadoopException)6 ScreenCreator (org.apache.drill.exec.physical.impl.ScreenCreator)4 MessageEvent (org.cerberus.engine.entity.MessageEvent)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Ignore (org.junit.Ignore)3 IOException (java.io.IOException)2 BatchUpdateException (java.sql.BatchUpdateException)2 CallableStatement (java.sql.CallableStatement)2