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
The following commit(s) were added to refs/heads/master by this push: new 0913284 Reformat code & fixed some typo. Closes #19. 0913284 is described below commit 0913284f15f89a7c96ededc2474abba1df96b9dc Author: liony <xcw...@163.com> AuthorDate: Sun Feb 3 16:15:13 2019 -0500 Reformat code & fixed some typo. Closes #19. --- .../apache/commons/pool2/TestBaseObjectPool.java | 98 ++++++------- .../apache/commons/pool2/TestKeyedObjectPool.java | 6 +- .../org/apache/commons/pool2/TestObjectPool.java | 6 +- src/test/java/org/apache/commons/pool2/Waiter.java | 12 +- .../pool2/impl/TestGenericKeyedObjectPool.java | 6 +- .../commons/pool2/impl/TestGenericObjectPool.java | 156 ++++++++++----------- .../pool2/impl/TestLinkedBlockingDeque.java | 2 +- .../commons/pool2/impl/TestSoftRefOutOfMemory.java | 6 +- .../commons/pool2/performance/PerformanceTest.java | 18 +-- 9 files changed, 155 insertions(+), 155 deletions(-) diff --git a/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java b/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java index 0e11de5..238b22e 100644 --- a/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/TestBaseObjectPool.java @@ -29,11 +29,11 @@ public class TestBaseObjectPool extends TestObjectPool { private ObjectPool<String> _pool = null; /** - * @param mincapacity Ignored by this implemented. Used by sub-classes. + * @param minCapacity Ignored by this implemented. Used by sub-classes. * * @return A newly created empty pool */ - protected ObjectPool<String> makeEmptyPool(final int mincapacity) { + protected ObjectPool<String> makeEmptyPool(final int minCapacity) { if (this.getClass() != TestBaseObjectPool.class) { fail("Subclasses of TestBaseObjectPool must reimplement this method."); } @@ -117,9 +117,9 @@ public class TestBaseObjectPool extends TestObjectPool { } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } - assertEquals(getNthObject(0),_pool.borrowObject()); - assertEquals(getNthObject(1),_pool.borrowObject()); - assertEquals(getNthObject(2),_pool.borrowObject()); + assertEquals(getNthObject(0), _pool.borrowObject()); + assertEquals(getNthObject(1), _pool.borrowObject()); + assertEquals(getNthObject(2), _pool.borrowObject()); _pool.close(); } @@ -131,18 +131,18 @@ public class TestBaseObjectPool extends TestObjectPool { return; // skip this test if unsupported } try { - assertEquals(0,_pool.getNumIdle()); - assertEquals(0,_pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); _pool.addObject(); - assertEquals(1,_pool.getNumIdle()); - assertEquals(0,_pool.getNumActive()); + assertEquals(1, _pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); final String obj = _pool.borrowObject(); - assertEquals(getNthObject(0),obj); - assertEquals(0,_pool.getNumIdle()); - assertEquals(1,_pool.getNumActive()); + assertEquals(getNthObject(0), obj); + assertEquals(0, _pool.getNumIdle()); + assertEquals(1, _pool.getNumActive()); _pool.returnObject(obj); - assertEquals(1,_pool.getNumIdle()); - assertEquals(0,_pool.getNumActive()); + assertEquals(1, _pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); } catch(final UnsupportedOperationException e) { return; // skip this test if one of those calls is unsupported } finally { @@ -158,17 +158,17 @@ public class TestBaseObjectPool extends TestObjectPool { return; // skip this test if unsupported } String obj0 = _pool.borrowObject(); - assertEquals(getNthObject(0),obj0); + assertEquals(getNthObject(0), obj0); String obj1 = _pool.borrowObject(); - assertEquals(getNthObject(1),obj1); + assertEquals(getNthObject(1), obj1); String obj2 = _pool.borrowObject(); - assertEquals(getNthObject(2),obj2); + assertEquals(getNthObject(2), obj2); _pool.returnObject(obj2); obj2 = _pool.borrowObject(); - assertEquals(getNthObject(2),obj2); + assertEquals(getNthObject(2), obj2); _pool.returnObject(obj1); obj1 = _pool.borrowObject(); - assertEquals(getNthObject(1),obj1); + assertEquals(getNthObject(1), obj1); _pool.returnObject(obj0); _pool.returnObject(obj2); obj2 = _pool.borrowObject(); @@ -193,23 +193,23 @@ public class TestBaseObjectPool extends TestObjectPool { public void testBaseNumActiveNumIdle() throws Exception { try { _pool = makeEmptyPool(3); - } catch(final UnsupportedOperationException e) { + } catch (final UnsupportedOperationException e) { return; // skip this test if unsupported } - assertEquals(0,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); final String obj0 = _pool.borrowObject(); - assertEquals(1,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(1, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); final String obj1 = _pool.borrowObject(); - assertEquals(2,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(2, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); _pool.returnObject(obj1); - assertEquals(1,_pool.getNumActive()); - assertEquals(1,_pool.getNumIdle()); + assertEquals(1, _pool.getNumActive()); + assertEquals(1, _pool.getNumIdle()); _pool.returnObject(obj0); - assertEquals(0,_pool.getNumActive()); - assertEquals(2,_pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); + assertEquals(2, _pool.getNumIdle()); _pool.close(); } @@ -217,24 +217,24 @@ public class TestBaseObjectPool extends TestObjectPool { public void testBaseClear() throws Exception { try { _pool = makeEmptyPool(3); - } catch(final UnsupportedOperationException e) { + } catch (final UnsupportedOperationException e) { return; // skip this test if unsupported } - assertEquals(0,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); final String obj0 = _pool.borrowObject(); final String obj1 = _pool.borrowObject(); - assertEquals(2,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(2, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); _pool.returnObject(obj1); _pool.returnObject(obj0); - assertEquals(0,_pool.getNumActive()); - assertEquals(2,_pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); + assertEquals(2, _pool.getNumIdle()); _pool.clear(); - assertEquals(0,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); final Object obj2 = _pool.borrowObject(); - assertEquals(getNthObject(2),obj2); + assertEquals(getNthObject(2), obj2); _pool.close(); } @@ -242,21 +242,21 @@ public class TestBaseObjectPool extends TestObjectPool { public void testBaseInvalidateObject() throws Exception { try { _pool = makeEmptyPool(3); - } catch(final UnsupportedOperationException e) { + } catch (final UnsupportedOperationException e) { return; // skip this test if unsupported } - assertEquals(0,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); final String obj0 = _pool.borrowObject(); final String obj1 = _pool.borrowObject(); - assertEquals(2,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(2, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); _pool.invalidateObject(obj0); - assertEquals(1,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(1, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); _pool.invalidateObject(obj1); - assertEquals(0,_pool.getNumActive()); - assertEquals(0,_pool.getNumIdle()); + assertEquals(0, _pool.getNumActive()); + assertEquals(0, _pool.getNumIdle()); _pool.close(); } diff --git a/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java index 222b895..750ae8f 100644 --- a/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java @@ -62,15 +62,15 @@ public abstract class TestKeyedObjectPool { /** * Create an {@link KeyedObjectPool} instance - * that can contain at least <i>mincapacity</i> + * that can contain at least <i>minCapacity</i> * idle and active objects, or * throw {@link IllegalArgumentException} * if such a pool cannot be created. - * @param mincapacity Minimum capacity of the pool to create + * @param minCapacity Minimum capacity of the pool to create * * @return the newly created keyed object pool */ - protected abstract KeyedObjectPool<Object,Object> makeEmptyPool(int mincapacity); + protected abstract KeyedObjectPool<Object,Object> makeEmptyPool(int minCapacity); /** * Return what we expect to be the n<sup>th</sup> diff --git a/src/test/java/org/apache/commons/pool2/TestObjectPool.java b/src/test/java/org/apache/commons/pool2/TestObjectPool.java index 38741d4..5d56fb3 100644 --- a/src/test/java/org/apache/commons/pool2/TestObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/TestObjectPool.java @@ -120,7 +120,7 @@ public abstract class TestObjectPool { assertEquals(0, pool.getNumActive()); assertEquals(0, pool.getNumIdle()); - // addObject should make a new object, pasivate it and put it in the pool + // addObject should make a new object, passivate it and put it in the pool pool.addObject(); assertEquals(0, pool.getNumActive()); assertEquals(1, pool.getNumIdle()); @@ -347,7 +347,7 @@ public abstract class TestObjectPool { } catch (final PrivateException ex) { // Expected } - Thread.sleep(250); // could be defered + Thread.sleep(250); // could be deferred removeDestroyObjectCall(factory.getMethodCalls()); assertEquals(expectedMethods, factory.getMethodCalls()); pool.close(); @@ -368,7 +368,7 @@ public abstract class TestObjectPool { PoolUtils.prefill(pool, 5); pool.clear(); - //// Test exception handling clear should swallow destory object failures + //// Test exception handling clear should swallow destroy object failures reset(pool, factory, expectedMethods); factory.setDestroyObjectFail(true); PoolUtils.prefill(pool, 5); diff --git a/src/test/java/org/apache/commons/pool2/Waiter.java b/src/test/java/org/apache/commons/pool2/Waiter.java index 6f99568..0c187b8 100644 --- a/src/test/java/org/apache/commons/pool2/Waiter.java +++ b/src/test/java/org/apache/commons/pool2/Waiter.java @@ -167,12 +167,12 @@ public class Waiter { @Override public String toString() { final StringBuilder buff = new StringBuilder(); - buff.append("ID = " + id + "\n"); - buff.append("valid = " + valid + "\n"); - buff.append("active = " + active + "\n"); - buff.append("lastPassivated = " + lastPassivated + "\n"); - buff.append("lastIdleTimeMs = " + lastIdleTimeMs + "\n"); - buff.append("latency = " + latency + "\n"); + buff.append("ID = " + id + '\n'); + buff.append("valid = " + valid + '\n'); + buff.append("active = " + active + '\n'); + buff.append("lastPassivated = " + lastPassivated + '\n'); + buff.append("lastIdleTimeMs = " + lastIdleTimeMs + '\n'); + buff.append("latency = " + latency + '\n'); return buff.toString(); } } 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 60e2244..41bdff4 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java @@ -67,13 +67,13 @@ import org.junit.Test; public class TestGenericKeyedObjectPool extends TestKeyedObjectPool { @Override - protected KeyedObjectPool<Object,Object> makeEmptyPool(final int mincapacity) { + protected KeyedObjectPool<Object,Object> makeEmptyPool(final int minCapacity) { final KeyedPooledObjectFactory<Object,Object> perKeyFactory = new SimplePerKeyFactory(); final GenericKeyedObjectPool<Object,Object> perKeyPool = new GenericKeyedObjectPool<>(perKeyFactory); - perKeyPool.setMaxTotalPerKey(mincapacity); - perKeyPool.setMaxIdlePerKey(mincapacity); + perKeyPool.setMaxTotalPerKey(minCapacity); + perKeyPool.setMaxIdlePerKey(minCapacity); return perKeyPool; } 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 ba6b2dc..dc0ab98 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java @@ -948,11 +948,11 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } @Override - protected ObjectPool<String> makeEmptyPool(final int mincap) { + protected ObjectPool<String> makeEmptyPool(final int minCap) { final GenericObjectPool<String> mtPool = new GenericObjectPool<>(new SimpleFactory()); - mtPool.setMaxTotal(mincap); - mtPool.setMaxIdle(mincap); + mtPool.setMaxTotal(minCap); + mtPool.setMaxIdle(minCap); return mtPool; } @@ -986,7 +986,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } if(threads[i].failed()) { - fail("Thread "+i+" failed: "+threads[i]._error.toString()); + fail("Thread " + i + " failed: " + threads[i]._error.toString()); } } } @@ -1024,7 +1024,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { Assert.assertEquals(msg.toString(), 0, registeredPoolCount); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testAddObject() throws Exception { assertEquals("should be zero idle", 0, genericObjectPool.getNumIdle()); genericObjectPool.addObject(); @@ -1047,7 +1047,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test(timeout=60000) + @Test(timeout = 60000) public void testBorrowObjectFairness() throws Exception { final int numThreads = 40; @@ -1105,7 +1105,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * On first borrow, first object fails validation, second object is OK. * Subsequent borrows are OK. This was POOL-152. */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testBrokenFactoryShouldNotBlockPool() { final int maxTotal = 1; @@ -1167,7 +1167,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testCloseMultiplePools1() throws Exception { GenericObjectPool<String> genericObjectPool2 = new GenericObjectPool<>(simpleFactory); genericObjectPool.setTimeBetweenEvictionRunsMillis(1); @@ -1176,7 +1176,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { genericObjectPool.close(); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testCloseMultiplePools2() throws Exception { GenericObjectPool<String> genericObjectPool2 = new GenericObjectPool<>(simpleFactory); // Ensure eviction takes a long time, during which time EvictionTimer.executor's queue is empty @@ -1193,13 +1193,13 @@ public class TestGenericObjectPool extends TestBaseObjectPool { genericObjectPool.close(); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testConcurrentBorrowAndEvict() throws Exception { genericObjectPool.setMaxTotal(1); genericObjectPool.addObject(); - for( int i=0; i<5000; i++) { + for (int i = 0; i < 5000; i++) { final ConcurrentBorrowAndEvictThread one = new ConcurrentBorrowAndEvictThread(true); final ConcurrentBorrowAndEvictThread two = @@ -1282,7 +1282,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } - @Test(timeout=60000) + @Test(timeout = 60000) public void testConstructors() throws Exception { // Make constructor arguments all different from defaults @@ -1350,7 +1350,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testDefaultConfiguration() throws Exception { assertConfiguration(new GenericObjectPoolConfig(),genericObjectPool); } @@ -1428,7 +1428,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * * @throws Exception May occur in some failure modes */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictAddObjects() throws Exception { simpleFactory.setMakeLatency(300); simpleFactory.setMaxTotal(2); @@ -1446,12 +1446,12 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertTrue(!borrower.failed()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictFIFO() throws Exception { checkEvict(false); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEviction() throws Exception { genericObjectPool.setMaxIdle(500); genericObjectPool.setMaxTotal(500); @@ -1461,10 +1461,10 @@ public class TestGenericObjectPool extends TestBaseObjectPool { genericObjectPool.setTestWhileIdle(true); final String[] active = new String[500]; - for(int i=0;i<500;i++) { + for (int i = 0; i < 500; i++) { active[i] = genericObjectPool.borrowObject(); } - for(int i=0;i<500;i++) { + for (int i = 0; i < 500; i++) { genericObjectPool.returnObject(active[i]); } @@ -1481,10 +1481,10 @@ public class TestGenericObjectPool extends TestBaseObjectPool { try { Thread.sleep(600L); } catch(final InterruptedException e) { } assertEquals("Should be zero idle, found " + genericObjectPool.getNumIdle(),0,genericObjectPool.getNumIdle()); - for(int i=0;i<500;i++) { + for (int i = 0; i < 500; i++) { active[i] = genericObjectPool.borrowObject(); } - for(int i=0;i<500;i++) { + for (int i = 0; i < 500; i++) { genericObjectPool.returnObject(active[i]); } @@ -1502,7 +1502,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals("Should be zero idle, found " + genericObjectPool.getNumIdle(),0,genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictionInvalid() throws Exception { try (final GenericObjectPool<Object> invalidFactoryPool = new GenericObjectPool<>(new InvalidFactory())) { @@ -1548,7 +1548,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * * @throws Exception May occur in some failure modes */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictionOrder() throws Exception { checkEvictionOrder(false); tearDown(); @@ -1556,7 +1556,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { checkEvictionOrder(true); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictionPolicy() throws Exception { genericObjectPool.setMaxIdle(500); genericObjectPool.setMaxTotal(500); @@ -1604,10 +1604,10 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals(TestEvictionPolicy.class.getName(), genericObjectPool.getEvictionPolicyClassName()); final String[] active = new String[500]; - for(int i=0;i<500;i++) { + for (int i = 0; i < 500; i++) { active[i] = genericObjectPool.borrowObject(); } - for(int i=0;i<500;i++) { + for (int i = 0; i < 500; i++) { genericObjectPool.returnObject(active[i]); } @@ -1622,7 +1622,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals("Should be 0 idle", 0, genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictionSoftMinIdle() throws Exception { class TimeTest extends BasePooledObjectFactory<TimeTest> { private final long createTime; @@ -1678,7 +1678,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictionWithNegativeNumTests() throws Exception { // when numTestsPerEvictionRun is negative, it represents a fraction of the idle objects to test genericObjectPool.setMaxIdle(6); @@ -1688,10 +1688,10 @@ public class TestGenericObjectPool extends TestBaseObjectPool { genericObjectPool.setTimeBetweenEvictionRunsMillis(100L); final String[] active = new String[6]; - for(int i=0;i<6;i++) { + for (int i = 0; i < 6; i++) { active[i] = genericObjectPool.borrowObject(); } - for(int i=0;i<6;i++) { + for (int i = 0; i < 6; i++) { genericObjectPool.returnObject(active[i]); } @@ -1705,7 +1705,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals("Should be zero idle, found " + genericObjectPool.getNumIdle(),0,genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictLIFO() throws Exception { checkEvict(true); } @@ -1722,14 +1722,14 @@ public class TestGenericObjectPool extends TestBaseObjectPool { checkEvictorVisiting(false); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testEvictWhileEmpty() throws Exception { genericObjectPool.evict(); genericObjectPool.evict(); genericObjectPool.close(); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testExceptionOnActivateDuringBorrow() throws Exception { final String obj1 = genericObjectPool.borrowObject(); final String obj2 = genericObjectPool.borrowObject(); @@ -1757,7 +1757,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals(0, genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testExceptionOnDestroyDuringBorrow() throws Exception { simpleFactory.setThrowExceptionOnDestroy(true); genericObjectPool.setTestOnBorrow(true); @@ -1773,7 +1773,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals(0, genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testExceptionOnDestroyDuringReturn() throws Exception { simpleFactory.setThrowExceptionOnDestroy(true); genericObjectPool.setTestOnReturn(true); @@ -1785,7 +1785,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals(0, genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testExceptionOnPassivateDuringReturn() throws Exception { final String obj = genericObjectPool.borrowObject(); simpleFactory.setThrowExceptionOnPassivate(true); @@ -1842,7 +1842,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testFIFO() throws Exception { String o = null; genericObjectPool.setLifo(false); @@ -1940,7 +1940,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { /** * Ensure the pool is registered. */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testJmxRegistration() { final ObjectName oname = genericObjectPool.getJmxName(); final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); @@ -1962,7 +1962,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testLIFO() throws Exception { String o = null; genericObjectPool.setLifo(true); @@ -1988,7 +1988,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * * @throws Exception May occur in some failure modes */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testMakeConcurrentWithReturn() throws Exception { genericObjectPool.setTestOnBorrow(true); simpleFactory.setValid(true); @@ -2005,7 +2005,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals(simpleFactory.getMakeCounter(), genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testMaxIdle() throws Exception { genericObjectPool.setMaxTotal(100); genericObjectPool.setMaxIdle(8); @@ -2022,7 +2022,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testMaxIdleZero() throws Exception { genericObjectPool.setMaxTotal(100); genericObjectPool.setMaxIdle(0); @@ -2042,7 +2042,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { /** * Showcasing a possible deadlock situation as reported in POOL-356 */ - @Test(timeout=60000) + @Test(timeout = 60000) @SuppressWarnings("rawtypes") public void testMaxIdleZeroUnderLoad() { // Config @@ -2124,7 +2124,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testMaxTotal() throws Exception { genericObjectPool.setMaxTotal(3); genericObjectPool.setBlockWhenExhausted(false); @@ -2147,7 +2147,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * * @throws Exception May occur in some failure modes */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testMaxTotalInvariant() throws Exception { final int maxTotal = 15; simpleFactory.setEvenValid(false); // Every other validation fails @@ -2161,7 +2161,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { runTestThreads(5, 10, 50, genericObjectPool); } - @Test(timeout=60000) + @Test(timeout = 60000) @SuppressWarnings("rawtypes") public void testMaxTotalUnderLoad() { // Config @@ -2225,7 +2225,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - for(int i=0;i<numThreads;i++) { + for (int i = 0; i < numThreads; i++) { while(!(threads[i]).complete()) { try { Thread.sleep(500L); @@ -2234,12 +2234,12 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } if(threads[i].failed()) { - fail("Thread "+i+" failed: "+threads[i]._error.toString()); + fail("Thread " + i + " failed: " + threads[i]._error.toString()); } } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testMaxTotalZero() throws Exception { genericObjectPool.setMaxTotal(0); genericObjectPool.setBlockWhenExhausted(false); @@ -2260,7 +2260,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * TestPerUserPoolDataSource.testMultipleThreads2() * Let's see if the this fails on Continuum too! */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testMaxWaitMultiThreaded() throws Exception { final long maxWait = 500; // wait for connection final long holdTime = 2 * maxWait; // how long to hold connection @@ -2270,10 +2270,10 @@ public class TestGenericObjectPool extends TestBaseObjectPool { genericObjectPool.setMaxTotal(threads); // Create enough threads so half the threads will have to wait final WaitingTestThread wtt[] = new WaitingTestThread[threads * 2]; - for(int i=0; i < wtt.length; i++){ + for (int i = 0; i < wtt.length; i++) { wtt[i] = new WaitingTestThread(genericObjectPool,holdTime); } - final long origin = System.currentTimeMillis()-1000; + final long origin = System.currentTimeMillis() - 1000; for (final WaitingTestThread element : wtt) { element.start(); } @@ -2294,19 +2294,19 @@ public class TestGenericObjectPool extends TestBaseObjectPool { ); for (final WaitingTestThread wt : wtt) { System.out.println( - "Preborrow: " + (wt.preborrow-origin) + - " Postborrow: " + (wt.postborrow != 0 ? wt.postborrow-origin : -1) + - " BorrowTime: " + (wt.postborrow != 0 ? wt.postborrow-wt.preborrow : -1) + - " PostReturn: " + (wt.postreturn != 0 ? wt.postreturn-origin : -1) + - " Ended: " + (wt.ended-origin) + + "PreBorrow: " + (wt.preborrow - origin) + + " PostBorrow: " + (wt.postborrow != 0 ? wt.postborrow - origin : -1) + + " BorrowTime: " + (wt.postborrow != 0 ? wt.postborrow - wt.preborrow : -1) + + " PostReturn: " + (wt.postreturn != 0 ? wt.postreturn - origin : -1) + + " Ended: " + (wt.ended - origin) + " ObjId: " + wt.objectId ); } } - assertEquals("Expected half the threads to fail",wtt.length/2,failed); + assertEquals("Expected half the threads to fail",wtt.length / 2, failed); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testMinIdle() throws Exception { genericObjectPool.setMaxIdle(500); genericObjectPool.setMinIdle(5); @@ -2340,7 +2340,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertTrue("Should be 10 idle, found " + genericObjectPool.getNumIdle(),genericObjectPool.getNumIdle() == 10); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testMinIdleMaxTotal() throws Exception { genericObjectPool.setMaxIdle(500); genericObjectPool.setMinIdle(5); @@ -2358,28 +2358,28 @@ public class TestGenericObjectPool extends TestBaseObjectPool { try { Thread.sleep(150L); } catch(final InterruptedException e) { } assertTrue("Should be 5 idle, found " + genericObjectPool.getNumIdle(),genericObjectPool.getNumIdle() == 5); - for(int i=0 ; i<5 ; i++) { + for (int i = 0; i < 5; i++) { active[i] = genericObjectPool.borrowObject(); } try { Thread.sleep(150L); } catch(final InterruptedException e) { } assertTrue("Should be 5 idle, found " + genericObjectPool.getNumIdle(),genericObjectPool.getNumIdle() == 5); - for(int i=0 ; i<5 ; i++) { + for(int i = 0 ; i < 5 ; i++) { genericObjectPool.returnObject(active[i]); } try { Thread.sleep(150L); } catch(final InterruptedException e) { } assertTrue("Should be 10 idle, found " + genericObjectPool.getNumIdle(),genericObjectPool.getNumIdle() == 10); - for(int i=0 ; i<10 ; i++) { + for (int i = 0; i < 10; i++) { active[i] = genericObjectPool.borrowObject(); } try { Thread.sleep(150L); } catch(final InterruptedException e) { } assertTrue("Should be 0 idle, found " + genericObjectPool.getNumIdle(),genericObjectPool.getNumIdle() == 0); - for(int i=0 ; i<10 ; i++) { + for (int i = 0; i < 10; i++) { genericObjectPool.returnObject(active[i]); } @@ -2458,7 +2458,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testNegativeMaxTotal() throws Exception { genericObjectPool.setMaxTotal(-1); genericObjectPool.setBlockWhenExhausted(false); @@ -2536,7 +2536,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * inserted just before the final call to isLifo() in the returnObject() * method. */ - //@Test(timeout=60000) + //@Test(timeout = 60000) public void testReturnObject() throws Exception { genericObjectPool.setMaxTotal(1); @@ -2566,7 +2566,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals(0, genericObjectPool.getNumIdle()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testSetConfig() throws Exception { final GenericObjectPoolConfig expected = new GenericObjectPoolConfig(); assertConfiguration(expected,genericObjectPool); @@ -2585,7 +2585,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertConfiguration(expected,genericObjectPool); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testSettersAndGetters() throws Exception { { // The object receives an Exception during its creation to prevent @@ -2679,7 +2679,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } } - @Test(timeout=60000) + @Test(timeout = 60000) public void testStartAndStopEvictor() throws Exception { // set up pool without evictor genericObjectPool.setMaxIdle(6); @@ -2687,14 +2687,14 @@ public class TestGenericObjectPool extends TestBaseObjectPool { genericObjectPool.setNumTestsPerEvictionRun(6); genericObjectPool.setMinEvictableIdleTimeMillis(100L); - for(int j=0;j<2;j++) { + for (int j = 0; j < 2; j++) { // populate the pool { final String[] active = new String[6]; - for(int i=0;i<6;i++) { + for (int i = 0; i < 6; i++) { active[i] = genericObjectPool.borrowObject(); } - for(int i=0;i<6;i++) { + for (int i = 0; i < 6; i++) { genericObjectPool.returnObject(active[i]); } } @@ -2750,7 +2750,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertEquals(2, swallowedExceptions.size()); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testThreaded1() throws Exception { genericObjectPool.setMaxTotal(15); genericObjectPool.setMaxIdle(15); @@ -2758,7 +2758,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { runTestThreads(20, 100, 50, genericObjectPool); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testTimeoutNoLeak() throws Exception { genericObjectPool.setMaxTotal(2); genericObjectPool.setMaxWaitMillis(10); @@ -2835,7 +2835,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { Assert.assertEquals(1, simpleFactory.validateCounter); } - @Test(timeout=60000) + @Test(timeout = 60000) public void testWhenExhaustedBlock() throws Exception { genericObjectPool.setMaxTotal(1); genericObjectPool.setBlockWhenExhausted(true); @@ -2857,7 +2857,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { * * @throws Exception May occur in some failure modes */ - @Test(timeout=60000) + @Test(timeout = 60000) public void testWhenExhaustedBlockClosePool() throws Exception { genericObjectPool.setMaxTotal(1); genericObjectPool.setBlockWhenExhausted(true); @@ -2883,8 +2883,8 @@ public class TestGenericObjectPool extends TestBaseObjectPool { assertTrue(wtt._thrown instanceof InterruptedException); } - @Test(timeout=60000) - public void testWhenExhaustedBlockInterupt() throws Exception { + @Test(timeout = 60000) + public void testWhenExhaustedBlockInterrupt() throws Exception { genericObjectPool.setMaxTotal(1); genericObjectPool.setBlockWhenExhausted(true); genericObjectPool.setMaxWaitMillis(-1); @@ -2924,7 +2924,7 @@ public class TestGenericObjectPool extends TestBaseObjectPool { } - @Test(timeout=60000) + @Test(timeout = 60000) public void testWhenExhaustedFail() throws Exception { genericObjectPool.setMaxTotal(1); genericObjectPool.setBlockWhenExhausted(false); diff --git a/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java b/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java index f104aa6..3ddfa0c 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java @@ -274,7 +274,7 @@ public class TestLinkedBlockingDeque { } @Test - public void testRemoveLastOccurence() { + public void testRemoveLastOccurrence() { assertFalse(deque.removeLastOccurrence(null)); assertFalse(deque.removeLastOccurrence(ONE)); deque.add(ONE); 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 3328bc5..45877d8 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java @@ -63,7 +63,7 @@ public class TestSoftRefOutOfMemory { if (freeMemory > Integer.MAX_VALUE) { freeMemory = Integer.MAX_VALUE; } - garbage.add(new byte[Math.min(1024 * 1024, (int)freeMemory/2)]); + garbage.add(new byte[Math.min(1024 * 1024, (int) freeMemory / 2)]); } catch (final OutOfMemoryError oome) { System.gc(); } @@ -103,7 +103,7 @@ public class TestSoftRefOutOfMemory { if (freeMemory > Integer.MAX_VALUE) { freeMemory = Integer.MAX_VALUE; } - garbage.add(new byte[Math.min(1024 * 1024, (int)freeMemory/2)]); + garbage.add(new byte[Math.min(1024 * 1024, (int) freeMemory / 2)]); } catch (final OutOfMemoryError oome) { System.gc(); } @@ -139,7 +139,7 @@ public class TestSoftRefOutOfMemory { if (freeMemory > Integer.MAX_VALUE) { freeMemory = Integer.MAX_VALUE; } - garbage.add(new byte[Math.min(1024 * 1024, (int)freeMemory/2)]); + garbage.add(new byte[Math.min(1024 * 1024, (int) freeMemory / 2)]); } catch (final OutOfMemoryError oome) { System.gc(); } diff --git a/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java b/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java index 0220310..8ba9fd3 100644 --- a/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java +++ b/src/test/java/org/apache/commons/pool2/performance/PerformanceTest.java @@ -80,8 +80,8 @@ public class PerformanceTest { final long rend = System.currentTimeMillis(); Thread.yield(); taskStats.complete++; - borrowTime = bend-bbegin; - returnTime = rend-rbegin; + borrowTime = bend - bbegin; + returnTime = rend - rbegin; } catch (final Exception e) { e.printStackTrace(); } @@ -97,10 +97,10 @@ public class PerformanceTest { taskStats.nrSamples++; if (logLevel >= 2) { final String name = "thread" + Thread.currentThread().getName(); - System.out.println("result " + taskStats.nrSamples + "\t" + - name + "\t" + "borrow time: " + borrowTime + "\t" + - "return time: " + returnTime + "\t" + "waiting: " + - taskStats.waiting + "\t" + "complete: " + + System.out.println("result " + taskStats.nrSamples + '\t' + + name + '\t' + "borrow time: " + borrowTime + '\t' + + "return time: " + returnTime + '\t' + "waiting: " + + taskStats.waiting + '\t' + "complete: " + taskStats.complete); } } @@ -175,9 +175,9 @@ public class PerformanceTest { System.out.println("totalBorrowTime: " + aggregate.totalBorrowTime); System.out.println("totalReturnTime: " + aggregate.totalReturnTime); System.out.println("avg BorrowTime: " + - aggregate.totalBorrowTime/aggregate.nrSamples); + aggregate.totalBorrowTime / aggregate.nrSamples); System.out.println("avg ReturnTime: " + - aggregate.totalReturnTime/aggregate.nrSamples); + aggregate.totalReturnTime / aggregate.nrSamples); threadPool.shutdown(); } @@ -191,7 +191,7 @@ public class PerformanceTest { test.run(1, 200, 5, 5); test.run(1, 400, 5, 5); - System.out.println("Increase threads & poolsize"); + System.out.println("Increase threads & poolSize"); test.run(1, 50, 5, 5); test.run(1, 100, 10, 10); test.run(1, 200, 20, 20);