@@ -95,64 +95,6 @@ void testBorrowWaitStatisticsMax() {
9595 assertEquals (20 , pool .getMaxBorrowWaitTimeMillis (), Double .MIN_VALUE );
9696 }
9797
98- @ Test
99- void testEvictionTimerMultiplePools () throws InterruptedException {
100- final AtomicIntegerFactory factory = new AtomicIntegerFactory ();
101- factory .setValidateLatency (50 );
102- try (GenericObjectPool <AtomicInteger > evictingPool = new GenericObjectPool <>(factory )) {
103- evictingPool .setTimeBetweenEvictionRuns (Duration .ofMillis (100 ));
104- evictingPool .setNumTestsPerEvictionRun (5 );
105- evictingPool .setTestWhileIdle (true );
106- evictingPool .setMinEvictableIdleTime (Duration .ofMillis (50 ));
107- for (int i = 0 ; i < 10 ; i ++) {
108- try {
109- evictingPool .addObject ();
110- } catch (final Exception e ) {
111- e .printStackTrace ();
112- }
113- }
114-
115- for (int i = 0 ; i < 1000 ; i ++) {
116- try (GenericObjectPool <AtomicInteger > nonEvictingPool = new GenericObjectPool <>(factory )) {
117- // empty
118- }
119- }
120-
121- Thread .sleep (1000 );
122- assertEquals (0 , evictingPool .getNumIdle ());
123- }
124- }
125-
126- /**
127- * POOL-393
128- * Tests JMX registration does not add too much latency to pool creation.
129- */
130- @ SuppressWarnings ("resource" ) // pools closed in finally block
131- @ Test
132- @ Timeout (value = 10_000 , unit = TimeUnit .MILLISECONDS )
133- void testJMXRegistrationLatency () {
134- final int numPools = 1000 ;
135- final MBeanServer mbs = ManagementFactory .getPlatformMBeanServer ();
136- final ArrayList <GenericObjectPool <Waiter >> pools = new ArrayList <>();
137- try {
138- // final long startTime = System.currentTimeMillis();
139- for (int i = 0 ; i < numPools ; i ++) {
140- pools .add (new GenericObjectPool <>(new WaiterFactory <>(0 , 0 , 0 , 0 , 0 , 0 ), new GenericObjectPoolConfig <>()));
141- }
142- // System.out.println("Duration: " + (System.currentTimeMillis() - startTime));
143- final ObjectName oname = pools .get (numPools - 1 ).getJmxName ();
144- assertEquals (1 , mbs .queryNames (oname , null ).size ());
145- } finally {
146- pools .forEach (GenericObjectPool ::close );
147- }
148- }
149-
150- @ Test
151- void testCollectDetailedStatisticsDefault () {
152- // Test that collectDetailedStatistics defaults to true for backward compatibility
153- assertTrue (pool .getCollectDetailedStatistics ());
154- }
155-
15698 @ Test
15799 void testCollectDetailedStatisticsConfiguration () {
158100 // Test configuration through config object
@@ -168,6 +110,12 @@ void testCollectDetailedStatisticsConfiguration() {
168110 assertTrue (pool .getCollectDetailedStatistics ());
169111 }
170112
113+ @ Test
114+ void testCollectDetailedStatisticsDefault () {
115+ // Test that collectDetailedStatistics defaults to true for backward compatibility
116+ assertTrue (pool .getCollectDetailedStatistics ());
117+ }
118+
171119 @ Test
172120 void testCollectDetailedStatisticsDisabled () throws Exception {
173121 // Configure pool to disable detailed statistics
@@ -229,6 +177,90 @@ void testCollectDetailedStatisticsToggling() throws Exception {
229177 assertEquals (2 , pool .getReturnedCount ());
230178 }
231179
180+ @ Test
181+ void testDetailedStatisticsConfigIntegration () {
182+ // Test that config property is properly applied during pool construction
183+ final GenericObjectPoolConfig <String > config = new GenericObjectPoolConfig <>();
184+ config .setCollectDetailedStatistics (false );
185+ try (GenericObjectPool <String > testPool = new GenericObjectPool <>(factory , config )) {
186+ assertFalse (testPool .getCollectDetailedStatistics (), "Pool should respect collectDetailedStatistics setting from config" );
187+ // Test that toString includes the new property
188+ final String configString = config .toString ();
189+ assertTrue (configString .contains ("collectDetailedStatistics" ), "Config toString should include collectDetailedStatistics property" );
190+ }
191+ }
192+
193+ @ Test
194+ void testEvictionTimerMultiplePools () throws InterruptedException {
195+ final AtomicIntegerFactory factory = new AtomicIntegerFactory ();
196+ factory .setValidateLatency (50 );
197+ try (GenericObjectPool <AtomicInteger > evictingPool = new GenericObjectPool <>(factory )) {
198+ evictingPool .setTimeBetweenEvictionRuns (Duration .ofMillis (100 ));
199+ evictingPool .setNumTestsPerEvictionRun (5 );
200+ evictingPool .setTestWhileIdle (true );
201+ evictingPool .setMinEvictableIdleTime (Duration .ofMillis (50 ));
202+ for (int i = 0 ; i < 10 ; i ++) {
203+ try {
204+ evictingPool .addObject ();
205+ } catch (final Exception e ) {
206+ e .printStackTrace ();
207+ }
208+ }
209+
210+ for (int i = 0 ; i < 1000 ; i ++) {
211+ try (GenericObjectPool <AtomicInteger > nonEvictingPool = new GenericObjectPool <>(factory )) {
212+ // empty
213+ }
214+ }
215+
216+ Thread .sleep (1000 );
217+ assertEquals (0 , evictingPool .getNumIdle ());
218+ }
219+ }
220+
221+ /**
222+ * POOL-393
223+ * Tests JMX registration does not add too much latency to pool creation.
224+ */
225+ @ SuppressWarnings ("resource" ) // pools closed in finally block
226+ @ Test
227+ @ Timeout (value = 10_000 , unit = TimeUnit .MILLISECONDS )
228+ void testJMXRegistrationLatency () {
229+ final int numPools = 1000 ;
230+ final MBeanServer mbs = ManagementFactory .getPlatformMBeanServer ();
231+ final ArrayList <GenericObjectPool <Waiter >> pools = new ArrayList <>();
232+ try {
233+ // final long startTime = System.currentTimeMillis();
234+ for (int i = 0 ; i < numPools ; i ++) {
235+ pools .add (new GenericObjectPool <>(new WaiterFactory <>(0 , 0 , 0 , 0 , 0 , 0 ), new GenericObjectPoolConfig <>()));
236+ }
237+ // System.out.println("Duration: " + (System.currentTimeMillis() - startTime));
238+ final ObjectName oname = pools .get (numPools - 1 ).getJmxName ();
239+ assertEquals (1 , mbs .queryNames (oname , null ).size ());
240+ } finally {
241+ pools .forEach (GenericObjectPool ::close );
242+ }
243+ }
244+
245+ @ Test
246+ void testStatsStoreCircularBuffer () throws Exception {
247+ // Test that StatsStore properly handles circular buffer behavior
248+ final DefaultPooledObject <String > pooledObject = (DefaultPooledObject <String >) factory .makeObject ();
249+ // Fill beyond the cache size (100) to test circular behavior
250+ final int cacheSize = 100 ; // BaseGenericObjectPool.MEAN_TIMING_STATS_CACHE_SIZE
251+ for (int i = 0 ; i < cacheSize + 50 ; i ++) {
252+ pool .updateStatsBorrow (pooledObject , Duration .ofMillis (i ));
253+ pool .updateStatsReturn (Duration .ofMillis (i * 2 ));
254+ }
255+ // Statistics should still be meaningful after circular buffer wrapping
256+ assertTrue (pool .getMeanActiveTimeMillis () > 0 );
257+ assertTrue (pool .getMeanBorrowWaitTimeMillis () > 0 );
258+ assertTrue (pool .getMaxBorrowWaitTimeMillis () > 0 );
259+ // The mean should reflect recent values, not all historical values
260+ // (exact assertion depends on circular buffer implementation)
261+ assertTrue (pool .getMeanBorrowWaitTimeMillis () >= 50 ); // Should be influenced by recent higher values
262+ }
263+
232264 @ Test
233265 void testStatsStoreConcurrentAccess () throws Exception {
234266 // Test the lock-free StatsStore implementation under concurrent load
@@ -277,36 +309,4 @@ void testStatsStoreConcurrentAccess() throws Exception {
277309 executor .shutdown ();
278310 assertTrue (executor .awaitTermination (5 , TimeUnit .SECONDS ));
279311 }
280-
281- @ Test
282- void testStatsStoreCircularBuffer () throws Exception {
283- // Test that StatsStore properly handles circular buffer behavior
284- final DefaultPooledObject <String > pooledObject = (DefaultPooledObject <String >) factory .makeObject ();
285- // Fill beyond the cache size (100) to test circular behavior
286- final int cacheSize = 100 ; // BaseGenericObjectPool.MEAN_TIMING_STATS_CACHE_SIZE
287- for (int i = 0 ; i < cacheSize + 50 ; i ++) {
288- pool .updateStatsBorrow (pooledObject , Duration .ofMillis (i ));
289- pool .updateStatsReturn (Duration .ofMillis (i * 2 ));
290- }
291- // Statistics should still be meaningful after circular buffer wrapping
292- assertTrue (pool .getMeanActiveTimeMillis () > 0 );
293- assertTrue (pool .getMeanBorrowWaitTimeMillis () > 0 );
294- assertTrue (pool .getMaxBorrowWaitTimeMillis () > 0 );
295- // The mean should reflect recent values, not all historical values
296- // (exact assertion depends on circular buffer implementation)
297- assertTrue (pool .getMeanBorrowWaitTimeMillis () >= 50 ); // Should be influenced by recent higher values
298- }
299-
300- @ Test
301- void testDetailedStatisticsConfigIntegration () {
302- // Test that config property is properly applied during pool construction
303- final GenericObjectPoolConfig <String > config = new GenericObjectPoolConfig <>();
304- config .setCollectDetailedStatistics (false );
305- try (GenericObjectPool <String > testPool = new GenericObjectPool <>(factory , config )) {
306- assertFalse (testPool .getCollectDetailedStatistics (), "Pool should respect collectDetailedStatistics setting from config" );
307- // Test that toString includes the new property
308- final String configString = config .toString ();
309- assertTrue (configString .contains ("collectDetailedStatistics" ), "Config toString should include collectDetailedStatistics property" );
310- }
311- }
312312}
0 commit comments