JDBCSSHRecordStoreConnection implements SSHRecordStoreConnection { @Override public void close() { if (con == null) { return; } try { con.close(); con = null; } catch (SQLException ex) { LOGGER.error("Failed to close connection: state - {}, code - {}, message - {}", ex.getSQLState(), ex.getErrorCode(), ex.getMessage()); } } JDBCSSHRecordStoreConnection(Connection con); @Override void setOperationTimeout(int queryTimeout); @Override void close(); @Override SSHCertRecord getSSHCertRecord(String instanceId, String service); @Override boolean updateSSHCertRecord(SSHCertRecord sshCertRecord); @Override boolean insertSSHCertRecord(SSHCertRecord sshCertRecord); @Override boolean deleteSSHCertRecord(String instanceId, String service); @Override int deleteExpiredSSHCertRecords(int expiryTimeMins); static final String DB_COLUMN_INSTANCE_ID; static final String DB_COLUMN_SERVICE; static final String DB_COLUMN_CLIENT_IP; static final String DB_COLUMN_PRIVATE_IP; static final String DB_COLUMN_PRINCIPALS; }
@Test public void testConnectionNullClose() throws SQLException { JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(mockConn); jdbcConn.con = null; jdbcConn.close(); }
@Test public void testConnectionCloseException() throws SQLException { Mockito.doThrow(new SQLException()).when(mockConn).close(); JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(mockConn); jdbcConn.close(); }