@Test public void testGetConnectionPoolEnabledNoPoolProps() throws SQLException { Driver mockDriver = mock(Driver.class); when(DriverManager.getDriver("test-url")).thenReturn(mockDriver); when(mockDriver.connect("test-url", connProps)).thenReturn(mockConnection); Driver mockDriver2 = mock(Driver.class); ; when(DriverManager.getDriver("test-url-2")).thenReturn(mockDriver2); Connection mockConnection2 = mock(Connection.class); when(mockDriver2.connect("test-url-2", connProps)).thenReturn(mockConnection2); 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); }
public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } private  ConnectionManager();   ConnectionManager(DataSourceFactory factory, Ticker ticker, long sleepIntervalNanos); }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } private  ConnectionManager();   ConnectionManager(DataSourceFactory factory, Ticker ticker, long sleepIntervalNanos); static ConnectionManager getInstance(); Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier); static String maskPassword(String password); }
ConnectionManager { public Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier) throws SQLException { Connection result; if (!isPoolEnabled) { LOG.debug("Requesting DriverManager.getConnection for server={}", server); result = DriverManager.getConnection(jdbcUrl, connectionConfiguration); } else { PoolDescriptor poolDescriptor = new PoolDescriptor(server, jdbcUrl, connectionConfiguration, poolConfiguration, qualifier); DataSource dataSource; try { LOG.debug("Requesting datasource for server={} and {}", server, poolDescriptor); dataSource = dataSources.getUnchecked(poolDescriptor); LOG.debug("Obtained datasource {} for server={} and {}", dataSource.hashCode(), server, poolDescriptor); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause() != null ? e.getCause() : e; throw new SQLException(String.format("Could not obtain datasource for server %s and %s : %s", server, poolDescriptor, cause.getMessage()), cause); } result = dataSource.getConnection(); } LOG.debug("Returning JDBC connection {} for server={}", result, server); return result; } private  ConnectionManager();   ConnectionManager(DataSourceFactory factory, Ticker ticker, long sleepIntervalNanos); static ConnectionManager getInstance(); Connection getConnection(String server, String jdbcUrl, Properties connectionConfiguration, boolean isPoolEnabled, Properties poolConfiguration, String qualifier); static String maskPassword(String password);  }