This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch POOL_2_X in repository https://gitbox.apache.org/repos/asf/commons-pool.git
commit 294ef8a5abcc084720e280820375aadfe37dbd68 Author: Gary D. Gregory <[email protected]> AuthorDate: Tue Feb 11 07:58:48 2025 -0500 Add Checkstyle RedundantModifier --- src/conf/checkstyle.xml | 1 + .../java/org/apache/commons/pool2/PoolUtils.java | 12 +- .../commons/pool2/impl/BaseGenericObjectPool.java | 4 +- .../org/apache/commons/pool2/impl/CallStack.java | 2 +- .../apache/commons/pool2/impl/EvictionPolicy.java | 2 +- .../commons/pool2/impl/GenericKeyedObjectPool.java | 2 +- .../pool2/impl/InterruptibleReentrantLock.java | 2 +- .../commons/pool2/impl/LinkedBlockingDeque.java | 10 +- .../commons/pool2/impl/ThrowableCallStack.java | 2 +- .../commons/pool2/AbstractTestKeyedObjectPool.java | 4 +- .../apache/commons/pool2/TestBaseObjectPool.java | 2 +- .../org/apache/commons/pool2/TestPoolUtils.java | 62 ++++------ .../pool2/impl/TestAbandonedKeyedObjectPool.java | 13 +- .../pool2/impl/TestAbandonedObjectPool.java | 29 +++-- .../pool2/impl/TestBaseGenericObjectPool.java | 4 +- .../pool2/impl/TestDefaultPooledObjectInfo.java | 8 +- .../commons/pool2/impl/TestEvictionTimer.java | 2 +- .../pool2/impl/TestGenericKeyedObjectPool.java | 54 +++++---- .../commons/pool2/impl/TestGenericObjectPool.java | 133 +++++++++++---------- .../impl/TestGenericObjectPoolClassLoaders.java | 8 +- .../commons/pool2/impl/TestSoftRefOutOfMemory.java | 2 +- .../commons/pool2/pool407/KeyedPool407Test.java | 4 +- .../apache/commons/pool2/pool407/Pool407Test.java | 4 +- 23 files changed, 183 insertions(+), 183 deletions(-) diff --git a/src/conf/checkstyle.xml b/src/conf/checkstyle.xml index 4e15c733..72800362 100644 --- a/src/conf/checkstyle.xml +++ b/src/conf/checkstyle.xml @@ -78,6 +78,7 @@ <module name="NeedBraces" /> <module name="ParenPad" /> <module name="RedundantImport" /> + <module name="RedundantModifier" /> <module name="TypecastParenPad" /> <module name="VisibilityModifier"> <property name="packageAllowed" value="true" /> diff --git a/src/main/java/org/apache/commons/pool2/PoolUtils.java b/src/main/java/org/apache/commons/pool2/PoolUtils.java index 18db8387..36fe754b 100644 --- a/src/main/java/org/apache/commons/pool2/PoolUtils.java +++ b/src/main/java/org/apache/commons/pool2/PoolUtils.java @@ -61,7 +61,7 @@ public final class PoolUtils { * @param factor * erosion factor */ - public ErodingFactor(final float factor) { + private ErodingFactor(final float factor) { this.factor = factor; nextShrinkMillis = System.currentTimeMillis() + (long) (900000 * factor); // now + 15 min * factor idleHighWaterMark = 1; @@ -72,7 +72,7 @@ public final class PoolUtils { * * @return next shrink time */ - public long getNextShrink() { + private long getNextShrink() { return nextShrinkMillis; } @@ -129,7 +129,7 @@ public final class PoolUtils { * events * @see #erodingFactor */ - protected ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, + private ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final ErodingFactor erodingFactor) { if (keyedPool == null) { throw new IllegalArgumentException( @@ -150,7 +150,7 @@ public final class PoolUtils { * events * @see #erodingFactor */ - public ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, + private ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final float factor) { this(keyedPool, new ErodingFactor(factor)); } @@ -346,7 +346,7 @@ public final class PoolUtils { * events * @see #factor */ - public ErodingObjectPool(final ObjectPool<T> pool, final float factor) { + private ErodingObjectPool(final ObjectPool<T> pool, final float factor) { this.pool = pool; this.factor = new ErodingFactor(factor); } @@ -486,7 +486,7 @@ public final class PoolUtils { * @param factor * erosion factor */ - public ErodingPerKeyKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final float factor) { + private ErodingPerKeyKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final float factor) { super(keyedPool, null); this.factor = factor; } diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java index ab175c3e..85c74294 100644 --- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java +++ b/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java @@ -213,7 +213,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject implements Aut * * @param instance object to wrap */ - public IdentityWrapper(final T instance) { + IdentityWrapper(final T instance) { this.instance = instance; } @@ -226,7 +226,7 @@ public abstract class BaseGenericObjectPool<T> extends BaseObject implements Aut /** * @return the wrapped object */ - public T getObject() { + T getObject() { return instance; } diff --git a/src/main/java/org/apache/commons/pool2/impl/CallStack.java b/src/main/java/org/apache/commons/pool2/impl/CallStack.java index 9db0452a..292de105 100644 --- a/src/main/java/org/apache/commons/pool2/impl/CallStack.java +++ b/src/main/java/org/apache/commons/pool2/impl/CallStack.java @@ -50,5 +50,5 @@ public interface CallStack { * @param writer a PrintWriter to write the current stack trace to if available * @return true if a stack trace was available to print or false if nothing was printed */ - boolean printStackTrace(final PrintWriter writer); + boolean printStackTrace(PrintWriter writer); } diff --git a/src/main/java/org/apache/commons/pool2/impl/EvictionPolicy.java b/src/main/java/org/apache/commons/pool2/impl/EvictionPolicy.java index 2bf10bc8..0b8d8d38 100644 --- a/src/main/java/org/apache/commons/pool2/impl/EvictionPolicy.java +++ b/src/main/java/org/apache/commons/pool2/impl/EvictionPolicy.java @@ -23,7 +23,7 @@ import org.apache.commons.pool2.PooledObject; * DefaultEvictionPolicy} for a pool, users must provide an implementation of * this interface that provides the required eviction policy. * - * @param <T> the type of objects in the pool + * @param <T> the type of objects in the pool. * @since 2.0 */ public interface EvictionPolicy<T> { diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java index e1dbb827..bf019bf9 100644 --- a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java +++ b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java @@ -128,7 +128,7 @@ public class GenericKeyedObjectPool<K, T> extends BaseGenericObjectPool<T> * @param fairness true means client threads waiting to borrow / return instances * will be served as if waiting in a FIFO queue. */ - public ObjectDeque(final boolean fairness) { + private ObjectDeque(final boolean fairness) { idleObjects = new LinkedBlockingDeque<>(fairness); } diff --git a/src/main/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java b/src/main/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java index 8687c7ea..4efe2548 100644 --- a/src/main/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java +++ b/src/main/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java @@ -39,7 +39,7 @@ final class InterruptibleReentrantLock extends ReentrantLock { * @param fairness true means threads should acquire contended locks as if * waiting in a FIFO queue */ - public InterruptibleReentrantLock(final boolean fairness) { + InterruptibleReentrantLock(final boolean fairness) { super(fairness); } diff --git a/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java b/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java index f11fa08b..c0ba8588 100644 --- a/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java +++ b/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java @@ -322,7 +322,7 @@ final class LinkedBlockingDeque<E> extends AbstractQueue<E> * Creates a {@code LinkedBlockingDeque} with a capacity of * {@link Integer#MAX_VALUE}. */ - public LinkedBlockingDeque() { + LinkedBlockingDeque() { this(Integer.MAX_VALUE); } @@ -332,7 +332,7 @@ final class LinkedBlockingDeque<E> extends AbstractQueue<E> * @param fairness true means threads waiting on the deque should be served * as if waiting in a FIFO request queue */ - public LinkedBlockingDeque(final boolean fairness) { + LinkedBlockingDeque(final boolean fairness) { this(Integer.MAX_VALUE, fairness); } @@ -348,7 +348,7 @@ final class LinkedBlockingDeque<E> extends AbstractQueue<E> * @throws NullPointerException if the specified collection or any * of its elements are null */ - public LinkedBlockingDeque(final Collection<? extends E> c) { + LinkedBlockingDeque(final Collection<? extends E> c) { this(Integer.MAX_VALUE); lock.lock(); // Never contended, but necessary for visibility try { @@ -369,7 +369,7 @@ final class LinkedBlockingDeque<E> extends AbstractQueue<E> * @param capacity the capacity of this deque * @throws IllegalArgumentException if {@code capacity} is less than 1 */ - public LinkedBlockingDeque(final int capacity) { + LinkedBlockingDeque(final int capacity) { this(capacity, false); } @@ -382,7 +382,7 @@ final class LinkedBlockingDeque<E> extends AbstractQueue<E> * as if waiting in a FIFO request queue * @throws IllegalArgumentException if {@code capacity} is less than 1 */ - public LinkedBlockingDeque(final int capacity, final boolean fairness) { + LinkedBlockingDeque(final int capacity, final boolean fairness) { if (capacity <= 0) { throw new IllegalArgumentException(); } diff --git a/src/main/java/org/apache/commons/pool2/impl/ThrowableCallStack.java b/src/main/java/org/apache/commons/pool2/impl/ThrowableCallStack.java index d313f591..3d853d2b 100644 --- a/src/main/java/org/apache/commons/pool2/impl/ThrowableCallStack.java +++ b/src/main/java/org/apache/commons/pool2/impl/ThrowableCallStack.java @@ -42,7 +42,7 @@ public class ThrowableCallStack implements CallStack { /** * Constructs a new instance with its message set to the now instant. */ - public Snapshot() { + private Snapshot() { this(Instant.now()); } diff --git a/src/test/java/org/apache/commons/pool2/AbstractTestKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/AbstractTestKeyedObjectPool.java index 1b5706ec..c4ff1354 100644 --- a/src/test/java/org/apache/commons/pool2/AbstractTestKeyedObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/AbstractTestKeyedObjectPool.java @@ -654,7 +654,7 @@ public abstract class AbstractTestKeyedObjectPool { pool.close(); // Test exception handling close should swallow failures - try (final KeyedObjectPool<Object, Object> pool2 = makeEmptyPool(factory)) { + try (KeyedObjectPool<Object, Object> pool2 = makeEmptyPool(factory)) { reset(pool2, factory, expectedMethods); factory.setDestroyObjectFail(true); pool2.addObjects(KEY, 5); @@ -755,7 +755,7 @@ public abstract class AbstractTestKeyedObjectPool { @Test public void testToString() { final FailingKeyedPooledObjectFactory factory = new FailingKeyedPooledObjectFactory(); - try (final KeyedObjectPool<Object, Object> pool = makeEmptyPool(factory)) { + try (KeyedObjectPool<Object, Object> pool = makeEmptyPool(factory)) { pool.toString(); } catch (final UnsupportedOperationException uoe) { return; // test not supported diff --git a/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java b/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java index bc430cef..5fd0efd4 100644 --- a/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java @@ -270,7 +270,7 @@ public class TestBaseObjectPool extends AbstractTestObjectPool { if (!getClass().equals(TestBaseObjectPool.class)) { return; // skip redundant tests } - try (final ObjectPool<Object> pool = new TestObjectPool()) { + try (ObjectPool<Object> pool = new TestObjectPool()) { assertTrue(pool.getNumIdle() < 0, "Negative expected."); assertTrue(pool.getNumActive() < 0, "Negative expected."); diff --git a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java index 902be893..bea3bdab 100644 --- a/src/test/java/org/apache/commons/pool2/TestPoolUtils.java +++ b/src/test/java/org/apache/commons/pool2/TestPoolUtils.java @@ -160,12 +160,12 @@ public class TestPoolUtils { assertThrows(IllegalArgumentException.class, () -> PoolUtils.checkMinIdle(null, new Object(), 1, 1), "PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not allow null pool."); try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { + KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { assertThrows(IllegalArgumentException.class, () -> PoolUtils.checkMinIdle(pool, (Object) null, 1, 1), "PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not accept null keys."); } try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { + KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { assertThrows(IllegalArgumentException.class, () -> PoolUtils.checkMinIdle(pool, new Object(), -1, 1), "PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not accept negative min idle values."); } @@ -176,7 +176,7 @@ public class TestPoolUtils { // Test that the minIdle check doesn't add too many idle objects @SuppressWarnings("unchecked") final KeyedPooledObjectFactory<Object, Object> kpof = createProxy(KeyedPooledObjectFactory.class, calledMethods); - try (final KeyedObjectPool<Object, Object> kop = new GenericKeyedObjectPool<>(kpof)) { + try (KeyedObjectPool<Object, Object> kop = new GenericKeyedObjectPool<>(kpof)) { PoolUtils.checkMinIdle(kop, key, 2, 100); Thread.sleep(400); assertEquals(2, kop.getNumIdle(key)); @@ -198,7 +198,7 @@ public class TestPoolUtils { try { calledMethods.clear(); try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { + KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { // checks minIdle immediately final TimerTask task = PoolUtils.checkMinIdle(pool, key, 1, CHECK_PERIOD); @@ -232,7 +232,7 @@ public class TestPoolUtils { afe = null; final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final KeyedObjectPool<String, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { + KeyedObjectPool<String, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { final Collection<String> keys = new ArrayList<>(2); keys.add("one"); keys.add("two"); @@ -262,13 +262,13 @@ public class TestPoolUtils { @Test public void testCheckMinIdleKeyedObjectPoolKeysNulls() { try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { + KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { assertThrows(IllegalArgumentException.class, () -> PoolUtils.checkMinIdle(pool, (Collection<?>) null, 1, 1), "PoolUtils.checkMinIdle(KeyedObjectPool,Collection,int,long) must not accept null keys."); } try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { + KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { PoolUtils.checkMinIdle(pool, (Collection<?>) Collections.emptyList(), 1, 1); } catch (final IllegalArgumentException iae) { fail("PoolUtils.checkMinIdle(KeyedObjectPool,Collection,int,long) must accept empty lists."); @@ -280,7 +280,7 @@ public class TestPoolUtils { assertThrows(IllegalArgumentException.class, () -> PoolUtils.checkMinIdle(null, 1, 1), "PoolUtils.checkMinIdle(ObjectPool,,) must not allow null pool."); try (@SuppressWarnings("unchecked") - final ObjectPool<Object> pool = createProxy(ObjectPool.class, (List<String>) null)) { + ObjectPool<Object> pool = createProxy(ObjectPool.class, (List<String>) null)) { assertThrows(IllegalArgumentException.class, () -> PoolUtils.checkMinIdle(pool, -1, 1), "PoolUtils.checkMinIdle(ObjectPool,,) must not accept negative min idle values."); } @@ -290,7 +290,7 @@ public class TestPoolUtils { // Test that the minIdle check doesn't add too many idle objects @SuppressWarnings("unchecked") final PooledObjectFactory<Object> pof = createProxy(PooledObjectFactory.class, calledMethods); - try (final ObjectPool<Object> op = new GenericObjectPool<>(pof)) { + try (ObjectPool<Object> op = new GenericObjectPool<>(pof)) { PoolUtils.checkMinIdle(op, 2, 100); Thread.sleep(1000); assertEquals(2, op.getNumIdle()); @@ -311,7 +311,7 @@ public class TestPoolUtils { try { calledMethods.clear(); try (@SuppressWarnings("unchecked") - final ObjectPool<Object> pool = createProxy(ObjectPool.class, calledMethods)) { + ObjectPool<Object> pool = createProxy(ObjectPool.class, calledMethods)) { final TimerTask task = PoolUtils.checkMinIdle(pool, 1, CHECK_PERIOD); // checks minIdle immediately Thread.sleep(CHECK_SLEEP_PERIOD); // will check CHECK_COUNT more times. @@ -363,8 +363,8 @@ public class TestPoolUtils { @Test public void testErodingObjectPoolDefaultFactor() { try (@SuppressWarnings("unchecked") - final ObjectPool<Object> internalPool = createProxy(ObjectPool.class, (arg0, arg1, arg2) -> null); - final ObjectPool<Object> pool = PoolUtils.erodingPool(internalPool)) { + ObjectPool<Object> internalPool = createProxy(ObjectPool.class, (arg0, arg1, arg2) -> null); + ObjectPool<Object> pool = PoolUtils.erodingPool(internalPool)) { final String expectedToString = "ErodingObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, pool=" + internalPool + "}"; // The factor is not exposed, but will be printed in the toString() method @@ -400,7 +400,7 @@ public class TestPoolUtils { // If the logic behind PoolUtils.erodingPool changes then this will need to be tweaked. final float factor = 0.01f; // about ~9 seconds until first discard try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), factor, true)) { + KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), factor, true)) { final List<String> expectedMethods = new ArrayList<>(); assertEquals(expectedMethods, calledMethods); @@ -479,7 +479,7 @@ public class TestPoolUtils { final float factor = 0.01f; // about ~9 seconds until first discard final List<String> expectedMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), factor)) { + KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(createProxy(KeyedObjectPool.class, handler), factor)) { assertEquals(expectedMethods, calledMethods); @@ -535,9 +535,9 @@ public class TestPoolUtils { @Test public void testErodingPoolKeyedObjectPoolDefaultFactor() { try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> internalPool = createProxy(KeyedObjectPool.class, + KeyedObjectPool<Object, Object> internalPool = createProxy(KeyedObjectPool.class, (arg0, arg1, arg2) -> null); - final KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(internalPool)) { + KeyedObjectPool<Object, Object> pool = PoolUtils.erodingPool(internalPool)) { final String expectedToString = "ErodingKeyedObjectPool{factor=ErodingFactor{factor=1.0, idleHighWaterMark=1}, keyedPool=" + internalPool + "}"; // The factor is not exposed, but will be printed in the toString() method @@ -574,7 +574,7 @@ public class TestPoolUtils { final float factor = 0.01f; // about ~9 seconds until first discard final List<String> expectedMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final ObjectPool<Object> pool = PoolUtils.erodingPool(createProxy(ObjectPool.class, handler), factor)) { + ObjectPool<Object> pool = PoolUtils.erodingPool(createProxy(ObjectPool.class, handler), factor)) { assertEquals(expectedMethods, calledMethods); @@ -635,21 +635,17 @@ public class TestPoolUtils { public void testPrefillKeyedObjectPool() throws Exception { assertThrows(IllegalArgumentException.class, () -> PoolUtils.prefill(null, new Object(), 1), "PoolUtils.prefill(KeyedObjectPool,Object,int) must not accept null pool."); - - try (final KeyedObjectPool<Object, String> pool = new GenericKeyedObjectPool<>(new TestGenericKeyedObjectPool.SimpleFactory<>())) { + try (KeyedObjectPool<Object, String> pool = new GenericKeyedObjectPool<>(new TestGenericKeyedObjectPool.SimpleFactory<>())) { assertThrows(IllegalArgumentException.class, () -> PoolUtils.prefill(pool, (Object) null, 1), "PoolUtils.prefill(KeyedObjectPool,Object,int) must not accept null key."); } - final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { - + KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { PoolUtils.prefill(pool, new Object(), 0); final List<String> expectedMethods = new ArrayList<>(); expectedMethods.add("addObjects"); assertEquals(expectedMethods, calledMethods); - calledMethods.clear(); PoolUtils.prefill(pool, new Object(), 3); assertEquals(expectedMethods, calledMethods); @@ -660,21 +656,18 @@ public class TestPoolUtils { @Test public void testPrefillKeyedObjectPoolCollection() throws Exception { try (@SuppressWarnings("unchecked") - final KeyedObjectPool<String, String> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { + KeyedObjectPool<String, String> pool = createProxy(KeyedObjectPool.class, (List<String>) null)) { assertThrows(IllegalArgumentException.class, () -> PoolUtils.prefill(pool, (Collection<String>) null, 1), "PoolUtils.prefill(KeyedObjectPool,Collection,int) must not accept null keys."); } - final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final KeyedObjectPool<String, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { - + KeyedObjectPool<String, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { final Set<String> keys = new HashSet<>(); PoolUtils.prefill(pool, keys, 0); final List<String> expectedMethods = new ArrayList<>(); expectedMethods.add("addObjects"); assertEquals(expectedMethods, calledMethods); - calledMethods.clear(); keys.add("one"); keys.add("two"); @@ -689,16 +682,13 @@ public class TestPoolUtils { @Test public void testPrefillObjectPool() throws Exception { assertThrows(IllegalArgumentException.class, () -> PoolUtils.prefill(null, 1), "PoolUtils.prefill(ObjectPool,int) must not allow null pool."); - final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final ObjectPool<Object> pool = createProxy(ObjectPool.class, calledMethods)) { - + ObjectPool<Object> pool = createProxy(ObjectPool.class, calledMethods)) { PoolUtils.prefill(pool, 0); final List<String> expectedMethods = new ArrayList<>(); expectedMethods.add("addObjects"); assertEquals(expectedMethods, calledMethods); - calledMethods.clear(); PoolUtils.prefill(pool, 3); assertEquals(expectedMethods, calledMethods); @@ -745,8 +735,8 @@ public class TestPoolUtils { final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final KeyedObjectPool<Object, Object> kop = createProxy(KeyedObjectPool.class, calledMethods); - final KeyedObjectPool<Object, Object> skop = PoolUtils.synchronizedPool(kop)) { + KeyedObjectPool<Object, Object> kop = createProxy(KeyedObjectPool.class, calledMethods); + KeyedObjectPool<Object, Object> skop = PoolUtils.synchronizedPool(kop)) { final List<String> expectedMethods = invokeEveryMethod(skop); assertEquals(expectedMethods, calledMethods); } @@ -758,13 +748,11 @@ public class TestPoolUtils { public void testSynchronizedPoolObjectPool() throws Exception { assertThrows(IllegalArgumentException.class, () -> PoolUtils.synchronizedPool((ObjectPool<Object>) null), "PoolUtils.synchronizedPool(ObjectPool) must not allow a null pool."); - final List<String> calledMethods = new ArrayList<>(); try (@SuppressWarnings("unchecked") - final ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods); final ObjectPool<Object> sop = PoolUtils.synchronizedPool(op)) { + ObjectPool<Object> op = createProxy(ObjectPool.class, calledMethods); ObjectPool<Object> sop = PoolUtils.synchronizedPool(op)) { final List<String> expectedMethods = invokeEveryMethod(sop); assertEquals(expectedMethods, calledMethods); - // TODO: Anyone feel motivated to construct a test that verifies proper synchronization? } } diff --git a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedKeyedObjectPool.java index 071edb3d..8c21bdf2 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedKeyedObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedKeyedObjectPool.java @@ -46,10 +46,10 @@ import org.junit.jupiter.api.Test; */ public class TestAbandonedKeyedObjectPool { - final class ConcurrentBorrower extends Thread { + private final class ConcurrentBorrower extends Thread { private final ArrayList<PooledTestObject> borrowed; - public ConcurrentBorrower(final ArrayList<PooledTestObject> borrowed) { + private ConcurrentBorrower(final ArrayList<PooledTestObject> borrowed) { this.borrowed = borrowed; } @@ -62,9 +62,10 @@ public class TestAbandonedKeyedObjectPool { } } } - final class ConcurrentReturner extends Thread { + + private final class ConcurrentReturner extends Thread { private final PooledTestObject returned; - public ConcurrentReturner(final PooledTestObject obj) { + private ConcurrentReturner(final PooledTestObject obj) { returned = obj; } @Override @@ -83,12 +84,12 @@ public class TestAbandonedKeyedObjectPool { private final long destroyLatencyMillis; private final long validateLatencyMillis; - public SimpleFactory() { + private SimpleFactory() { destroyLatencyMillis = 0; validateLatencyMillis = 0; } - public SimpleFactory(final long destroyLatencyMillis, final long validateLatencyMillis) { + private SimpleFactory(final long destroyLatencyMillis, final long validateLatencyMillis) { this.destroyLatencyMillis = destroyLatencyMillis; this.validateLatencyMillis = validateLatencyMillis; } diff --git a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java index 99f03e6b..3d449027 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java @@ -54,11 +54,11 @@ final class PooledTestObject implements TrackedUse { private boolean abandoned; private boolean detached; // destroy-abandoned "detaches" - public PooledTestObject() { + PooledTestObject() { this.hash = ATOMIC_HASH.incrementAndGet(); } - public void destroy(final DestroyMode mode) { + void destroy(final DestroyMode mode) { destroyed = true; if (mode.equals(DestroyMode.ABANDONED)) { detached = true; @@ -100,23 +100,23 @@ final class PooledTestObject implements TrackedUse { return hash; } - public synchronized boolean isActive() { + synchronized boolean isActive() { return active; } - public boolean isDestroyed() { + boolean isDestroyed() { return destroyed; } - public boolean isDetached() { + boolean isDetached() { return detached; } - public void setAbandoned(final boolean b) { + void setAbandoned(final boolean b) { abandoned = b; } - public synchronized void setActive(final boolean b) { + synchronized void setActive(final boolean b) { active = b; } } @@ -126,10 +126,10 @@ final class PooledTestObject implements TrackedUse { */ public class TestAbandonedObjectPool { - final class ConcurrentBorrower extends Thread { + private final class ConcurrentBorrower extends Thread { private final ArrayList<PooledTestObject> borrowed; - public ConcurrentBorrower(final ArrayList<PooledTestObject> borrowed) { + private ConcurrentBorrower(final ArrayList<PooledTestObject> borrowed) { this.borrowed = borrowed; } @@ -142,11 +142,14 @@ public class TestAbandonedObjectPool { } } } - final class ConcurrentReturner extends Thread { + + private final class ConcurrentReturner extends Thread { private final PooledTestObject returned; - public ConcurrentReturner(final PooledTestObject obj) { + + private ConcurrentReturner(final PooledTestObject obj) { returned = obj; } + @Override public void run() { try { @@ -163,12 +166,12 @@ public class TestAbandonedObjectPool { private final long destroyLatency; private final long validateLatency; - public SimpleFactory() { + private SimpleFactory() { destroyLatency = 0; validateLatency = 0; } - public SimpleFactory(final long destroyLatency, final long validateLatency) { + private SimpleFactory(final long destroyLatency, final long validateLatency) { this.destroyLatency = destroyLatency; this.validateLatency = validateLatency; } 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 0368908c..cdf4e28d 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java @@ -92,7 +92,7 @@ public class TestBaseGenericObjectPool { public void testEvictionTimerMultiplePools() throws InterruptedException { final AtomicIntegerFactory factory = new AtomicIntegerFactory(); factory.setValidateLatency(50); - try (final GenericObjectPool<AtomicInteger> evictingPool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<AtomicInteger> evictingPool = new GenericObjectPool<>(factory)) { evictingPool.setTimeBetweenEvictionRuns(Duration.ofMillis(100)); evictingPool.setNumTestsPerEvictionRun(5); evictingPool.setTestWhileIdle(true); @@ -106,7 +106,7 @@ public class TestBaseGenericObjectPool { } for (int i = 0; i < 1000; i++) { - try (final GenericObjectPool<AtomicInteger> nonEvictingPool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<AtomicInteger> nonEvictingPool = new GenericObjectPool<>(factory)) { // empty } } diff --git a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java index fd05ad49..320d14b2 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java @@ -34,7 +34,7 @@ public class TestDefaultPooledObjectInfo { abandonedConfig.setRemoveAbandonedOnBorrow(true); abandonedConfig.setRemoveAbandonedTimeout(TestConstants.ONE_SECOND_DURATION); abandonedConfig.setLogAbandoned(true); - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory(), + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory(), new GenericObjectPoolConfig<>(), abandonedConfig)) { pool.borrowObject(); @@ -50,7 +50,7 @@ public class TestDefaultPooledObjectInfo { @Test public void testGetPooledObjectToString() throws Exception { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory())) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory())) { final String s1 = pool.borrowObject(); @@ -66,7 +66,7 @@ public class TestDefaultPooledObjectInfo { @Test public void testGetPooledObjectType() throws Exception { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory())) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory())) { pool.borrowObject(); @@ -82,7 +82,7 @@ public class TestDefaultPooledObjectInfo { @Test public void testTiming() throws Exception { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory())) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new SimpleFactory())) { final long t1Millis = System.currentTimeMillis(); diff --git a/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java b/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java index 9e332d4c..fd3eb52c 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestEvictionTimer.java @@ -37,7 +37,7 @@ public class TestEvictionTimer { @Test public void testStartStopEvictionTimer() throws Exception { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new BasePooledObjectFactory<String>() { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new BasePooledObjectFactory<String>() { @Override public String create() { diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java index 0f00a466..fd3255fe 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java @@ -88,6 +88,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { public Object create(final Object key) { return null; } + @Override public PooledObject<Object> wrap(final Object value) { return new DefaultPooledObject<>(value); @@ -105,6 +106,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { public HashSet<String> create(final String key) { return new HashSet<>(); } + @Override public PooledObject<HashSet<String>> wrap(final HashSet<String> value) { return new DefaultPooledObject<>(value); @@ -121,13 +123,13 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { private final String key; private boolean done; - public InvalidateThread(final KeyedObjectPool<String, String> pool, final String key, final String obj) { + private InvalidateThread(final KeyedObjectPool<String, String> pool, final String key, final String obj) { this.obj = obj; this.pool = pool; this.key = key; } - public boolean complete() { + private boolean complete() { return done; } @@ -379,19 +381,19 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { private volatile boolean failed; private volatile Exception exception; - public TestThread(final KeyedObjectPool<String, T> pool) { + private TestThread(final KeyedObjectPool<String, T> pool) { this(pool, 100, 50, 50, true, null, null); } - public TestThread(final KeyedObjectPool<String, T> pool, final int iter) { + private TestThread(final KeyedObjectPool<String, T> pool, final int iter) { this(pool, iter, 50, 50, true, null, null); } - public TestThread(final KeyedObjectPool<String, T> pool, final int iter, final int delay) { + private TestThread(final KeyedObjectPool<String, T> pool, final int iter, final int delay) { this(pool, iter, delay, delay, true, null, null); } - public TestThread(final KeyedObjectPool<String, T> pool, final int iter, final int startDelay, + private TestThread(final KeyedObjectPool<String, T> pool, final int iter, final int startDelay, final int holdTime, final boolean randomDelay, final T expectedObject, final String key) { this.pool = pool; this.iter = iter; @@ -403,11 +405,11 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { } - public boolean complete() { + private boolean complete() { return complete; } - public boolean failed() { + private boolean failed() { return failed; } @@ -451,7 +453,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { * Very simple test thread that just tries to borrow an object from * the provided pool with the specified key and returns it after a wait */ - static class WaitingTestThread extends Thread { + private static class WaitingTestThread extends Thread { private final KeyedObjectPool<String, String> pool; private final String key; private final long pause; @@ -463,7 +465,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { private long endedMillis; private String objectId; - public WaitingTestThread(final KeyedObjectPool<String, String> pool, final String key, final long pause) { + private WaitingTestThread(final KeyedObjectPool<String, String> pool, final String key, final long pause) { this.pool = pool; this.key = key; this.pause = pause; @@ -508,7 +510,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { private void checkEvictionOrder(final boolean lifo) throws Exception { final SimpleFactory<Integer> intFactory = new SimpleFactory<>(); - try (final GenericKeyedObjectPool<Integer, String> intPool = new GenericKeyedObjectPool<>(intFactory)) { + try (GenericKeyedObjectPool<Integer, String> intPool = new GenericKeyedObjectPool<>(intFactory)) { intPool.setNumTestsPerEvictionRun(2); intPool.setMinEvictableIdleTime(Duration.ofMillis(100)); intPool.setLifo(lifo); @@ -901,7 +903,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { public void testAppendStats() { assertFalse(gkoPool.getMessageStatistics()); assertEquals("foo", gkoPool.appendStats("foo")); - try (final GenericKeyedObjectPool<?, ?> pool = new GenericKeyedObjectPool<>(new SimpleFactory<>())) { + try (GenericKeyedObjectPool<?, ?> pool = new GenericKeyedObjectPool<>(new SimpleFactory<>())) { pool.setMessagesStatistics(true); assertNotEquals("foo", pool.appendStats("foo")); pool.setMessagesStatistics(false); @@ -1033,7 +1035,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { public void testClearOldest() throws Exception { // Make destroy have some latency so clearOldest takes some time final WaiterFactory<String> waiterFactory = new WaiterFactory<>(0, 20, 0, 0, 0, 0, 50, 5, 0); - try (final GenericKeyedObjectPool<String, Waiter> waiterPool = new GenericKeyedObjectPool<>(waiterFactory)) { + try (GenericKeyedObjectPool<String, Waiter> waiterPool = new GenericKeyedObjectPool<>(waiterFactory)) { waiterPool.setMaxTotalPerKey(5); waiterPool.setMaxTotal(50); waiterPool.setLifo(false); @@ -1188,7 +1190,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { final SimpleFactory<String> factory = new SimpleFactory<>(); // Give makeObject a little latency factory.setMakeLatency(200); - try (final GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory, + try (GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory, new GenericKeyedObjectPoolConfig<>())) { final String s = pool.borrowObject("one"); // First borrow waits on create, so wait time should be at least 200 ms @@ -1466,7 +1468,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { config.setTimeBetweenEvictionRuns(Duration.ofMillis(500)); config.setMinEvictableIdleDuration(Duration.ofMillis(50)); config.setNumTestsPerEvictionRun(5); - try (final GenericKeyedObjectPool<String, String> p = new GenericKeyedObjectPool<>(simpleFactory, config)) { + try (GenericKeyedObjectPool<String, String> p = new GenericKeyedObjectPool<>(simpleFactory, config)) { for (int i = 0; i < 5; i++) { p.addObject("one"); } @@ -1486,7 +1488,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { @Test public void testEqualsIndiscernible() throws Exception { final HashSetFactory factory = new HashSetFactory(); - try (final GenericKeyedObjectPool<String, HashSet<String>> pool = new GenericKeyedObjectPool<>(factory, + try (GenericKeyedObjectPool<String, HashSet<String>> pool = new GenericKeyedObjectPool<>(factory, new GenericKeyedObjectPoolConfig<>())) { final HashSet<String> s1 = pool.borrowObject("a"); final HashSet<String> s2 = pool.borrowObject("a"); @@ -1784,7 +1786,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { @Test public void testInvalidateFreesCapacity() throws Exception { final SimpleFactory<String> factory = new SimpleFactory<>(); - try (final GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { + try (GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { pool.setMaxTotalPerKey(2); pool.setMaxWaitMillis(500); // Borrow an instance and hold if for 5 seconds @@ -1852,7 +1854,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { config.setTestWhileIdle(true); config.setTimeBetweenEvictionRuns(Duration.ofMillis(-1)); - try (final GenericKeyedObjectPool<Integer, Object> pool = new GenericKeyedObjectPool<>(new ObjectFactory(), config)) { + try (GenericKeyedObjectPool<Integer, Object> pool = new GenericKeyedObjectPool<>(new ObjectFactory(), config)) { // Allocate both objects with this thread pool.borrowObject(Integer.valueOf(1)); // object1 @@ -1959,7 +1961,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { @Test public void testMakeObjectException() throws Exception { final SimpleFactory<String> factory = new SimpleFactory<>(); - try (final GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { + try (GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { pool.setMaxTotalPerKey(1); pool.setBlockWhenExhausted(false); factory.exceptionOnCreate = true; @@ -1978,7 +1980,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { final WaiterFactory<String> waiterFactory = new WaiterFactory<>(0, 20, 0, 0, 0, 0, 8, 5, 0); // TODO Fix this. Can't use local pool since runTestThreads uses the // protected pool field - try (final GenericKeyedObjectPool<String, Waiter> waiterPool = new GenericKeyedObjectPool<>(waiterFactory)) { + try (GenericKeyedObjectPool<String, Waiter> waiterPool = new GenericKeyedObjectPool<>(waiterFactory)) { waiterPool.setMaxTotalPerKey(5); waiterPool.setMaxTotal(8); waiterPool.setTestOnBorrow(true); @@ -2389,7 +2391,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { @Test public void testMultipleReturn() throws Exception { final WaiterFactory<String> factory = new WaiterFactory<>(0, 0, 0, 0, 0, 0); - try (final GenericKeyedObjectPool<String, Waiter> pool = new GenericKeyedObjectPool<>(factory)) { + try (GenericKeyedObjectPool<String, Waiter> pool = new GenericKeyedObjectPool<>(factory)) { pool.setTestOnReturn(true); final Waiter waiter = pool.borrowObject("a"); pool.returnObject("a", waiter); @@ -2415,7 +2417,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { @Test public void testMutable() throws Exception { final HashSetFactory factory = new HashSetFactory(); - try (final GenericKeyedObjectPool<String, HashSet<String>> pool = new GenericKeyedObjectPool<>(factory, + try (GenericKeyedObjectPool<String, HashSet<String>> pool = new GenericKeyedObjectPool<>(factory, new GenericKeyedObjectPoolConfig<>())) { final HashSet<String> s1 = pool.borrowObject("a"); final HashSet<String> s2 = pool.borrowObject("a"); @@ -2449,7 +2451,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { DisconnectingWaiterFactory.DEFAULT_DISCONNECTED_VALIDATION_ACTION ); // @formatter:on - try (final GenericKeyedObjectPool<String, Waiter> pool = new GenericKeyedObjectPool<>(factory)) { + try (GenericKeyedObjectPool<String, Waiter> pool = new GenericKeyedObjectPool<>(factory)) { final String key = "one"; pool.setTestOnBorrow(true); pool.setMaxTotal(-1); @@ -2515,7 +2517,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { @Test public void testReturnObjectThrowsIllegalStateException() { - try (final GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(new SimpleFactory<>())) { + try (GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(new SimpleFactory<>())) { assertThrows(IllegalStateException.class, () -> pool.returnObject("Foo", "Bar")); } @@ -2563,7 +2565,7 @@ public class TestGenericKeyedObjectPool extends AbstractTestKeyedObjectPool { final SimpleFactory<String> factory = new SimpleFactory<>(); factory.setValidateLatency(100); factory.setValid(true); // Validation always succeeds - try (final GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { + try (GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { pool.setMaxWaitMillis(1000); pool.setTestWhileIdle(true); pool.setMaxTotalPerKey(2); @@ -2710,7 +2712,7 @@ public void testValidateOnCreateFailure() throws Exception { final SimpleFactory<String> factory = new SimpleFactory<>(); factory.setValid(false); // Validate will always fail factory.setValidationEnabled(true); - try (final GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { + try (GenericKeyedObjectPool<String, String> pool = new GenericKeyedObjectPool<>(factory)) { pool.setMaxTotalPerKey(2); pool.setMaxWaitMillis(1500); pool.setTestOnReturn(true); diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java index 133af3da..b5cd1d20 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java @@ -74,7 +74,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { private final boolean borrow; String obj; - public ConcurrentBorrowAndEvictThread(final boolean borrow) { + private ConcurrentBorrowAndEvictThread(final boolean borrow) { this.borrow = borrow; } @@ -153,7 +153,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { private static final class EvictionThread<T> extends Thread { private final GenericObjectPool<T> pool; - public EvictionThread(final GenericObjectPool<T> pool) { + private EvictionThread(final GenericObjectPool<T> pool) { this.pool = pool; } @@ -186,17 +186,17 @@ public class TestGenericObjectPool extends TestBaseObjectPool { /** * Attempts to invalidate an object, swallowing IllegalStateException. */ - static class InvalidateThread implements Runnable { + private static class InvalidateThread implements Runnable { private final String obj; private final ObjectPool<String> pool; private boolean done; - public InvalidateThread(final ObjectPool<String> pool, final String obj) { + private InvalidateThread(final ObjectPool<String> pool, final String obj) { this.obj = obj; this.pool = pool; } - public boolean complete() { + private boolean complete() { return done; } @@ -232,7 +232,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - public static class SimpleFactory implements PooledObjectFactory<String> { + static class SimpleFactory implements PooledObjectFactory<String> { int makeCounter; int activationCounter; int validateCounter; @@ -249,15 +249,15 @@ public class TestGenericObjectPool extends TestBaseObjectPool { long validateLatency; int maxTotal = Integer.MAX_VALUE; - public SimpleFactory() { + SimpleFactory() { this(true); } - public SimpleFactory(final boolean valid) { + SimpleFactory(final boolean valid) { this(valid, valid); } - public SimpleFactory(final boolean evalid, final boolean ovalid) { + SimpleFactory(final boolean evalid, final boolean ovalid) { evenValid = evalid; oddValid = ovalid; } @@ -302,15 +302,15 @@ public class TestGenericObjectPool extends TestBaseObjectPool { Waiter.sleepQuietly(latency); } - public synchronized int getMakeCounter() { + synchronized int getMakeCounter() { return makeCounter; } - public synchronized boolean isThrowExceptionOnActivate() { + synchronized boolean isThrowExceptionOnActivate() { return exceptionOnActivate; } - public synchronized boolean isValidationEnabled() { + synchronized boolean isValidationEnabled() { return enableValidation; } @@ -345,52 +345,52 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - public synchronized void setDestroyLatency(final long destroyLatency) { + synchronized void setDestroyLatency(final long destroyLatency) { this.destroyLatency = destroyLatency; } - public synchronized void setEvenValid(final boolean valid) { + synchronized void setEvenValid(final boolean valid) { evenValid = valid; } - public synchronized void setMakeLatency(final long makeLatency) { + synchronized void setMakeLatency(final long makeLatency) { this.makeLatency = makeLatency; } - public synchronized void setMaxTotal(final int maxTotal) { + synchronized void setMaxTotal(final int maxTotal) { this.maxTotal = maxTotal; } - public synchronized void setOddValid(final boolean valid) { + synchronized void setOddValid(final boolean valid) { oddValid = valid; } - public synchronized void setThrowExceptionOnActivate(final boolean b) { + synchronized void setThrowExceptionOnActivate(final boolean b) { exceptionOnActivate = b; } - public synchronized void setThrowExceptionOnDestroy(final boolean b) { + synchronized void setThrowExceptionOnDestroy(final boolean b) { exceptionOnDestroy = b; } - public synchronized void setThrowExceptionOnPassivate(final boolean bool) { + synchronized void setThrowExceptionOnPassivate(final boolean bool) { exceptionOnPassivate = bool; } - public synchronized void setThrowExceptionOnValidate(final boolean bool) { + synchronized void setThrowExceptionOnValidate(final boolean bool) { exceptionOnValidate = bool; } - public synchronized void setValid(final boolean valid) { + synchronized void setValid(final boolean valid) { setEvenValid(valid); setOddValid(valid); } - public synchronized void setValidateLatency(final long validateLatency) { + synchronized void setValidateLatency(final long validateLatency) { this.validateLatency = validateLatency; } - public synchronized void setValidationEnabled(final boolean b) { + synchronized void setValidationEnabled(final boolean b) { enableValidation = b; } @@ -423,6 +423,11 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } + /** + * Must not be public for the test to instantiate this class through reflection. + * + * @param <T> the type of objects in the pool. + */ public static class TestEvictionPolicy<T> implements EvictionPolicy<T> { private final AtomicInteger callCount = new AtomicInteger(); @@ -432,7 +437,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - static class TestThread<T> implements Runnable { + private static class TestThread<T> implements Runnable { /** Source of random delay times */ private final Random random; /** Pool to borrow from */ @@ -451,27 +456,27 @@ public class TestGenericObjectPool extends TestBaseObjectPool { private volatile boolean failed; private volatile Throwable error; - public TestThread(final ObjectPool<T> pool) { + private TestThread(final ObjectPool<T> pool) { this(pool, 100, 50, true, null); } - public TestThread(final ObjectPool<T> pool, final int iter) { + private TestThread(final ObjectPool<T> pool, final int iter) { this(pool, iter, 50, true, null); } - public TestThread(final ObjectPool<T> pool, final int iter, final int delay) { + private TestThread(final ObjectPool<T> pool, final int iter, final int delay) { this(pool, iter, delay, true, null); } - public TestThread(final ObjectPool<T> pool, final int iter, final int delay, final boolean randomDelay) { + private TestThread(final ObjectPool<T> pool, final int iter, final int delay, final boolean randomDelay) { this(pool, iter, delay, randomDelay, null); } - public TestThread(final ObjectPool<T> pool, final int iter, final int delay, final boolean randomDelay, final Object obj) { + private TestThread(final ObjectPool<T> pool, final int iter, final int delay, final boolean randomDelay, final Object obj) { this(pool, iter, delay, delay, randomDelay, obj); } - public TestThread(final ObjectPool<T> pool, final int iter, final int startDelay, final int holdTime, final boolean randomDelay, final Object obj) { + private TestThread(final ObjectPool<T> pool, final int iter, final int startDelay, final int holdTime, final boolean randomDelay, final Object obj) { this.pool = pool; this.iter = iter; this.startDelay = startDelay; @@ -481,11 +486,11 @@ public class TestGenericObjectPool extends TestBaseObjectPool { this.expectedObject = obj; } - public boolean complete() { + private boolean complete() { return complete; } - public boolean failed() { + private boolean failed() { return failed; } @@ -527,7 +532,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { /* * Very simple test thread that just tries to borrow an object from the provided pool returns it after a wait */ - static class WaitingTestThread extends Thread { + private static class WaitingTestThread extends Thread { private final GenericObjectPool<String> pool; private final long pause; private Throwable thrown; @@ -537,7 +542,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { private long endedMillis; private String objectId; - public WaitingTestThread(final GenericObjectPool<String> pool, final long pause) { + private WaitingTestThread(final GenericObjectPool<String> pool, final long pause) { this.pool = pool; this.pause = pause; this.thrown = null; @@ -941,7 +946,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { public void testAppendStats() { assertFalse(genericObjectPool.getMessageStatistics()); assertEquals("foo", genericObjectPool.appendStats("foo")); - try (final GenericObjectPool<?> pool = new GenericObjectPool<>(new SimpleFactory())) { + try (GenericObjectPool<?> pool = new GenericObjectPool<>(new SimpleFactory())) { pool.setMessagesStatistics(true); assertNotEquals("foo", pool.appendStats("foo")); pool.setMessagesStatistics(false); @@ -1001,7 +1006,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test @Timeout(value = 1200, unit = TimeUnit.MILLISECONDS) public void testBorrowObjectOverrideMaxWaitLarge() throws Exception { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { pool.setMaxTotal(1); pool.setMaxWait(Duration.ofMillis(1_000)); // large pool.setBlockWhenExhausted(false); @@ -1024,7 +1029,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test @Timeout(value = 1200, unit = TimeUnit.MILLISECONDS) public void testBorrowObjectOverrideMaxWaitSmall() throws Exception { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { pool.setMaxTotal(1); pool.setMaxWait(Duration.ofMillis(1)); // small pool.setBlockWhenExhausted(false); @@ -1137,7 +1142,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { final SimpleFactory factory = new SimpleFactory(); // Give makeObject a little latency factory.setMakeLatency(200); - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(factory, new GenericObjectPoolConfig<>())) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(factory, new GenericObjectPoolConfig<>())) { final String s = pool.borrowObject(); // First borrow waits on create, so wait time should be at least 200 ms // Allow 100ms error in clock times @@ -1155,7 +1160,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) public void testCloseMultiplePools1() { - try (final GenericObjectPool<String> genericObjectPool2 = new GenericObjectPool<>(simpleFactory)) { + try (GenericObjectPool<String> genericObjectPool2 = new GenericObjectPool<>(simpleFactory)) { genericObjectPool.setTimeBetweenEvictionRuns(TestConstants.ONE_MILLISECOND_DURATION); genericObjectPool2.setTimeBetweenEvictionRuns(TestConstants.ONE_MILLISECOND_DURATION); } @@ -1165,7 +1170,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) public void testCloseMultiplePools2() throws Exception { - try (final GenericObjectPool<String> genericObjectPool2 = new GenericObjectPool<>(simpleFactory)) { + try (GenericObjectPool<String> genericObjectPool2 = new GenericObjectPool<>(simpleFactory)) { // Ensure eviction takes a long time, during which time EvictionTimer.executor's queue is empty simpleFactory.setDestroyLatency(1000L); // Ensure there is an object to evict, so that above latency takes effect @@ -1340,7 +1345,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test public void testEqualsIndiscernible() throws Exception { final HashSetFactory factory = new HashSetFactory(); - try (final GenericObjectPool<HashSet<String>> pool = new GenericObjectPool<>(factory, new GenericObjectPoolConfig<>())) { + try (GenericObjectPool<HashSet<String>> pool = new GenericObjectPool<>(factory, new GenericObjectPoolConfig<>())) { final HashSet<String> s1 = pool.borrowObject(); final HashSet<String> s2 = pool.borrowObject(); pool.returnObject(s1); @@ -1351,7 +1356,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test public void testErrorFactoryDoesNotBlockThreads() throws Exception { final CreateErrorFactory factory = new CreateErrorFactory(); - try (final GenericObjectPool<String> createFailFactoryPool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<String> createFailFactoryPool = new GenericObjectPool<>(factory)) { createFailFactoryPool.setMaxTotal(1); // Try and borrow the first object from the pool final WaitingTestThread thread1 = new WaitingTestThread(createFailFactoryPool, 0); @@ -1469,7 +1474,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) public void testEvictionInvalid() throws Exception { - try (final GenericObjectPool<Object> invalidFactoryPool = new GenericObjectPool<>(new InvalidFactory())) { + try (GenericObjectPool<Object> invalidFactoryPool = new GenericObjectPool<>(new InvalidFactory())) { invalidFactoryPool.setMaxIdle(1); invalidFactoryPool.setMaxTotal(1); invalidFactoryPool.setTestOnBorrow(false); @@ -1561,7 +1566,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { final class TimeTest extends BasePooledObjectFactory<TimeTest> { private final long createTimeMillis; - public TimeTest() { + TimeTest() { createTimeMillis = System.currentTimeMillis(); } @@ -1579,7 +1584,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { return new DefaultPooledObject<>(value); } } - try (final GenericObjectPool<TimeTest> timePool = new GenericObjectPool<>(new TimeTest())) { + try (GenericObjectPool<TimeTest> timePool = new GenericObjectPool<>(new TimeTest())) { timePool.setMaxIdle(5); timePool.setMaxTotal(5); timePool.setNumTestsPerEvictionRun(5); @@ -1733,7 +1738,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test public void testFailingFactoryDoesNotBlockThreads() throws Exception { final CreateFailFactory factory = new CreateFailFactory(); - try (final GenericObjectPool<String> createFailFactoryPool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<String> createFailFactoryPool = new GenericObjectPool<>(factory)) { createFailFactoryPool.setMaxTotal(1); // Try and borrow the first object from the pool final WaitingTestThread thread1 = new WaitingTestThread(createFailFactoryPool, 0); @@ -1789,49 +1794,49 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test public void testGetFactoryType_DefaultPooledObjectFactory() { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(createDefaultPooledObjectFactory())) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(createDefaultPooledObjectFactory())) { assertNotNull(pool.getFactoryType()); } } @Test public void testGetFactoryType_NullPooledObjectFactory() { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(createNullPooledObjectFactory())) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(createNullPooledObjectFactory())) { assertNotNull(pool.getFactoryType()); } } @Test public void testGetFactoryType_PoolUtilsSynchronizedDefaultPooledFactory() { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(PoolUtils.synchronizedPooledFactory(createDefaultPooledObjectFactory()))) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(PoolUtils.synchronizedPooledFactory(createDefaultPooledObjectFactory()))) { assertNotNull(pool.getFactoryType()); } } @Test public void testGetFactoryType_PoolUtilsSynchronizedNullPooledFactory() { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(PoolUtils.synchronizedPooledFactory(createNullPooledObjectFactory()))) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(PoolUtils.synchronizedPooledFactory(createNullPooledObjectFactory()))) { assertNotNull(pool.getFactoryType()); } } @Test public void testGetFactoryType_SynchronizedDefaultPooledObjectFactory() { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new TestSynchronizedPooledObjectFactory<>(createDefaultPooledObjectFactory()))) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new TestSynchronizedPooledObjectFactory<>(createDefaultPooledObjectFactory()))) { assertNotNull(pool.getFactoryType()); } } @Test public void testGetFactoryType_SynchronizedNullPooledObjectFactory() { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new TestSynchronizedPooledObjectFactory<>(createNullPooledObjectFactory()))) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new TestSynchronizedPooledObjectFactory<>(createNullPooledObjectFactory()))) { assertNotNull(pool.getFactoryType()); } } @Test public void testGetStatsString() { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new TestSynchronizedPooledObjectFactory<>(createNullPooledObjectFactory()))) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(new TestSynchronizedPooledObjectFactory<>(createNullPooledObjectFactory()))) { assertNotNull(pool.getStatsString()); } } @@ -1846,7 +1851,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test public void testInvalidateFreesCapacity() throws Exception { final SimpleFactory factory = new SimpleFactory(); - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(factory)) { pool.setMaxTotal(2); pool.setMaxWaitMillis(500); // Borrow an instance and hold if for 5 seconds @@ -1880,13 +1885,13 @@ public class TestGenericObjectPool extends TestBaseObjectPool { genericObjectPool.jmxUnregister(); final GenericObjectPoolConfig<String> config = new GenericObjectPoolConfig<>(); config.setJmxEnabled(false); - try (final GenericObjectPool<String> poolWithoutJmx = new GenericObjectPool<>(simpleFactory, config)) { + try (GenericObjectPool<String> poolWithoutJmx = new GenericObjectPool<>(simpleFactory, config)) { assertNull(poolWithoutJmx.getJmxName()); config.setJmxEnabled(true); poolWithoutJmx.jmxUnregister(); } config.setJmxNameBase(null); - try (final GenericObjectPool<String> poolWithDefaultJmxNameBase = new GenericObjectPool<>(simpleFactory, config)) { + try (GenericObjectPool<String> poolWithDefaultJmxNameBase = new GenericObjectPool<>(simpleFactory, config)) { assertNotNull(poolWithDefaultJmxNameBase.getJmxName()); } } @@ -2288,7 +2293,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test public void testMultipleReturn() throws Exception { final WaiterFactory<String> factory = new WaiterFactory<>(0, 0, 0, 0, 0, 0); - try (final GenericObjectPool<Waiter> pool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<Waiter> pool = new GenericObjectPool<>(factory)) { pool.setTestOnReturn(true); final Waiter waiter = pool.borrowObject(); pool.returnObject(waiter); @@ -2308,7 +2313,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { // POOL-248 @Test public void testMultipleReturnOfSameObject() throws Exception { - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(simpleFactory, new GenericObjectPoolConfig<>())) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(simpleFactory, new GenericObjectPoolConfig<>())) { assertEquals(0, pool.getNumActive()); assertEquals(0, pool.getNumIdle()); final String obj = pool.borrowObject(); @@ -2331,7 +2336,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Test public void testMutable() throws Exception { final HashSetFactory factory = new HashSetFactory(); - try (final GenericObjectPool<HashSet<String>> pool = new GenericObjectPool<>(factory, new GenericObjectPoolConfig<>())) { + try (GenericObjectPool<HashSet<String>> pool = new GenericObjectPool<>(factory, new GenericObjectPoolConfig<>())) { final HashSet<String> s1 = pool.borrowObject(); final HashSet<String> s2 = pool.borrowObject(); s1.add("One"); @@ -2361,7 +2366,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { final int delay = 1; final int iterations = 1000; final AtomicIntegerFactory factory = new AtomicIntegerFactory(); - try (final GenericObjectPool<AtomicInteger> pool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<AtomicInteger> pool = new GenericObjectPool<>(factory)) { pool.setMaxTotal(maxTotal); pool.setMaxIdle(maxTotal); pool.setTestOnBorrow(true); @@ -2451,7 +2456,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Timeout(value = 1200, unit = TimeUnit.MILLISECONDS) public void testReturnBorrowObjectWithingMaxWaitDuration() throws Exception { final Duration maxWaitDuration = Duration.ofMillis(500); - try (final GenericObjectPool<String> createSlowObjectFactoryPool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { + try (GenericObjectPool<String> createSlowObjectFactoryPool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { createSlowObjectFactoryPool.setMaxTotal(1); createSlowObjectFactoryPool.setMaxWait(maxWaitDuration); // thread1 tries creating a slow object to make pool full. @@ -2470,7 +2475,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @Timeout(value = 1200, unit = TimeUnit.MILLISECONDS) public void testReturnBorrowObjectWithingMaxWaitMillis() throws Exception { final long maxWaitMillis = 500; - try (final GenericObjectPool<String> createSlowObjectFactoryPool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { + try (GenericObjectPool<String> createSlowObjectFactoryPool = new GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) { createSlowObjectFactoryPool.setMaxTotal(1); createSlowObjectFactoryPool.setMaxWaitMillis(maxWaitMillis); // thread1 tries creating a slow object to make pool full. @@ -2752,7 +2757,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { final SimpleFactory factory = new SimpleFactory(); factory.setValid(false); // Validate will always fail factory.setValidationEnabled(true); - try (final GenericObjectPool<String> pool = new GenericObjectPool<>(factory)) { + try (GenericObjectPool<String> pool = new GenericObjectPool<>(factory)) { pool.setMaxTotal(2); pool.setMaxWaitMillis(1500); pool.setTestOnReturn(true); diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolClassLoaders.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolClassLoaders.java index a237866e..5e66f8d9 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolClassLoaders.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolClassLoaders.java @@ -78,10 +78,10 @@ public class TestGenericObjectPoolClassLoaders { final ClassLoader savedClassloader = Thread.currentThread().getContextClassLoader(); - try (final CustomClassLoader cl1 = new CustomClassLoader(1)) { + try (CustomClassLoader cl1 = new CustomClassLoader(1)) { Thread.currentThread().setContextClassLoader(cl1); final CustomClassLoaderObjectFactory factory1 = new CustomClassLoaderObjectFactory(1); - try (final GenericObjectPool<URL> pool1 = new GenericObjectPool<>(factory1)) { + try (GenericObjectPool<URL> pool1 = new GenericObjectPool<>(factory1)) { pool1.setMinIdle(1); pool1.setDurationBetweenEvictionRuns(Duration.ofMillis(100)); int counter = 0; @@ -91,10 +91,10 @@ public class TestGenericObjectPoolClassLoaders { } assertEquals(1, pool1.getNumIdle(), "Wrong number of idle objects in pool1"); - try (final CustomClassLoader cl2 = new CustomClassLoader(2)) { + try (CustomClassLoader cl2 = new CustomClassLoader(2)) { Thread.currentThread().setContextClassLoader(cl2); final CustomClassLoaderObjectFactory factory2 = new CustomClassLoaderObjectFactory(2); - try (final GenericObjectPool<URL> pool2 = new GenericObjectPool<>(factory2)) { + try (GenericObjectPool<URL> pool2 = new GenericObjectPool<>(factory2)) { pool2.setMinIdle(1); pool2.addObject(); diff --git a/src/test/java/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java b/src/test/java/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java index c7e9f267..79a0aea9 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java @@ -58,7 +58,7 @@ public class TestSoftRefOutOfMemory { private final OomeTrigger trigger; - public OomeFactory(final OomeTrigger trigger) { + OomeFactory(final OomeTrigger trigger) { this.trigger = trigger; } diff --git a/src/test/java/org/apache/commons/pool2/pool407/KeyedPool407Test.java b/src/test/java/org/apache/commons/pool2/pool407/KeyedPool407Test.java index 59e332cc..407ae497 100644 --- a/src/test/java/org/apache/commons/pool2/pool407/KeyedPool407Test.java +++ b/src/test/java/org/apache/commons/pool2/pool407/KeyedPool407Test.java @@ -37,7 +37,7 @@ public class KeyedPool407Test extends AbstractPool407Test { private static final class KeyedPool407RoundtripRunnable implements Runnable { private final KeyedPool407 pool; - public KeyedPool407RoundtripRunnable(final KeyedPool407 pool) { + KeyedPool407RoundtripRunnable(final KeyedPool407 pool) { this.pool = pool; } @@ -73,7 +73,7 @@ public class KeyedPool407Test extends AbstractPool407Test { private void test(final AbstractKeyedPool407Factory factory, final int poolSize, final Duration poolConfigMaxWait) throws Exception { final ExecutorService executor = Executors.newFixedThreadPool(poolSize); - try (final KeyedPool407 pool = new KeyedPool407(factory, poolConfigMaxWait)) { + try (KeyedPool407 pool = new KeyedPool407(factory, poolConfigMaxWait)) { // Start 'poolSize' threads that try to borrow a Pool407Fixture with the same key for (int i = 0; i < poolSize; i++) { executor.execute(new KeyedPool407RoundtripRunnable(pool)); diff --git a/src/test/java/org/apache/commons/pool2/pool407/Pool407Test.java b/src/test/java/org/apache/commons/pool2/pool407/Pool407Test.java index 50e833f3..4c26fdbc 100644 --- a/src/test/java/org/apache/commons/pool2/pool407/Pool407Test.java +++ b/src/test/java/org/apache/commons/pool2/pool407/Pool407Test.java @@ -37,7 +37,7 @@ public class Pool407Test extends AbstractPool407Test { private static final class Pool407RoundtripRunnable implements Runnable { private final Pool407 pool; - public Pool407RoundtripRunnable(final Pool407 pool) { + Pool407RoundtripRunnable(final Pool407 pool) { this.pool = pool; } @@ -70,7 +70,7 @@ public class Pool407Test extends AbstractPool407Test { private void test(final AbstractPool407Factory factory, final int poolSize, final Duration poolConfigMaxWait) throws Exception { final ExecutorService executor = Executors.newFixedThreadPool(poolSize); - try (final Pool407 pool = new Pool407(factory, poolConfigMaxWait)) { + try (Pool407 pool = new Pool407(factory, poolConfigMaxWait)) { // Start 'poolSize' threads that try to borrow a Pool407Fixture with the same key for (int i = 0; i < poolSize; i++) { executor.execute(new Pool407RoundtripRunnable(pool));
