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 2020/09/24 02:21:17 UTC
[commons-pool] 01/03: Use try-with-resource. Remove unused imports.
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-pool.git
commit aca566e6a2e01311e16b4aa02bbe84824fa75495
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 23 22:16:49 2020 -0400
Use try-with-resource.
Remove unused imports.
---
.../commons/pool2/impl/AtomicIntegerFactory.java | 1 -
.../pool2/impl/TestBaseGenericObjectPool.java | 45 +++++++++++-----------
2 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/src/test/java/org/apache/commons/pool2/impl/AtomicIntegerFactory.java b/src/test/java/org/apache/commons/pool2/impl/AtomicIntegerFactory.java
index 803d1db..b0b9d1f 100644
--- a/src/test/java/org/apache/commons/pool2/impl/AtomicIntegerFactory.java
+++ b/src/test/java/org/apache/commons/pool2/impl/AtomicIntegerFactory.java
@@ -20,7 +20,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.impl.DefaultPooledObject;
/**
* Factory that sources PooledObjects that wrap AtomicIntegers.
diff --git a/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java
index 8c9f1fb..af06ac3 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java
@@ -71,36 +71,37 @@ public class TestBaseGenericObjectPool {
@Test
public void testActiveTimeStatistics() {
- for (int i = 0; i < 99; i++) { // must be < MEAN_TIMING_STATS_CACHE_SIZE
- pool.updateStatsReturn(i);
- }
- Assert.assertEquals(49, pool.getMeanActiveTimeMillis(), Double.MIN_VALUE);
+ for (int i = 0; i < 99; i++) { // must be < MEAN_TIMING_STATS_CACHE_SIZE
+ pool.updateStatsReturn(i);
+ }
+ Assert.assertEquals(49, pool.getMeanActiveTimeMillis(), Double.MIN_VALUE);
}
@Test
public void testEvictionTimerMultiplePools() throws InterruptedException {
final AtomicIntegerFactory factory = new AtomicIntegerFactory();
factory.setValidateLatency(50);
- final GenericObjectPool<AtomicInteger> evictingPool = new GenericObjectPool<>(factory);
- evictingPool.setTimeBetweenEvictionRunsMillis(100);
- evictingPool.setNumTestsPerEvictionRun(5);
- evictingPool.setTestWhileIdle(true);
- evictingPool.setMinEvictableIdleTimeMillis(50);
- for (int i = 0; i < 10; i++) {
- try {
- evictingPool.addObject();
- } catch (Exception e) {
- e.printStackTrace();
+ try (final GenericObjectPool<AtomicInteger> evictingPool = new GenericObjectPool<>(factory)) {
+ evictingPool.setTimeBetweenEvictionRunsMillis(100);
+ evictingPool.setNumTestsPerEvictionRun(5);
+ evictingPool.setTestWhileIdle(true);
+ evictingPool.setMinEvictableIdleTimeMillis(50);
+ for (int i = 0; i < 10; i++) {
+ try {
+ evictingPool.addObject();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- }
- for (int i = 0; i < 1000; i++) {
- final GenericObjectPool<AtomicInteger> nonEvictingPool = new GenericObjectPool<>(factory);
- nonEvictingPool.close();
- }
+ for (int i = 0; i < 1000; i++) {
+ try (final GenericObjectPool<AtomicInteger> nonEvictingPool = new GenericObjectPool<>(factory)) {
+ // empty
+ }
+ }
- Thread.sleep(1000);
- Assert.assertEquals(0, evictingPool.getNumIdle());
- evictingPool.close();
+ Thread.sleep(1000);
+ Assert.assertEquals(0, evictingPool.getNumIdle());
+ }
}
}