You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/09/09 13:14:48 UTC
[commons-dbcp] 01/02: Sort members
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 a7755dbd9c59d16630e7d302e1a330c440fe516f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Sep 9 09:09:28 2023 -0400
Sort members
---
.../org/apache/commons/dbcp2/BasicDataSource.java | 92 ++++++++--------
.../commons/dbcp2/DelegatingPreparedStatement.java | 42 +++----
.../apache/commons/dbcp2/PoolableConnection.java | 64 +++++------
.../apache/commons/dbcp2/TestBasicDataSource.java | 42 +++----
.../commons/dbcp2/TestBasicDataSourceMXBean.java | 14 +--
.../apache/commons/dbcp2/TestConnectionPool.java | 4 +-
.../commons/dbcp2/TestPoolableConnection.java | 48 ++++----
.../datasources/TestCPDSConnectionFactory.java | 16 +--
.../datasources/TestPerUserPoolDataSource.java | 122 ++++++++++-----------
.../datasources/TestSharedPoolDataSource.java | 42 +++----
10 files changed, 243 insertions(+), 243 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 1a990b7e..e308e86e 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -912,6 +912,17 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
return this.driverClassName;
}
+ /**
+ * Gets the value of the {code durationBetweenEvictionRuns} property.
+ *
+ * @return the time (in milliseconds) between evictor runs
+ * @see #setDurationBetweenEvictionRuns(Duration)
+ * @since 2.10.0
+ */
+ public synchronized Duration getDurationBetweenEvictionRuns() {
+ return this.durationBetweenEvictionRuns;
+ }
+
/**
* Gets the value of the flag that controls whether or not connections being returned to the pool will be checked
* and configured with {@link Connection#setAutoCommit(boolean) Connection.setAutoCommit(true)} if the auto commit
@@ -1402,17 +1413,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
return this.testWhileIdle;
}
- /**
- * Gets the value of the {code durationBetweenEvictionRuns} property.
- *
- * @return the time (in milliseconds) between evictor runs
- * @see #setDurationBetweenEvictionRuns(Duration)
- * @since 2.10.0
- */
- public synchronized Duration getDurationBetweenEvictionRuns() {
- return this.durationBetweenEvictionRuns;
- }
-
/**
* Gets the value of the {code durationBetweenEvictionRuns} property.
*
@@ -1461,21 +1461,21 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
* Gets the validation query timeout.
*
* @return the timeout in seconds before connection validation queries fail.
+ * @deprecated Use {@link #getValidationQueryTimeoutDuration()}.
*/
- public Duration getValidationQueryTimeoutDuration() {
- return validationQueryTimeoutDuration;
+ @Deprecated
+ @Override
+ public int getValidationQueryTimeout() {
+ return (int) validationQueryTimeoutDuration.getSeconds();
}
/**
* Gets the validation query timeout.
*
* @return the timeout in seconds before connection validation queries fail.
- * @deprecated Use {@link #getValidationQueryTimeoutDuration()}.
*/
- @Deprecated
- @Override
- public int getValidationQueryTimeout() {
- return (int) validationQueryTimeoutDuration.getSeconds();
+ public Duration getValidationQueryTimeoutDuration() {
+ return validationQueryTimeoutDuration;
}
/**
@@ -1696,12 +1696,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
}
}
- private <T> void setConnectionPool(final BiConsumer<GenericObjectPool<PoolableConnection>, T> consumer, final T object) {
- if (connectionPool != null) {
- consumer.accept(connectionPool, object);
- }
- }
-
/**
* Sets the print writer to be used by this configuration to log information on abandoned objects.
*
@@ -1811,6 +1805,12 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
this.connectionInitSqls = Utils.isEmpty(collect) ? null : collect;
}
+ private <T> void setConnectionPool(final BiConsumer<GenericObjectPool<PoolableConnection>, T> consumer, final T object) {
+ if (connectionPool != null) {
+ consumer.accept(connectionPool, object);
+ }
+ }
+
/**
* Sets the connection properties passed to driver.connect(...).
* <p>
@@ -2019,6 +2019,18 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
this.driverClassName = isEmpty(driverClassName) ? null : driverClassName;
}
+ /**
+ * Sets the {code durationBetweenEvictionRuns} property.
+ *
+ * @param timeBetweenEvictionRunsMillis the new time between evictor runs
+ * @see #setDurationBetweenEvictionRuns(Duration)
+ * @since 2.10.0
+ */
+ public synchronized void setDurationBetweenEvictionRuns(final Duration timeBetweenEvictionRunsMillis) {
+ this.durationBetweenEvictionRuns = timeBetweenEvictionRunsMillis;
+ setConnectionPool(GenericObjectPool::setTimeBetweenEvictionRuns, timeBetweenEvictionRunsMillis);
+ }
+
/**
* Sets the value of the flag that controls whether or not connections being returned to the pool will be checked
* and configured with {@link Connection#setAutoCommit(boolean) Connection.setAutoCommit(true)} if the auto commit
@@ -2078,16 +2090,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
this.jmxName = jmxName;
}
- /**
- * Sets if connection level JMX tracking is requested for this DataSource. If true, each connection will be
- * registered for tracking with JMX.
- *
- * @param registerConnectionMBean connection tracking requested for this DataSource.
- */
- public void setRegisterConnectionMBean(final boolean registerConnectionMBean) {
- this.registerConnectionMBean = registerConnectionMBean;
- }
-
/**
* Sets the LIFO property. True means the pool behaves as a LIFO queue; false means FIFO.
*
@@ -2325,6 +2327,16 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
this.poolPreparedStatements = poolingStatements;
}
+ /**
+ * Sets if connection level JMX tracking is requested for this DataSource. If true, each connection will be
+ * registered for tracking with JMX.
+ *
+ * @param registerConnectionMBean connection tracking requested for this DataSource.
+ */
+ public void setRegisterConnectionMBean(final boolean registerConnectionMBean) {
+ this.registerConnectionMBean = registerConnectionMBean;
+ }
+
/**
* @param removeAbandonedOnBorrow true means abandoned connections may be removed when connections are borrowed from
* the pool.
@@ -2461,18 +2473,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
setConnectionPool(GenericObjectPool::setTestWhileIdle, testWhileIdle);
}
- /**
- * Sets the {code durationBetweenEvictionRuns} property.
- *
- * @param timeBetweenEvictionRunsMillis the new time between evictor runs
- * @see #setDurationBetweenEvictionRuns(Duration)
- * @since 2.10.0
- */
- public synchronized void setDurationBetweenEvictionRuns(final Duration timeBetweenEvictionRunsMillis) {
- this.durationBetweenEvictionRuns = timeBetweenEvictionRunsMillis;
- setConnectionPool(GenericObjectPool::setTimeBetweenEvictionRuns, timeBetweenEvictionRunsMillis);
- }
-
/**
* Sets the {code durationBetweenEvictionRuns} property.
*
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
index e1b06ca8..a13f774a 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
@@ -167,6 +167,27 @@ public class DelegatingPreparedStatement extends DelegatingStatement implements
}
}
+ protected void prepareToReturn() throws SQLException {
+ setClosedInternal(true);
+ removeThisTrace(getConnectionInternal());
+
+ // The JDBC spec requires that a statement close any open
+ // ResultSet's when it is closed.
+ // FIXME The PreparedStatement we're wrapping should handle this for us.
+ // See DBCP-10 for what could happen when ResultSets are closed twice.
+ final List<AbandonedTrace> traceList = getTrace();
+ if (traceList != null) {
+ final List<Exception> thrownList = new ArrayList<>();
+ traceList.forEach(trace -> trace.close(thrownList::add));
+ clearTrace();
+ if (!thrownList.isEmpty()) {
+ throw new SQLExceptionList(thrownList);
+ }
+ }
+
+ super.passivate();
+ }
+
@Override
public void setArray(final int i, final Array x) throws SQLException {
checkOpen();
@@ -693,25 +714,4 @@ public class DelegatingPreparedStatement extends DelegatingStatement implements
final Statement statement = getDelegate();
return statement == null ? "NULL" : statement.toString();
}
-
- protected void prepareToReturn() throws SQLException {
- setClosedInternal(true);
- removeThisTrace(getConnectionInternal());
-
- // The JDBC spec requires that a statement close any open
- // ResultSet's when it is closed.
- // FIXME The PreparedStatement we're wrapping should handle this for us.
- // See DBCP-10 for what could happen when ResultSets are closed twice.
- final List<AbandonedTrace> traceList = getTrace();
- if (traceList != null) {
- final List<Exception> thrownList = new ArrayList<>();
- traceList.forEach(trace -> trace.close(thrownList::add));
- clearTrace();
- if (!thrownList.isEmpty()) {
- throw new SQLExceptionList(thrownList);
- }
- }
-
- super.passivate();
- }
}
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
index 83148e2a..440cb756 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
@@ -264,6 +264,14 @@ public class PoolableConnection extends DelegatingConnection<Connection> impleme
return fatalException;
}
+ /**
+ * @return Whether to fail-fast.
+ * @since 2.6.0
+ */
+ public boolean isFastFailValidation() {
+ return fastFailValidation;
+ }
+
/**
* Checks the SQLState of the input exception and any nested SQLExceptions it wraps.
* <p>
@@ -291,14 +299,6 @@ public class PoolableConnection extends DelegatingConnection<Connection> impleme
return fatalException;
}
- /**
- * @return Whether to fail-fast.
- * @since 2.6.0
- */
- public boolean isFastFailValidation() {
- return fastFailValidation;
- }
-
@Override
protected void passivate() throws SQLException {
super.passivate();
@@ -324,30 +324,6 @@ public class PoolableConnection extends DelegatingConnection<Connection> impleme
super.closeInternal();
}
- /**
- * Validates the connection, using the following algorithm:
- * <ol>
- * <li>If {@code fastFailValidation} (constructor argument) is {@code true} and this connection has previously
- * thrown a fatal disconnection exception, a {@code SQLException} is thrown.</li>
- * <li>If {@code sql} is null, the driver's #{@link Connection#isValid(int) isValid(timeout)} is called. If it
- * returns {@code false}, {@code SQLException} is thrown; otherwise, this method returns successfully.</li>
- * <li>If {@code sql} is not null, it is executed as a query and if the resulting {@code ResultSet} contains at
- * least one row, this method returns successfully. If not, {@code SQLException} is thrown.</li>
- * </ol>
- *
- * @param sql
- * The validation SQL query.
- * @param timeoutSeconds
- * The validation timeout in seconds.
- * @throws SQLException
- * Thrown when validation fails or an SQLException occurs during validation
- * @deprecated Use {@link #validate(String, Duration)}.
- */
- @Deprecated
- public void validate(final String sql, final int timeoutSeconds) throws SQLException {
- validate(sql, Duration.ofSeconds(timeoutSeconds));
- }
-
/**
* Validates the connection, using the following algorithm:
* <ol>
@@ -401,4 +377,28 @@ public class PoolableConnection extends DelegatingConnection<Connection> impleme
throw sqle;
}
}
+
+ /**
+ * Validates the connection, using the following algorithm:
+ * <ol>
+ * <li>If {@code fastFailValidation} (constructor argument) is {@code true} and this connection has previously
+ * thrown a fatal disconnection exception, a {@code SQLException} is thrown.</li>
+ * <li>If {@code sql} is null, the driver's #{@link Connection#isValid(int) isValid(timeout)} is called. If it
+ * returns {@code false}, {@code SQLException} is thrown; otherwise, this method returns successfully.</li>
+ * <li>If {@code sql} is not null, it is executed as a query and if the resulting {@code ResultSet} contains at
+ * least one row, this method returns successfully. If not, {@code SQLException} is thrown.</li>
+ * </ol>
+ *
+ * @param sql
+ * The validation SQL query.
+ * @param timeoutSeconds
+ * The validation timeout in seconds.
+ * @throws SQLException
+ * Thrown when validation fails or an SQLException occurs during validation
+ * @deprecated Use {@link #validate(String, Duration)}.
+ */
+ @Deprecated
+ public void validate(final String sql, final int timeoutSeconds) throws SQLException {
+ validate(sql, Duration.ofSeconds(timeoutSeconds));
+ }
}
diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
index bfa6f71b..2ee8357e 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
@@ -229,6 +229,27 @@ public class TestBasicDataSource extends TestConnectionPool {
ds.close();
}
+ /**
+ * Test disabling MBean registration for Connection objects.
+ * JIRA: DBCP-585
+ */
+ @Test
+ public void testConnectionMBeansDisabled() throws Exception {
+ final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ // Unregister leftovers from other tests (TODO: worry about concurrent test execution)
+ final ObjectName commons = new ObjectName("org.apache.commons.*:*");
+ final Set<ObjectName> results = mbs.queryNames(commons, null);
+ for (final ObjectName result : results) {
+ mbs.unregisterMBean(result);
+ }
+ ds.setRegisterConnectionMBean(false); // Should disable Connection MBean registration
+ try (Connection conn = ds.getConnection()) { // Trigger initialization
+ // No Connection MBeans shall be registered
+ final ObjectName connections = new ObjectName("org.apache.commons.*:connection=*,*");
+ assertEquals(0, mbs.queryNames(connections, null).size());
+ }
+ }
+
/**
* JIRA: DBCP-547
* Verify that ConnectionFactory interface in BasicDataSource.createConnectionFactory().
@@ -622,27 +643,6 @@ public class TestBasicDataSource extends TestConnectionPool {
}
}
- /**
- * Test disabling MBean registration for Connection objects.
- * JIRA: DBCP-585
- */
- @Test
- public void testConnectionMBeansDisabled() throws Exception {
- final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- // Unregister leftovers from other tests (TODO: worry about concurrent test execution)
- final ObjectName commons = new ObjectName("org.apache.commons.*:*");
- final Set<ObjectName> results = mbs.queryNames(commons, null);
- for (final ObjectName result : results) {
- mbs.unregisterMBean(result);
- }
- ds.setRegisterConnectionMBean(false); // Should disable Connection MBean registration
- try (Connection conn = ds.getConnection()) { // Trigger initialization
- // No Connection MBeans shall be registered
- final ObjectName connections = new ObjectName("org.apache.commons.*:connection=*,*");
- assertEquals(0, mbs.queryNames(connections, null).size());
- }
- }
-
/**
* Tests JIRA <a href="https://issues.apache.org/jira/browse/DBCP-562">DBCP-562</a>.
* <p>
diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java
index 833328f5..db0398b9 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java
@@ -34,6 +34,13 @@ import org.junit.jupiter.api.Test;
*/
public class TestBasicDataSourceMXBean {
+ public static void testMXBeanCompliance(Class<?> clazz) throws OperationsException {
+ assertTrue(JMX.isMXBeanInterface(clazz));
+ final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ final ObjectName objectName = ObjectName.getInstance("com.sun.management:type=DiagnosticCommand");
+ JMX.newMBeanProxy(server, objectName, clazz, true);
+ }
+
private final BasicDataSourceMXBean bean = new BasicDataSourceMXBean() {
@Override
@@ -257,11 +264,4 @@ public class TestBasicDataSourceMXBean {
public void testMXBeanCompliance() throws OperationsException {
testMXBeanCompliance(BasicDataSourceMXBean.class);
}
-
- public static void testMXBeanCompliance(Class<?> clazz) throws OperationsException {
- assertTrue(JMX.isMXBeanInterface(clazz));
- final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
- final ObjectName objectName = ObjectName.getInstance("com.sun.management:type=DiagnosticCommand");
- JMX.newMBeanProxy(server, objectName, clazz, true);
- }
}
diff --git a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java
index ec680c24..3d65d2a9 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java
@@ -53,8 +53,6 @@ import org.junit.jupiter.api.Test;
*/
public abstract class TestConnectionPool {
- private static final Duration MAX_WAIT_DURATION = Duration.ofMillis(100);
-
protected class PoolTest implements Runnable {
/**
* The number of milliseconds to hold onto a database connection
@@ -219,6 +217,8 @@ public abstract class TestConnectionPool {
}
}
+ private static final Duration MAX_WAIT_DURATION = Duration.ofMillis(100);
+
private static final boolean DISPLAY_THREAD_DETAILS=
Boolean.parseBoolean(System.getProperty("TestConnectionPool.display.thread.details", "false"));
// To pass this to a Maven test, use:
diff --git a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java
index 2d2518d7..757e4a56 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java
@@ -164,6 +164,30 @@ public class TestPoolableConnection {
assertEquals(0, pool.getNumIdle(), "The pool should have no idle connections");
}
+ @Test
+ public void testIsDisconnectionSqlExceptionStackOverflow() throws Exception {
+ final int maxDeep = 100_000;
+ final SQLException rootException = new SQLException("Data truncated", "22001");
+ SQLException parentException = rootException;
+ for (int i = 0; i <= maxDeep; i++) {
+ final SQLException childException = new SQLException("Data truncated: " + i, "22001");
+ parentException.setNextException(childException);
+ parentException = childException;
+ }
+ final Connection conn = pool.borrowObject();
+ assertEquals(false, ((PoolableConnection) conn).isDisconnectionSqlException(rootException));
+ assertEquals(false, ((PoolableConnection) conn).isFatalException(rootException));
+ }
+
+ /**
+ * Tests if the {@link PoolableConnectionMXBean} interface is a valid MXBean
+ * interface.
+ */
+ @Test
+ public void testMXBeanCompliance() throws OperationsException {
+ TestBasicDataSourceMXBean.testMXBeanCompliance(PoolableConnectionMXBean.class);
+ }
+
// Bugzilla Bug 33591: PoolableConnection leaks connections if the
// delegated connection closes itself.
@Test
@@ -189,28 +213,4 @@ public class TestPoolableConnection {
assertEquals(0, pool.getNumActive(), "The pool should have no active connections");
}
-
- @Test
- public void testIsDisconnectionSqlExceptionStackOverflow() throws Exception {
- final int maxDeep = 100_000;
- final SQLException rootException = new SQLException("Data truncated", "22001");
- SQLException parentException = rootException;
- for (int i = 0; i <= maxDeep; i++) {
- final SQLException childException = new SQLException("Data truncated: " + i, "22001");
- parentException.setNextException(childException);
- parentException = childException;
- }
- final Connection conn = pool.borrowObject();
- assertEquals(false, ((PoolableConnection) conn).isDisconnectionSqlException(rootException));
- assertEquals(false, ((PoolableConnection) conn).isFatalException(rootException));
- }
-
- /**
- * Tests if the {@link PoolableConnectionMXBean} interface is a valid MXBean
- * interface.
- */
- @Test
- public void testMXBeanCompliance() throws OperationsException {
- TestBasicDataSourceMXBean.testMXBeanCompliance(PoolableConnectionMXBean.class);
- }
}
diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
index 41a7476c..de052b47 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
@@ -118,8 +118,8 @@ public class TestCPDSConnectionFactory {
* JIRA: DBCP-442
*/
@Test
- public void testNullValidationQuery_Deprecated() throws Exception {
- final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, -1, false, "userName", "password");
+ public void testNullValidationQuery() throws Exception {
+ final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, Duration.ofMillis(-1), false, "userName", "password");
try (final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory)) {
factory.setPool(pool);
pool.setTestOnBorrow(true);
@@ -133,8 +133,8 @@ public class TestCPDSConnectionFactory {
* JIRA: DBCP-442
*/
@Test
- public void testNullValidationQuery() throws Exception {
- final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, Duration.ofMillis(-1), false, "userName", "password");
+ public void testNullValidationQuery_Deprecated() throws Exception {
+ final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, -1, false, "userName", "password");
try (final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory)) {
factory.setPool(pool);
pool.setTestOnBorrow(true);
@@ -145,8 +145,8 @@ public class TestCPDSConnectionFactory {
}
@Test
- public void testSetPasswordThenModCharArray_Deprecated() {
- final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, -1, false, "userName", "password");
+ public void testSetPasswordThenModCharArray() {
+ final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, Duration.ofMillis(-1), false, "userName", "password");
final char[] pwd = {'a'};
factory.setPassword(pwd);
assertEquals("a", String.valueOf(factory.getPasswordCharArray()));
@@ -155,8 +155,8 @@ public class TestCPDSConnectionFactory {
}
@Test
- public void testSetPasswordThenModCharArray() {
- final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, Duration.ofMillis(-1), false, "userName", "password");
+ public void testSetPasswordThenModCharArray_Deprecated() {
+ final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, -1, false, "userName", "password");
final char[] pwd = {'a'};
factory.setPassword(pwd);
assertEquals("a", String.valueOf(factory.getPasswordCharArray()));
diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
index 8e67cd15..529c6beb 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
@@ -650,6 +650,45 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertNull(ds.getPerUserDefaultTransactionIsolation("missingkey"));
}
+ @Test
+ public void testPerUserDurationBetweenEvictionRunsMapInitialized() {
+ final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
+ Map<String, Duration> values = new HashMap<>();
+ values.put("key", Duration.ZERO);
+ ds.setPerUserDurationBetweenEvictionRuns(values);
+ assertEquals(0L, ds.getPerUserTimeBetweenEvictionRunsMillis("key"));
+ assertEquals(Duration.ZERO, ds.getPerUserDurationBetweenEvictionRuns("key"));
+ values = new HashMap<>();
+ values.put("anonymous", Duration.ZERO);
+ ds.setPerUserDurationBetweenEvictionRuns(values);
+ assertEquals(ds.getDefaultTimeBetweenEvictionRunsMillis(), ds.getPerUserTimeBetweenEvictionRunsMillis("key"));
+ assertEquals(ds.getDefaultDurationBetweenEvictionRuns(), ds.getPerUserDurationBetweenEvictionRuns("key"));
+ assertEquals(0L, ds.getPerUserTimeBetweenEvictionRunsMillis("anonymous"));
+ assertEquals(Duration.ZERO, ds.getPerUserDurationBetweenEvictionRuns("anonymous"));
+ }
+
+ // -- per user default transaction isolation
+
+ @Test
+ public void testPerUserDurationBetweenEvictionRunsMapNotInitialized() {
+ final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
+ final Map<String, Duration> values = new HashMap<>();
+ values.put("key", DURATION_1_MILLISECOND);
+ ds.setPerUserDurationBetweenEvictionRuns(values);
+ assertEquals(1L, ds.getPerUserTimeBetweenEvictionRunsMillis("key"));
+ assertEquals(DURATION_1_MILLISECOND, ds.getPerUserDurationBetweenEvictionRuns("key"));
+ }
+
+ @Test
+ public void testPerUserDurationBetweenEvictionRunsMapNotInitializedMissingKey() {
+ final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
+ final Map<String, Duration> values = new HashMap<>();
+ values.put("key", Duration.ZERO);
+ ds.setPerUserDurationBetweenEvictionRuns(values);
+ assertEquals(ds.getDefaultTimeBetweenEvictionRunsMillis(), ds.getPerUserTimeBetweenEvictionRunsMillis("missingkey"));
+ assertEquals(ds.getDefaultDurationBetweenEvictionRuns(), ds.getPerUserDurationBetweenEvictionRuns("missingkey"));
+ }
+
@Test
public void testPerUserEvictionPolicyClassNameMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -664,8 +703,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals("bar", ds.getPerUserEvictionPolicyClassName("anonymous"));
}
- // -- per user default transaction isolation
-
@Test
public void testPerUserEvictionPolicyClassNameMapNotInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -694,6 +731,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals("bar", ds.getPerUserEvictionPolicyClassName("anotheruser"));
}
+ // -- per user eviction policy class name
+
@Test
public void testPerUserEvictionPolicyClassNameWithUserMapNotInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -722,8 +761,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(Boolean.FALSE, ds.getPerUserLifo("anonymous"));
}
- // -- per user eviction policy class name
-
@Test
public void testPerUserLifoMapNotInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -752,6 +789,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(Boolean.FALSE, ds.getPerUserLifo("anotheruser"));
}
+ // -- per user lifo
+
@Test
public void testPerUserLifoWithUserMapNotInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -780,8 +819,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals((Integer) 0, (Integer) ds.getPerUserMaxIdle("anonymous"));
}
- // -- per user lifo
-
@Test
public void testPerUserMaxIdleMapNotInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -810,6 +847,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals((Integer) 0, (Integer) ds.getPerUserMaxIdle("anotheruser"));
}
+ // -- per user max idle
+
@Test
public void testPerUserMaxIdleWithUserMapNotInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -838,8 +877,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals((Integer) 0, (Integer) ds.getPerUserMaxTotal("anonymous"));
}
- // -- per user max idle
-
@Test
public void testPerUserMaxTotalMapNotInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -925,6 +962,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(0L, ds.getPerUserMaxWaitMillis("anotheruser"));
}
+ // -- per user max wait millis
+
@Test
@SuppressWarnings("deprecation")
public void testPerUserMaxWaitMillisWithUserMapNotInitialized_Deprecated() {
@@ -990,8 +1029,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(0, tds.getNumIdle("u2"));
}
- // -- per user max wait millis
-
@Test
public void testPerUserMinEvictableIdleDurationMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1029,6 +1066,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultMinEvictableIdleDuration(), ds.getPerUserMinEvictableIdleDuration("missingkey"));
}
+ // -- per user min evictable idle time millis
+
@Test
public void testPerUserMinEvictableIdleTimeMillisWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1053,8 +1092,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultMinEvictableIdleTimeMillis(), ds.getPerUserMinEvictableIdleTimeMillis("missingkey"));
}
- // -- per user min evictable idle time millis
-
@Test
public void testPerUserMinIdleMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1087,6 +1124,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals((Integer) ds.getDefaultMinIdle(), (Integer) ds.getPerUserMinIdle("missingkey"));
}
+ // -- per user min idle
+
@Test
public void testPerUserMinIdleWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1111,8 +1150,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals((Integer) ds.getDefaultMinIdle(), (Integer) ds.getPerUserMinIdle("missingkey"));
}
- // -- per user min idle
-
@Test
public void testPerUserNumTestsPerEvictionRunMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1145,6 +1182,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals((Integer) ds.getDefaultNumTestsPerEvictionRun(), (Integer) ds.getPerUserNumTestsPerEvictionRun("missingkey"));
}
+ // -- per user num tests per eviction run
+
@Test
public void testPerUserNumTestsPerEvictionRunWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1169,8 +1208,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals((Integer) ds.getDefaultNumTestsPerEvictionRun(), (Integer) ds.getPerUserNumTestsPerEvictionRun("missingkey"));
}
- // -- per user num tests per eviction run
-
@Test
public void testPerUserSoftMinEvictableIdleDurationMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1208,6 +1245,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultSoftMinEvictableIdleDuration(), ds.getPerUserSoftMinEvictableIdleDuration("missingkey"));
}
+ // -- per user soft min evictable idle time millis
+
@Test
public void testPerUserSoftMinEvictableIdleTimeMillisWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1232,8 +1271,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultSoftMinEvictableIdleTimeMillis(), ds.getPerUserSoftMinEvictableIdleTimeMillis("missingkey"));
}
- // -- per user soft min evictable idle time millis
-
@Test
public void testPerUserTestOnBorrowMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1266,6 +1303,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultTestOnBorrow(), ds.getPerUserTestOnBorrow("missingkey"));
}
+ // -- per user test on borrow
+
@Test
public void testPerUserTestOnBorrowWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1290,8 +1329,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultTestOnBorrow(), ds.getPerUserTestOnBorrow("missingkey"));
}
- // -- per user test on borrow
-
@Test
public void testPerUserTestOnCreateMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1324,6 +1361,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultTestOnCreate(), ds.getPerUserTestOnCreate("missingkey"));
}
+ // -- per user test on create
+
@Test
public void testPerUserTestOnCreateWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1348,8 +1387,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultTestOnCreate(), ds.getPerUserTestOnCreate("missingkey"));
}
- // -- per user test on create
-
@Test
public void testPerUserTestOnReturnMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1382,6 +1419,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultTestOnReturn(), ds.getPerUserTestOnReturn("missingkey"));
}
+ // -- per user test on return
+
@Test
public void testPerUserTestOnReturnWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1406,8 +1445,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultTestOnReturn(), ds.getPerUserTestOnReturn("missingkey"));
}
- // -- per user test on return
-
@Test
public void testPerUserTestWhileIdleMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
@@ -1464,43 +1501,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(ds.getDefaultTestWhileIdle(), ds.getPerUserTestWhileIdle("missingkey"));
}
- @Test
- public void testPerUserDurationBetweenEvictionRunsMapInitialized() {
- final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
- Map<String, Duration> values = new HashMap<>();
- values.put("key", Duration.ZERO);
- ds.setPerUserDurationBetweenEvictionRuns(values);
- assertEquals(0L, ds.getPerUserTimeBetweenEvictionRunsMillis("key"));
- assertEquals(Duration.ZERO, ds.getPerUserDurationBetweenEvictionRuns("key"));
- values = new HashMap<>();
- values.put("anonymous", Duration.ZERO);
- ds.setPerUserDurationBetweenEvictionRuns(values);
- assertEquals(ds.getDefaultTimeBetweenEvictionRunsMillis(), ds.getPerUserTimeBetweenEvictionRunsMillis("key"));
- assertEquals(ds.getDefaultDurationBetweenEvictionRuns(), ds.getPerUserDurationBetweenEvictionRuns("key"));
- assertEquals(0L, ds.getPerUserTimeBetweenEvictionRunsMillis("anonymous"));
- assertEquals(Duration.ZERO, ds.getPerUserDurationBetweenEvictionRuns("anonymous"));
- }
-
- @Test
- public void testPerUserDurationBetweenEvictionRunsMapNotInitialized() {
- final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
- final Map<String, Duration> values = new HashMap<>();
- values.put("key", DURATION_1_MILLISECOND);
- ds.setPerUserDurationBetweenEvictionRuns(values);
- assertEquals(1L, ds.getPerUserTimeBetweenEvictionRunsMillis("key"));
- assertEquals(DURATION_1_MILLISECOND, ds.getPerUserDurationBetweenEvictionRuns("key"));
- }
-
- @Test
- public void testPerUserDurationBetweenEvictionRunsMapNotInitializedMissingKey() {
- final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
- final Map<String, Duration> values = new HashMap<>();
- values.put("key", Duration.ZERO);
- ds.setPerUserDurationBetweenEvictionRuns(values);
- assertEquals(ds.getDefaultTimeBetweenEvictionRunsMillis(), ds.getPerUserTimeBetweenEvictionRunsMillis("missingkey"));
- assertEquals(ds.getDefaultDurationBetweenEvictionRuns(), ds.getPerUserDurationBetweenEvictionRuns("missingkey"));
- }
-
@Test
public void testPerUserTimeBetweenEvictionRunsMillisWithUserMapInitialized() {
final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds;
diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java
index 7e41b43d..bd7c0ffa 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java
@@ -47,27 +47,6 @@ import org.junit.jupiter.api.Test;
*/
public class TestSharedPoolDataSource extends TestConnectionPool {
- private static class CscbString extends AbstractPrepareCallCallback {
- @Override
- CallableStatement getCallableStatement() throws SQLException {
- return conn.prepareCall("{call home()}");
- }
- }
-
- private static class CscbStringIntInt extends AbstractPrepareCallCallback {
- @Override
- CallableStatement getCallableStatement() throws SQLException {
- return conn.prepareCall("{call home()}", 0, 0);
- }
- }
-
- private static class CscbStringIntIntInt extends AbstractPrepareCallCallback {
- @Override
- CallableStatement getCallableStatement() throws SQLException {
- return conn.prepareCall("{call home()}", 0, 0, 0);
- }
- }
-
/**
* There are 3 different prepareCall statement methods so add a little complexity to reduce what would otherwise be lots
* of copy and paste.
@@ -96,6 +75,27 @@ public class TestSharedPoolDataSource extends TestConnectionPool {
}
}
+ private static class CscbString extends AbstractPrepareCallCallback {
+ @Override
+ CallableStatement getCallableStatement() throws SQLException {
+ return conn.prepareCall("{call home()}");
+ }
+ }
+
+ private static class CscbStringIntInt extends AbstractPrepareCallCallback {
+ @Override
+ CallableStatement getCallableStatement() throws SQLException {
+ return conn.prepareCall("{call home()}", 0, 0);
+ }
+ }
+
+ private static class CscbStringIntIntInt extends AbstractPrepareCallCallback {
+ @Override
+ CallableStatement getCallableStatement() throws SQLException {
+ return conn.prepareCall("{call home()}", 0, 0, 0);
+ }
+ }
+
private static class PscbString extends AbstractPrepareStatementCallback {
@Override
PreparedStatement prepareStatement() throws SQLException {