This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit d3bd07b57b590a5143d8e1968556177f780f9ac6 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Jul 14 12:49:31 2024 -0400 Normalize instance variable names in tests --- .../apache/commons/dbcp2/TestConnectionPool.java | 32 ++--- .../dbcp2/TestParallelCreationWithNoIdle.java | 4 +- .../org/apache/commons/dbcp2/TesterConnection.java | 52 ++++---- .../commons/dbcp2/TesterPreparedStatement.java | 76 +++++------ .../org/apache/commons/dbcp2/TesterResultSet.java | 2 +- .../org/apache/commons/dbcp2/TesterStatement.java | 140 ++++++++++----------- 6 files changed, 153 insertions(+), 153 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java index 597d2cab..acee1c87 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java +++ b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java @@ -164,37 +164,37 @@ public abstract class TestConnectionPool { } final class TestThread implements Runnable { - final java.util.Random _random = new java.util.Random(); - boolean _complete; - boolean _failed; - int _iter = 100; - int _delay = 50; + final java.util.Random random = new java.util.Random(); + boolean complete; + boolean failed; + int iter = 100; + int delay = 50; public TestThread() { } public TestThread(final int iter) { - _iter = iter; + this.iter = iter; } public TestThread(final int iter, final int delay) { - _iter = iter; - _delay = delay; + this.iter = iter; + this.delay = delay; } public boolean complete() { - return _complete; + return complete; } public boolean failed() { - return _failed; + return failed; } @Override public void run() { - for (int i = 0; i < _iter; i++) { + for (int i = 0; i < iter; i++) { try { - Thread.sleep(_random.nextInt(_delay)); + Thread.sleep(random.nextInt(delay)); } catch (final Exception e) { // ignored } @@ -202,18 +202,18 @@ public abstract class TestConnectionPool { PreparedStatement stmt = conn.prepareStatement("select 'literal', SYSDATE from dual"); ResultSet rset = stmt.executeQuery()) { try { - Thread.sleep(_random.nextInt(_delay)); + Thread.sleep(random.nextInt(delay)); } catch (final Exception ignore) { // ignored } } catch (final Exception e) { e.printStackTrace(); - _failed = true; - _complete = true; + failed = true; + complete = true; break; } } - _complete = true; + complete = true; } } diff --git a/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java b/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java index 395d4a13..3b2ea0e1 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java +++ b/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java @@ -36,7 +36,7 @@ import org.junit.jupiter.api.Test; public class TestParallelCreationWithNoIdle { final class TestThread extends Thread { - final java.util.Random _random = new java.util.Random(); + final java.util.Random random = new java.util.Random(); final int iter; final int delay; final int delayAfter; @@ -72,7 +72,7 @@ public class TestParallelCreationWithNoIdle { return; } try { - Thread.sleep(_random.nextInt(timeMax)); + Thread.sleep(random.nextInt(timeMax)); } catch (final Exception e) { // ignored } diff --git a/src/test/java/org/apache/commons/dbcp2/TesterConnection.java b/src/test/java/org/apache/commons/dbcp2/TesterConnection.java index 00b60751..3e6e4bb4 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterConnection.java @@ -40,15 +40,15 @@ import java.util.concurrent.Executor; */ public class TesterConnection extends AbandonedTrace implements Connection { - protected boolean _open = true; - protected boolean _aborted; - protected boolean _autoCommit = true; - protected int _transactionIsolation = 1; - protected final DatabaseMetaData _metaData = new TesterDatabaseMetaData(); - protected String _catalog; + protected boolean open = true; + protected boolean aborted; + protected boolean autoCommit = true; + protected int transactionIsolation = 1; + protected final DatabaseMetaData metaData = new TesterDatabaseMetaData(); + protected String catalog; protected String schema; - protected Map<String,Class<?>> _typeMap; - protected boolean _readOnly; + protected Map<String,Class<?>> typeMap; + protected boolean readOnly; protected SQLWarning warnings; protected final String userName; protected Exception failure; @@ -62,8 +62,8 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public void abort(final Executor executor) throws SQLException { checkFailure(); - _aborted = true; - _open = false; + aborted = true; + open = false; } protected void checkFailure() throws SQLException { @@ -76,7 +76,7 @@ public class TesterConnection extends AbandonedTrace implements Connection { } protected void checkOpen() throws SQLException { - if (!_open) { + if (!open) { throw new SQLException("Connection is closed."); } checkFailure(); @@ -91,7 +91,7 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public void close() throws SQLException { checkFailure(); - _open = false; + open = false; } @Override @@ -155,13 +155,13 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public boolean getAutoCommit() throws SQLException { checkOpen(); - return _autoCommit; + return autoCommit; } @Override public String getCatalog() throws SQLException { checkOpen(); - return _catalog; + return catalog; } @Override @@ -182,7 +182,7 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public DatabaseMetaData getMetaData() throws SQLException { checkOpen(); - return _metaData; + return metaData; } @Override @@ -199,13 +199,13 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public int getTransactionIsolation() throws SQLException { checkOpen(); - return _transactionIsolation; + return transactionIsolation; } @Override public Map<String,Class<?>> getTypeMap() throws SQLException { checkOpen(); - return _typeMap; + return typeMap; } public String getUserName() { @@ -220,19 +220,19 @@ public class TesterConnection extends AbandonedTrace implements Connection { public boolean isAborted() throws SQLException { checkFailure(); - return _aborted; + return aborted; } @Override public boolean isClosed() throws SQLException { checkFailure(); - return !_open; + return !open; } @Override public boolean isReadOnly() throws SQLException { checkOpen(); - return _readOnly; + return readOnly; } public boolean isSqlExceptionOnClose() { @@ -241,7 +241,7 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public boolean isValid(final int timeout) throws SQLException { - return _open; + return open; } @Override @@ -352,13 +352,13 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public void setAutoCommit(final boolean autoCommit) throws SQLException { checkOpen(); - _autoCommit = autoCommit; + this.autoCommit = autoCommit; } @Override public void setCatalog(final String catalog) throws SQLException { checkOpen(); - _catalog = catalog; + this.catalog = catalog; } @Override @@ -389,7 +389,7 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public void setReadOnly(final boolean readOnly) throws SQLException { checkOpen(); - _readOnly = readOnly; + this.readOnly = readOnly; } @Override @@ -415,13 +415,13 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public void setTransactionIsolation(final int level) throws SQLException { checkOpen(); - _transactionIsolation = level; + this.transactionIsolation = level; } @Override public void setTypeMap(final Map<String,Class<?>> map) throws SQLException { checkOpen(); - _typeMap = map; + this.typeMap = map; } public void setWarnings(final SQLWarning warning) { diff --git a/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java b/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java index 3d11bbb7..b171c857 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java @@ -40,17 +40,17 @@ import java.util.Calendar; */ public class TesterPreparedStatement extends TesterStatement implements PreparedStatement { - private final ResultSetMetaData _resultSetMetaData = null; - private String _sql; - private String _catalog; - private int _autoGeneratedKeys = 1; - private int[] _columnIndexes; - private String[] _columnNames; + private final ResultSetMetaData resultSetMetaData = null; + private String sql; + private String catalog; + private int autoGeneratedKeys = 1; + private int[] columnIndexes; + private String[] columnNames; public TesterPreparedStatement(final Connection conn) { super(conn); try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -58,9 +58,9 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared public TesterPreparedStatement(final Connection conn, final String sql) { super(conn); - _sql = sql; + this.sql = sql; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -68,10 +68,10 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared public TesterPreparedStatement(final Connection conn, final String sql, final int autoGeneratedKeys) { super(conn); - _sql = sql; - _autoGeneratedKeys = autoGeneratedKeys; + this.sql = sql; + this.autoGeneratedKeys = autoGeneratedKeys; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -79,9 +79,9 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared public TesterPreparedStatement(final Connection conn, final String sql, final int resultSetType, final int resultSetConcurrency) { super(conn, resultSetType, resultSetConcurrency); - _sql = sql; + this.sql = sql; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -90,9 +90,9 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared public TesterPreparedStatement(final Connection conn, final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { super(conn, resultSetType, resultSetConcurrency, resultSetHoldability); - _sql = sql; + this.sql = sql; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -100,10 +100,10 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared public TesterPreparedStatement(final Connection conn, final String sql, final int[] columnIndexes) { super(conn); - _sql = sql; - _columnIndexes = columnIndexes; + this.sql = sql; + this.columnIndexes = columnIndexes; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -111,10 +111,10 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared public TesterPreparedStatement(final Connection conn, final String sql, final String[] columnNames) { super(conn); - _sql = sql; - _columnNames = columnNames; + this.sql = sql; + this.columnNames = columnNames; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -156,13 +156,13 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared @Override public long executeLargeUpdate() throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override public long executeLargeUpdate(final String sql) throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override @@ -186,14 +186,14 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared @Override public ResultSet executeQuery() throws SQLException { checkOpen(); - if ("null".equals(_sql)) { + if ("null".equals(sql)) { return null; } - if (_queryTimeout > 0 && _queryTimeout < 5) { + if (queryTimeout > 0 && queryTimeout < 5) { // Simulate timeout if queryTimout is set to less than 5 seconds throw new SQLException("query timeout"); } - return new TesterResultSet(this, _resultSetType, _resultSetConcurrency); + return new TesterResultSet(this, resultSetType, resultSetConcurrency); } @Override @@ -202,19 +202,19 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared if ("null".equals(sql)) { return null; } - return new TesterResultSet(this, _resultSetType, _resultSetConcurrency); + return new TesterResultSet(this, resultSetType, resultSetConcurrency); } @Override public int executeUpdate() throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override public int executeUpdate(final String sql) throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override @@ -236,30 +236,30 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared } public int getAutoGeneratedKeys() { - return _autoGeneratedKeys; + return autoGeneratedKeys; } public String getCatalog() { - return _catalog; + return catalog; } public int[] getColumnIndexes() { - return _columnIndexes; + return columnIndexes; } public String[] getColumnNames() { - return _columnNames; + return columnNames; } @Override public ResultSet getGeneratedKeys() throws SQLException { - return new TesterResultSet(this, _resultSetType, _resultSetConcurrency); + return new TesterResultSet(this, resultSetType, resultSetConcurrency); } @Override public ResultSetMetaData getMetaData() throws SQLException { checkOpen(); - return _resultSetMetaData; + return resultSetMetaData; } @Override @@ -274,7 +274,7 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared /** For junit test only */ public String getSql() { - return _sql; + return sql; } @Override @@ -531,6 +531,6 @@ public class TesterPreparedStatement extends TesterStatement implements Prepared @Override public String toString() { - return _sql; + return sql; } } diff --git a/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java b/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java index dad25d59..0150e263 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java @@ -111,7 +111,7 @@ public class TesterResultSet extends AbandonedTrace implements ResultSet { // Not all result sets are generated from statements eg DatabaseMetaData if (_statement != null) { - ((TesterStatement) _statement)._resultSet = null; + ((TesterStatement) _statement).resultSet = null; } _open = false; diff --git a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java index 3357543c..0b6479c8 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java @@ -28,39 +28,39 @@ import java.sql.Statement; */ public class TesterStatement extends AbandonedTrace implements Statement { - protected final Connection _connection; - protected boolean _open = true; - protected final long _rowsUpdated = 1; - protected final boolean _executeResponse = true; - protected int _maxFieldSize = 1024; - protected long _maxRows = 1024; - protected boolean _escapeProcessing; - protected int _queryTimeout = 1000; - protected String _cursorName; - protected int _fetchDirection = 1; - protected int _fetchSize = 1; - protected int _resultSetConcurrency = 1; - protected int _resultSetType = 1; - private int _resultSetHoldability = 1; - protected ResultSet _resultSet; - protected boolean _sqlExceptionOnClose; - - public TesterStatement(final Connection conn) { - _connection = conn; - } - - public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency) { - _connection = conn; - _resultSetType = resultSetType; - _resultSetConcurrency = resultSetConcurrency; - } - - public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency, + protected final Connection connection; + protected boolean open = true; + protected final long rowsUpdated = 1; + protected final boolean executeResponse = true; + protected int maxFieldSize = 1024; + protected long maxRows = 1024; + protected boolean escapeProcessing; + protected int queryTimeout = 1000; + protected String cursorName; + protected int fetchDirection = 1; + protected int fetchSize = 1; + protected int resultSetConcurrency = 1; + protected int resultSetType = 1; + private int resultSetHoldability = 1; + protected ResultSet resultSet; + protected boolean sqlExceptionOnClose; + + public TesterStatement(final Connection connection) { + this.connection = connection; + } + + public TesterStatement(final Connection connection, final int resultSetType, final int resultSetConcurrency) { + this.connection = connection; + this.resultSetType = resultSetType; + this.resultSetConcurrency = resultSetConcurrency; + } + + public TesterStatement(final Connection connection, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { - _connection = conn; - _resultSetType = resultSetType; - _resultSetConcurrency = resultSetConcurrency; - _resultSetHoldability = resultSetHoldability; + this.connection = connection; + this.resultSetType = resultSetType; + this.resultSetConcurrency = resultSetConcurrency; + this.resultSetHoldability = resultSetHoldability; } @Override @@ -74,7 +74,7 @@ public class TesterStatement extends AbandonedTrace implements Statement { } protected void checkOpen() throws SQLException { - if (!_open) { + if (!open) { throw new SQLException("Connection is closed."); } } @@ -91,19 +91,19 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public void close() throws SQLException { - if (_sqlExceptionOnClose) { + if (sqlExceptionOnClose) { throw new SQLException("TestSQLExceptionOnClose"); } // calling close twice has no effect - if (!_open) { + if (!open) { return; } - _open = false; - if (_resultSet != null) { - _resultSet.close(); - _resultSet = null; + open = false; + if (resultSet != null) { + resultSet.close(); + resultSet = null; } } @@ -118,7 +118,7 @@ public class TesterStatement extends AbandonedTrace implements Statement { if ("invalid".equals(sql)) { throw new SQLException("invalid query"); } - return _executeResponse; + return executeResponse; } @Override @@ -154,7 +154,7 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public long executeLargeUpdate(final String sql) throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override @@ -185,12 +185,12 @@ public class TesterStatement extends AbandonedTrace implements Statement { throw new SQLException("broken connection"); } if ("select username".equals(sql)) { - final String userName = ((TesterConnection) _connection).getUserName(); + final String userName = ((TesterConnection) connection).getUserName(); final Object[][] data = { { userName } }; return new TesterResultSet(this, data); } // Simulate timeout if queryTimout is set to less than 5 seconds - if (_queryTimeout > 0 && _queryTimeout < 5) { + if (queryTimeout > 0 && queryTimeout < 5) { throw new SQLException("query timeout"); } return new TesterResultSet(this); @@ -199,7 +199,7 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public int executeUpdate(final String sql) throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override @@ -220,19 +220,19 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public Connection getConnection() throws SQLException { checkOpen(); - return _connection; + return connection; } @Override public int getFetchDirection() throws SQLException { checkOpen(); - return _fetchDirection; + return fetchDirection; } @Override public int getFetchSize() throws SQLException { checkOpen(); - return _fetchSize; + return fetchSize; } @Override @@ -243,25 +243,25 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public long getLargeMaxRows() throws SQLException { checkOpen(); - return _maxRows; + return maxRows; } @Override public long getLargeUpdateCount() throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override public int getMaxFieldSize() throws SQLException { checkOpen(); - return _maxFieldSize; + return maxFieldSize; } @Override public int getMaxRows() throws SQLException { checkOpen(); - return (int) _maxRows; + return (int) maxRows; } @Override @@ -278,40 +278,40 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public int getQueryTimeout() throws SQLException { checkOpen(); - return _queryTimeout; + return queryTimeout; } @Override public ResultSet getResultSet() throws SQLException { checkOpen(); - if (_resultSet == null) { - _resultSet = new TesterResultSet(this); + if (resultSet == null) { + resultSet = new TesterResultSet(this); } - return _resultSet; + return resultSet; } @Override public int getResultSetConcurrency() throws SQLException { checkOpen(); - return _resultSetConcurrency; + return resultSetConcurrency; } @Override public int getResultSetHoldability() throws SQLException { checkOpen(); - return _resultSetHoldability; + return resultSetHoldability; } @Override public int getResultSetType() throws SQLException { checkOpen(); - return _resultSetType; + return resultSetType; } @Override public int getUpdateCount() throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override @@ -322,7 +322,7 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public boolean isClosed() throws SQLException { - return !_open; + return !open; } @Override @@ -336,7 +336,7 @@ public class TesterStatement extends AbandonedTrace implements Statement { } public boolean isSqlExceptionOnClose() { - return _sqlExceptionOnClose; + return sqlExceptionOnClose; } @Override @@ -347,43 +347,43 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public void setCursorName(final String name) throws SQLException { checkOpen(); - _cursorName = name; + this.cursorName = name; } @Override public void setEscapeProcessing(final boolean enable) throws SQLException { checkOpen(); - _escapeProcessing = enable; + this.escapeProcessing = enable; } @Override public void setFetchDirection(final int direction) throws SQLException { checkOpen(); - _fetchDirection = direction; + this.fetchDirection = direction; } @Override public void setFetchSize(final int rows) throws SQLException { checkOpen(); - _fetchSize = rows; + this.fetchSize = rows; } @Override public void setLargeMaxRows(final long max) throws SQLException { checkOpen(); - _maxRows = max; + this.maxRows = max; } @Override public void setMaxFieldSize(final int max) throws SQLException { checkOpen(); - _maxFieldSize = max; + this.maxFieldSize = max; } @Override public void setMaxRows(final int max) throws SQLException { checkOpen(); - _maxRows = max; + this.maxRows = max; } @Override @@ -394,11 +394,11 @@ public class TesterStatement extends AbandonedTrace implements Statement { @Override public void setQueryTimeout(final int seconds) throws SQLException { checkOpen(); - _queryTimeout = seconds; + this.queryTimeout = seconds; } public void setSqlExceptionOnClose(final boolean _sqlExceptionOnClose) { - this._sqlExceptionOnClose = _sqlExceptionOnClose; + this.sqlExceptionOnClose = _sqlExceptionOnClose; } @Override