You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/05/21 14:17:04 UTC

[GitHub] [commons-dbcp] garydgregory commented on a change in pull request #40: Add Evictor threads test code.

garydgregory commented on a change in pull request #40:
URL: https://github.com/apache/commons-dbcp/pull/40#discussion_r428679539



##########
File path: src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
##########
@@ -916,6 +917,34 @@ public void testCreateConnectionFactory() throws Exception {
         conn.close();
         ds.close();
     }
+
+    @Test
+    public void testEvict() throws Exception {
+        ds.setInitialSize(10);
+        ds.setMaxIdle(10);
+        ds.setMaxTotal(10);
+        ds.setMinIdle(5);
+        ds.setNumTestsPerEvictionRun(3);
+        ds.setMinEvictableIdleTimeMillis(100);
+        ds.setTimeBetweenEvictionRunsMillis(1000);
+        ds.setPoolPreparedStatements(true);
+
+        Connection conn = ds.getConnection();
+        conn.close();
+
+        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
+        while (Arrays.stream(threadBean.getThreadInfo(threadBean.getAllThreadIds()))
+                .anyMatch(t -> t.getThreadName().equals("commons-pool-evictor-thread"))) {
+            if (ds.getNumIdle() <= ds.getMinIdle()) {
+                break;
+            }
+            Thread.sleep(1000);

Review comment:
       If this `1000` matches the one above in the call to `setTimeBetweenEvictionRunsMillis`, it would make sense to refactor the value in a local variable to make obvious that these must indeed match.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org