@Test public void testShutDownDbmsPools() throws SQLException { DBConnectionManager dbcManagerSpy = getDBConnectionManagerSpyWithPooling(); PooledDataSource dataSourceMock = mock(PooledDataSource.class); dbcManagerSpy.dbmsPoolTable = getHashTableObject1(dataSourceMock); Hashtable<String, PooledDataSourceProvider> providerTable = new Hashtable<>(); PooledDataSourceProvider dataSourceProviderMock = mock(PooledDataSourceProvider.class); doNothing().when(dataSourceProviderMock).closePooledDataSource(any(DataSource.class)); providerTable.put(C3P0PooledDataSourceProvider.C3P0_DATASOURCE_PROVIDER_NAME, dataSourceProviderMock); dbcManagerSpy.providerTable = providerTable; Connection connMock = mock(Connection.class); doReturn(connMock).when(dbcManagerSpy).getPooledConnection(any(DBType.class) , any(String.class), any(String.class), any(String.class)); dbcManagerSpy.getConnection(DBType.DB2, EMPTY_STRING, DB_URL, DHARMA_USER, DHARMA_PASSWORD, getPoolingProperties()); dbcManagerSpy.shutdownDbmsPools(); verify(dataSourceProviderMock, times(1)).closePooledDataSource(any(DataSource.class)); assertNull(dbcManagerSpy.dbmsPoolTable); }
public synchronized void shutdownDbmsPools() { datasourceCleaner.shutdown(); datasourceCleaner = null; cleanerThread.interrupt(); cleanerThread = null; if (dbmsPoolTable == null) { return; } Enumeration<String> allDbmsKeys = dbmsPoolTable.keys(); while (allDbmsKeys.hasMoreElements()) { String dbmsKey = allDbmsKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(dbmsKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbmsKey); for (DataSource ds : dsTable.values()) { try { provider.closePooledDataSource(ds); } catch (SQLException e) { } } dsTable.clear(); } dbmsPoolTable.clear(); dbmsPoolTable = null; }
DBConnectionManager { public synchronized void shutdownDbmsPools() { datasourceCleaner.shutdown(); datasourceCleaner = null; cleanerThread.interrupt(); cleanerThread = null; if (dbmsPoolTable == null) { return; } Enumeration<String> allDbmsKeys = dbmsPoolTable.keys(); while (allDbmsKeys.hasMoreElements()) { String dbmsKey = allDbmsKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(dbmsKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbmsKey); for (DataSource ds : dsTable.values()) { try { provider.closePooledDataSource(ds); } catch (SQLException e) { } } dsTable.clear(); } dbmsPoolTable.clear(); dbmsPoolTable = null; } }
DBConnectionManager { public synchronized void shutdownDbmsPools() { datasourceCleaner.shutdown(); datasourceCleaner = null; cleanerThread.interrupt(); cleanerThread = null; if (dbmsPoolTable == null) { return; } Enumeration<String> allDbmsKeys = dbmsPoolTable.keys(); while (allDbmsKeys.hasMoreElements()) { String dbmsKey = allDbmsKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(dbmsKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbmsKey); for (DataSource ds : dsTable.values()) { try { provider.closePooledDataSource(ds); } catch (SQLException e) { } } dsTable.clear(); } dbmsPoolTable.clear(); dbmsPoolTable = null; } protected  DBConnectionManager(); }
DBConnectionManager { public synchronized void shutdownDbmsPools() { datasourceCleaner.shutdown(); datasourceCleaner = null; cleanerThread.interrupt(); cleanerThread = null; if (dbmsPoolTable == null) { return; } Enumeration<String> allDbmsKeys = dbmsPoolTable.keys(); while (allDbmsKeys.hasMoreElements()) { String dbmsKey = allDbmsKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(dbmsKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbmsKey); for (DataSource ds : dsTable.values()) { try { provider.closePooledDataSource(ds); } catch (SQLException e) { } } dsTable.clear(); } dbmsPoolTable.clear(); dbmsPoolTable = null; } protected  DBConnectionManager(); static DBConnectionManager getInstance(); void finalize(); synchronized Connection getConnection(DBType aDbType, String aAuthType, String aDbUrl, String aUsername, String aPassword, Properties properties); void cleanDataSources(); synchronized void shutdownDbmsPools(); int getDbmsPoolSize(); int getConnectionSize(DBType aDbType, String aDbUrl); int getCheckedOutConnectionSize(DBType aDbType, String aDbUrl); int getCheckedInConnectionSize(DBType aDbType, String aDbUrl); int getTotalConnectionSize(); int getTotalCheckedOutConnectionSize(); int getTotalCheckedInConnectionSize(); }
DBConnectionManager { public synchronized void shutdownDbmsPools() { datasourceCleaner.shutdown(); datasourceCleaner = null; cleanerThread.interrupt(); cleanerThread = null; if (dbmsPoolTable == null) { return; } Enumeration<String> allDbmsKeys = dbmsPoolTable.keys(); while (allDbmsKeys.hasMoreElements()) { String dbmsKey = allDbmsKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(dbmsKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbmsKey); for (DataSource ds : dsTable.values()) { try { provider.closePooledDataSource(ds); } catch (SQLException e) { } } dsTable.clear(); } dbmsPoolTable.clear(); dbmsPoolTable = null; } protected  DBConnectionManager(); static DBConnectionManager getInstance(); void finalize(); synchronized Connection getConnection(DBType aDbType, String aAuthType, String aDbUrl, String aUsername, String aPassword, Properties properties); void cleanDataSources(); synchronized void shutdownDbmsPools(); int getDbmsPoolSize(); int getConnectionSize(DBType aDbType, String aDbUrl); int getCheckedOutConnectionSize(DBType aDbType, String aDbUrl); int getCheckedInConnectionSize(DBType aDbType, String aDbUrl); int getTotalConnectionSize(); int getTotalCheckedOutConnectionSize(); int getTotalCheckedInConnectionSize();  }