Search in sources :

Example 6 with SQLTransientConnectionException

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

the class SQLTransientConnectionExceptionTests method test12.

/**
     * Validate that the ordering of the returned Exceptions is correct
     * using traditional while loop
     */
@Test
public void test12() {
    SQLTransientConnectionException ex = new SQLTransientConnectionException("Exception 1", t1);
    SQLTransientConnectionException ex1 = new SQLTransientConnectionException("Exception 2");
    SQLTransientConnectionException ex2 = new SQLTransientConnectionException("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 : SQLTransientConnectionException(java.sql.SQLTransientConnectionException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 7 with SQLTransientConnectionException

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

the class SQLTransientConnectionExceptionTests method test8.

/**
     * Create SQLTransientConnectionException with null Throwable
     */
@Test
public void test8() {
    SQLTransientConnectionException ex = new SQLTransientConnectionException((Throwable) null);
    assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0);
}
Also used : SQLTransientConnectionException(java.sql.SQLTransientConnectionException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 8 with SQLTransientConnectionException

use of java.sql.SQLTransientConnectionException in project HikariCP by brettwooldridge.

the class PrometheusMetricsTrackerTest method recordConnectionTimeout.

@Test
public void recordConnectionTimeout() throws Exception {
    HikariConfig config = newHikariConfig();
    config.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
    config.setJdbcUrl("jdbc:h2:mem:");
    config.setMaximumPoolSize(2);
    config.setConnectionTimeout(250);
    String[] labelNames = { POOL_LABEL_NAME };
    String[] labelValues = { config.getPoolName() };
    try (HikariDataSource hikariDataSource = new HikariDataSource(config)) {
        try (Connection connection1 = hikariDataSource.getConnection();
            Connection connection2 = hikariDataSource.getConnection()) {
            try (Connection connection3 = hikariDataSource.getConnection()) {
            } catch (SQLTransientConnectionException ignored) {
            }
        }
        Double total = collectorRegistry.getSampleValue("hikaricp_connection_timeout_total", labelNames, labelValues);
        assertThat(total, is(1.0));
    }
}
Also used : SQLTransientConnectionException(java.sql.SQLTransientConnectionException) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 9 with SQLTransientConnectionException

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

the class SQLTransientConnectionExceptionTests method test13.

/**
     * Create SQLTransientConnectionException and validate it is an instance of
     * SQLNonTransientException
     */
@Test
public void test13() {
    Exception ex = new SQLTransientConnectionException();
    assertTrue(ex instanceof SQLTransientException);
}
Also used : SQLTransientConnectionException(java.sql.SQLTransientConnectionException) SQLTransientException(java.sql.SQLTransientException) SQLException(java.sql.SQLException) SQLTransientException(java.sql.SQLTransientException) SQLTransientConnectionException(java.sql.SQLTransientConnectionException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 10 with SQLTransientConnectionException

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

the class SQLTransientConnectionExceptionTests method test1.

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

Aggregations

SQLTransientConnectionException (java.sql.SQLTransientConnectionException)18 Test (org.testng.annotations.Test)14 BaseTest (util.BaseTest)14 SQLException (java.sql.SQLException)4 Connection (java.sql.Connection)3 Test (org.junit.Test)2 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)1 ProxyConnection (com.zaxxer.hikari.pool.ProxyConnection)1 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)1 ClockSource.elapsedDisplayString (com.zaxxer.hikari.util.ClockSource.elapsedDisplayString)1 SQLTransientException (java.sql.SQLTransientException)1 NamingException (javax.naming.NamingException)1