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 997e199274124649593ee1f6e479c459a2d348e5 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sun May 25 18:03:35 2025 -0400 Ad org.apache.commons.dbcp2.datasources.TestPerUserPoolDataSource.testDefaultReadOnly() --- .../datasources/TestPerUserPoolDataSource.java | 83 +++++++++++++--------- 1 file changed, 49 insertions(+), 34 deletions(-) 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 75f80002..ab319a04 100644 --- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java @@ -52,10 +52,10 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { private static final Duration DURATION_1_MILLISECOND = Duration.ofMillis(1); - private String user; - private DataSource ds; + private String user; + @Override protected Connection getConnection() throws SQLException { return ds.getConnection(user, "bar"); @@ -173,7 +173,7 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { */ @Test public void testDbcp597() throws SQLException { - PerUserPoolDataSource tds = (PerUserPoolDataSource) ds; + final PerUserPoolDataSource tds = (PerUserPoolDataSource) ds; tds.setDefaultTestOnBorrow(true); tds.setValidationQuery("SELECT 1"); // The tester statement throws a SQLTimeoutException when the timeout is > 0 and < 5. @@ -188,6 +188,21 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(NoSuchElementException.class, e.getCause().getClass()); } + @Test + public void testDefaultReadOnly() { + try (PerUserPoolDataSource ds = new PerUserPoolDataSource()) { + assertNull(ds.isDefaultReadOnly()); + ds.setDefaultReadOnly(true); + assertTrue(ds.isDefaultReadOnly().booleanValue()); + ds.setDefaultReadOnly(false); + assertFalse(ds.isDefaultReadOnly().booleanValue()); + ds.setDefaultReadOnly(true); + assertTrue(ds.isDefaultReadOnly().booleanValue()); + ds.setDefaultReadOnly(null); + assertNull(ds.isDefaultReadOnly()); + } + } + // see issue https://issues.apache.org/bugzilla/show_bug.cgi?id=23843 @Test public void testDefaultUser1() throws Exception { @@ -451,6 +466,11 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(Boolean.TRUE, ds.getPerUserBlockWhenExhausted("missingkey")); } + // getters and setters. Most follow the same pattern. The initial tests contain a more + // complete documentation, which can be helpful when write/understanding the other methods. + + // -- per user block when exhausted + @Test public void testPerUserDefaultAutoCommitMapInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -465,11 +485,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(Boolean.FALSE, ds.getPerUserDefaultAutoCommit("anonymous")); } - // getters and setters. Most follow the same pattern. The initial tests contain a more - // complete documentation, which can be helpful when write/understanding the other methods. - - // -- per user block when exhausted - @Test public void testPerUserDefaultAutoCommitMapNotInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -514,6 +529,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertNull(ds.getPerUserDefaultAutoCommit("missingkey")); } + // -- per user default auto commit + @Test public void testPerUserDefaultReadOnlyMapInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -528,8 +545,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(Boolean.FALSE, ds.getPerUserDefaultReadOnly("anonymous")); } - // -- per user default auto commit - @Test public void testPerUserDefaultReadOnlyMapNotInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -574,6 +589,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertNull(ds.getPerUserDefaultReadOnly("missingkey")); } + // -- per user default read only + @Test public void testPerUserDefaultTransactionIsolationMapInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -589,8 +606,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals((Integer) 0, ds.getPerUserDefaultTransactionIsolation("anonymous")); } - // -- per user default read only - @Test public void testPerUserDefaultTransactionIsolationMapNotInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -635,6 +650,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertNull(ds.getPerUserDefaultTransactionIsolation("missingkey")); } + // -- per user default transaction isolation + @Test public void testPerUserDurationBetweenEvictionRunsMapInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -652,8 +669,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(Duration.ZERO, ds.getPerUserDurationBetweenEvictionRuns("anonymous")); } - // -- per user default transaction isolation - @Test public void testPerUserDurationBetweenEvictionRunsMapNotInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -706,6 +721,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(ds.getDefaultEvictionPolicyClassName(), ds.getPerUserEvictionPolicyClassName("missingkey")); } + // -- per user eviction policy class name + @Test public void testPerUserEvictionPolicyClassNameWithUserMapInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -716,8 +733,6 @@ 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; @@ -764,6 +779,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(ds.getDefaultLifo(), ds.getPerUserLifo("missingkey")); } + // -- per user lifo + @Test public void testPerUserLifoWithUserMapInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -774,8 +791,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(Boolean.FALSE, ds.getPerUserLifo("anotheruser")); } - // -- per user lifo - @Test public void testPerUserLifoWithUserMapNotInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -822,6 +837,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals((Integer) ds.getDefaultMaxIdle(), (Integer) ds.getPerUserMaxIdle("missingkey")); } + // -- per user max idle + @Test public void testPerUserMaxIdleWithUserMapInitialized() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -832,8 +849,6 @@ 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; @@ -936,6 +951,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(ds.getDefaultMaxWait(), ds.getPerUserMaxWaitDuration("missingkey")); } + // -- per user max wait millis + @Test @SuppressWarnings("deprecation") public void testPerUserMaxWaitMillisWithUserMapInitializedDeprecated() { @@ -947,8 +964,6 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(0L, ds.getPerUserMaxWaitMillis("anotheruser")); } - // -- per user max wait millis - @Test @SuppressWarnings("deprecation") public void testPerUserMaxWaitMillisWithUserMapNotInitializedDeprecated() { @@ -1041,6 +1056,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(DURATION_1_MILLISECOND, ds.getPerUserMinEvictableIdleDuration("key")); } + // -- per user min evictable idle time millis + @Test public void testPerUserMinEvictableIdleDurationMapNotInitializedMissingKey() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -1051,8 +1068,6 @@ 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; @@ -1100,6 +1115,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals((Integer) 1, (Integer) ds.getPerUserMinIdle("key")); } + // -- per user min idle + @Test public void testPerUserMinIdleMapNotInitializedMissingKey() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -1109,8 +1126,6 @@ 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; @@ -1158,6 +1173,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals((Integer) 1, (Integer) ds.getPerUserNumTestsPerEvictionRun("key")); } + // -- per user num tests per eviction run + @Test public void testPerUserNumTestsPerEvictionRunMapNotInitializedMissingKey() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -1167,8 +1184,6 @@ 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; @@ -1220,6 +1235,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(DURATION_1_MILLISECOND, ds.getPerUserSoftMinEvictableIdleDuration("key")); } + // -- per user soft min evictable idle time millis + @Test public void testPerUserSoftMinEvictableIdleDurationMapNotInitializedMissingKey() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -1230,8 +1247,6 @@ 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; @@ -1279,6 +1294,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(Boolean.TRUE, ds.getPerUserTestOnBorrow("key")); } + // -- per user test on borrow + @Test public void testPerUserTestOnBorrowMapNotInitializedMissingKey() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -1288,8 +1305,6 @@ 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; @@ -1337,6 +1352,8 @@ public class TestPerUserPoolDataSource extends TestConnectionPool { assertEquals(Boolean.TRUE, ds.getPerUserTestOnCreate("key")); } + // -- per user test on create + @Test public void testPerUserTestOnCreateMapNotInitializedMissingKey() { final PerUserPoolDataSource ds = (PerUserPoolDataSource) this.ds; @@ -1346,8 +1363,6 @@ 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;