Search in sources :

Example 1 with HikariProxyConnection

use of com.zaxxer.hikari.pool.HikariProxyConnection in project backend by CatalogueOfLife.

the class InitDbUtils method toPgConnection.

public static PgConnection toPgConnection(Connection c) throws SQLException {
    PgConnection pgc;
    if (c instanceof HikariProxyConnection) {
        HikariProxyConnection hpc = (HikariProxyConnection) c;
        pgc = hpc.unwrap(PgConnection.class);
    } else {
        pgc = (PgConnection) c;
    }
    return pgc;
}
Also used : PgConnection(org.postgresql.jdbc.PgConnection) HikariProxyConnection(com.zaxxer.hikari.pool.HikariProxyConnection)

Example 2 with HikariProxyConnection

use of com.zaxxer.hikari.pool.HikariProxyConnection in project pxf by greenplum-db.

the class ConnectionManagerTest method testGetConnectionPoolEnabledNoPoolProps.

@Test
public void testGetConnectionPoolEnabledNoPoolProps() throws SQLException {
    Driver mockDriver = mock(Driver.class);
    when(mockDriverManagerWrapper.getDriver("test-url")).thenReturn(mockDriver);
    when(mockDriver.connect("test-url", connProps)).thenReturn(mockConnection);
    when(mockDriver.acceptsURL("test-url")).thenReturn(true);
    DriverManager.registerDriver(mockDriver);
    Driver mockDriver2 = mock(Driver.class);
    when(mockDriverManagerWrapper.getDriver("test-url-2")).thenReturn(mockDriver2);
    Connection mockConnection2 = mock(Connection.class);
    when(mockDriver2.connect("test-url-2", connProps)).thenReturn(mockConnection2);
    when(mockDriver2.acceptsURL("test-url-2")).thenReturn(true);
    DriverManager.registerDriver(mockDriver2);
    Connection conn;
    for (int i = 0; i < 5; i++) {
        conn = manager.getConnection("test-server", "test-url", connProps, true, poolProps, null);
        assertNotNull(conn);
        assertTrue(conn instanceof HikariProxyConnection);
        assertSame(mockConnection, conn.unwrap(Connection.class));
        conn.close();
    }
    Connection conn2 = manager.getConnection("test-server", "test-url-2", connProps, true, poolProps, null);
    assertNotNull(conn2);
    assertTrue(conn2 instanceof HikariProxyConnection);
    assertSame(mockConnection2, conn2.unwrap(Connection.class));
    verify(mockDriver, times(1)).connect("test-url", connProps);
    verify(mockDriver2, times(1)).connect("test-url-2", connProps);
    DriverManager.deregisterDriver(mockDriver);
    DriverManager.deregisterDriver(mockDriver2);
}
Also used : Connection(java.sql.Connection) HikariProxyConnection(com.zaxxer.hikari.pool.HikariProxyConnection) Driver(java.sql.Driver) HikariProxyConnection(com.zaxxer.hikari.pool.HikariProxyConnection) Test(org.junit.jupiter.api.Test)

Aggregations

HikariProxyConnection (com.zaxxer.hikari.pool.HikariProxyConnection)2 Connection (java.sql.Connection)1 Driver (java.sql.Driver)1 Test (org.junit.jupiter.api.Test)1 PgConnection (org.postgresql.jdbc.PgConnection)1