@Test(expected = SQLException.class) public void testGetConnection_FailToGetConnection() throws Exception { ComboPooledDataSource cpds1 = createMock(ComboPooledDataSource.class); expectNew(ComboPooledDataSource.class).andReturn(cpds1); cpds1.setDriverClass("org.postgresql.Driver"); expectLastCall().once(); cpds1.setJdbcUrl("jdbc:postgresql: expectLastCall().once(); cpds1.setUser("user"); expectLastCall().once(); cpds1.setPassword("password"); expectLastCall().once(); cpds1.setInitialPoolSize(0); expectLastCall().once(); cpds1.setMinPoolSize(0); expectLastCall().once(); cpds1.setMaxPoolSize(1); expectLastCall().once(); cpds1.setMaxIdleTime(600); expectLastCall().once(); cpds1.setAcquireRetryAttempts(5); expectLastCall().once(); cpds1.setAcquireRetryDelay(1000); expectLastCall().once(); Connection conn1 = createMock(Connection.class); expect(cpds1.getConnection()).andThrow(new SQLException("fail")); replay(cpds1, ComboPooledDataSource.class); replay(conn1); datasource.getConnection("host", "port", "user", "password"); }
Connection getConnection(String host, String port, String user, String password) throws SystemException, SQLException { LOG.debug("Getting connection for = {}:{}:{}", host, port, user); String key = composeKey(host, port, user, password); if (!key.equals(dataSourceKey)) { resetDataSource(host, port, user, password); } Connection conn = dataSource.getConnection(); LOG.debug("Acquired connection = {}", conn); return conn; }
HAWQDataSource { Connection getConnection(String host, String port, String user, String password) throws SystemException, SQLException { LOG.debug("Getting connection for = {}:{}:{}", host, port, user); String key = composeKey(host, port, user, password); if (!key.equals(dataSourceKey)) { resetDataSource(host, port, user, password); } Connection conn = dataSource.getConnection(); LOG.debug("Acquired connection = {}", conn); return conn; } }
HAWQDataSource { Connection getConnection(String host, String port, String user, String password) throws SystemException, SQLException { LOG.debug("Getting connection for = {}:{}:{}", host, port, user); String key = composeKey(host, port, user, password); if (!key.equals(dataSourceKey)) { resetDataSource(host, port, user, password); } Connection conn = dataSource.getConnection(); LOG.debug("Acquired connection = {}", conn); return conn; }  }
HAWQDataSource { Connection getConnection(String host, String port, String user, String password) throws SystemException, SQLException { LOG.debug("Getting connection for = {}:{}:{}", host, port, user); String key = composeKey(host, port, user, password); if (!key.equals(dataSourceKey)) { resetDataSource(host, port, user, password); } Connection conn = dataSource.getConnection(); LOG.debug("Acquired connection = {}", conn); return conn; }   }
HAWQDataSource { Connection getConnection(String host, String port, String user, String password) throws SystemException, SQLException { LOG.debug("Getting connection for = {}:{}:{}", host, port, user); String key = composeKey(host, port, user, password); if (!key.equals(dataSourceKey)) { resetDataSource(host, port, user, password); } Connection conn = dataSource.getConnection(); LOG.debug("Acquired connection = {}", conn); return conn; }    }