psteitz commented on a change in pull request #32:
URL: https://github.com/apache/commons-pool/pull/32#discussion_r459810041
##########
File path:
src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java
##########
@@ -2996,4 +2909,24 @@ public void testWhenExhaustedFail() throws Exception {
genericObjectPool.close();
}
+ /**
+ * Check that a pool that starts an evictor, but is never closed does not
+ * leave EvictionTimer executor running. Confirmation check is in teardown.
+ */
+ @Test
+ public void testAbandonedPool() throws Exception {
+ GenericObjectPoolConfig config = new GenericObjectPoolConfig();
+ config.setJmxEnabled(false);
+ GenericObjectPool<String> abandoned = new
GenericObjectPool<>(simpleFactory, config);
+ abandoned.setTimeBetweenEvictionRunsMillis(100); // Starts evictor
+
+ // This is ugly, but forces gc to hit the pool
Review comment:
Yes, that is why it has to be done in a loop. Suggestions for a better
way to test this welcome. The teardown method verifies that there are no
abandoned evictor tasks. It will fail unless the weak reference held by the
EvictionTimer to this pool's evictor is cleared. All other pool tests
(correctly) close their pools.
----------------------------------------------------------------
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:
[email protected]