commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-pool git commit: [POOL-332] ObjectPool and KeyedObject pool should extend Closeable. Cleaning up tests by managing pools with try-with-resource blocks. More to do.
Date Wed, 01 Nov 2017 16:46:15 GMT
Repository: commons-pool
Updated Branches:
  refs/heads/master 55628bc3e -> c5309f13a


[POOL-332] ObjectPool and KeyedObject pool should extend Closeable.
Cleaning up tests by managing pools with try-with-resource blocks.
More to do.

Project: http://git-wip-us.apache.org/repos/asf/commons-pool/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-pool/commit/c5309f13
Tree: http://git-wip-us.apache.org/repos/asf/commons-pool/tree/c5309f13
Diff: http://git-wip-us.apache.org/repos/asf/commons-pool/diff/c5309f13

Branch: refs/heads/master
Commit: c5309f13a0b5ab35df90090d93792b51ead81688
Parents: 55628bc
Author: Gary Gregory <ggregory@apache.org>
Authored: Wed Nov 1 10:46:13 2017 -0600
Committer: Gary Gregory <ggregory@apache.org>
Committed: Wed Nov 1 10:46:13 2017 -0600

----------------------------------------------------------------------
 .../pool2/impl/TestDefaultPooledObjectInfo.java | 109 +++++++++----------
 1 file changed, 53 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-pool/blob/c5309f13/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java
----------------------------------------------------------------------
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 88728f9..9960115 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java
@@ -27,84 +27,82 @@ public class TestDefaultPooledObjectInfo {
 
     @Test
     public void testTiming() throws Exception {
-        final GenericObjectPool<String> pool =
-                new GenericObjectPool<>(new SimpleFactory());
+        try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new
SimpleFactory())) {
 
-        final long t1 = System.currentTimeMillis();
+            final long t1 = System.currentTimeMillis();
 
-        Thread.sleep(50);
-        final String s1 = pool.borrowObject();
-        Thread.sleep(50);
+            Thread.sleep(50);
+            final String s1 = pool.borrowObject();
+            Thread.sleep(50);
 
-        final long t2 = System.currentTimeMillis();
+            final long t2 = System.currentTimeMillis();
 
-        Thread.sleep(50);
-        pool.returnObject(s1);
-        Thread.sleep(50);
+            Thread.sleep(50);
+            pool.returnObject(s1);
+            Thread.sleep(50);
 
-        final long t3 = System.currentTimeMillis();
+            final long t3 = System.currentTimeMillis();
 
-        Thread.sleep(50);
-        pool.borrowObject();
-        Thread.sleep(50);
+            Thread.sleep(50);
+            pool.borrowObject();
+            Thread.sleep(50);
 
-        final long t4 = System.currentTimeMillis();
+            final long t4 = System.currentTimeMillis();
 
-        final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+            final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
 
-        Assert.assertEquals(1, strings.size());
+            Assert.assertEquals(1, strings.size());
 
-        final DefaultPooledObjectInfo s1Info = strings.iterator().next();
+            final DefaultPooledObjectInfo s1Info = strings.iterator().next();
 
-        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+            final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
 
-        Assert.assertTrue(s1Info.getCreateTime() > t1);
-        Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getCreateTime())),
-                s1Info.getCreateTimeFormatted());
-        Assert.assertTrue(s1Info.getCreateTime() < t2);
+            Assert.assertTrue(s1Info.getCreateTime() > t1);
+            Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getCreateTime())), s1Info.getCreateTimeFormatted());
+            Assert.assertTrue(s1Info.getCreateTime() < t2);
 
-        Assert.assertTrue(s1Info.getLastReturnTime() > t2);
-        Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getLastReturnTime())),
-                s1Info.getLastReturnTimeFormatted());
-        Assert.assertTrue(s1Info.getLastReturnTime() < t3);
+            Assert.assertTrue(s1Info.getLastReturnTime() > t2);
+            Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getLastReturnTime())),
+                    s1Info.getLastReturnTimeFormatted());
+            Assert.assertTrue(s1Info.getLastReturnTime() < t3);
 
-        Assert.assertTrue(s1Info.getLastBorrowTime() > t3);
-        Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getLastBorrowTime())),
-                s1Info.getLastBorrowTimeFormatted());
-        Assert.assertTrue(s1Info.getLastBorrowTime() < t4);
+            Assert.assertTrue(s1Info.getLastBorrowTime() > t3);
+            Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getLastBorrowTime())),
+                    s1Info.getLastBorrowTimeFormatted());
+            Assert.assertTrue(s1Info.getLastBorrowTime() < t4);
+        }
     }
 
     @Test
     public void testGetPooledObjectType() throws Exception {
-        final GenericObjectPool<String> pool =
-                new GenericObjectPool<>(new SimpleFactory());
+        try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new
SimpleFactory())) {
 
-        pool.borrowObject();
+            pool.borrowObject();
 
-        final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+            final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
 
-        Assert.assertEquals(1, strings.size());
+            Assert.assertEquals(1, strings.size());
 
-        final DefaultPooledObjectInfo s1Info = strings.iterator().next();
+            final DefaultPooledObjectInfo s1Info = strings.iterator().next();
 
-        Assert.assertEquals(String.class.getName(),
-                s1Info.getPooledObjectType());
+            Assert.assertEquals(String.class.getName(), s1Info.getPooledObjectType());
+        }
     }
 
     @Test
     public void testGetPooledObjectToString() throws Exception {
-        final GenericObjectPool<String> pool =
-                new GenericObjectPool<>(new SimpleFactory());
+        try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new
SimpleFactory())) {
 
-        final String s1 = pool.borrowObject();
+            final String s1 = pool.borrowObject();
 
-        final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+            final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
 
-        Assert.assertEquals(1, strings.size());
+            Assert.assertEquals(1, strings.size());
 
-        final DefaultPooledObjectInfo s1Info = strings.iterator().next();
+            final DefaultPooledObjectInfo s1Info = strings.iterator().next();
 
-        Assert.assertEquals(s1, s1Info.getPooledObjectToString());
+            Assert.assertEquals(s1, s1Info.getPooledObjectToString());
+        }
     }
 
     @Test
@@ -114,18 +112,17 @@ public class TestDefaultPooledObjectInfo {
         abandonedConfig.setRemoveAbandonedOnBorrow(true);
         abandonedConfig.setRemoveAbandonedTimeout(1);
         abandonedConfig.setLogAbandoned(true);
-        final GenericObjectPool<String> pool = new GenericObjectPool<>(
-                new SimpleFactory(),
-                new GenericObjectPoolConfig(),
-                abandonedConfig);
+        try (final GenericObjectPool<String> pool = new GenericObjectPool<>(new
SimpleFactory(),
+                new GenericObjectPoolConfig(), abandonedConfig)) {
 
-        pool.borrowObject();
-        //pool.returnObject(s1); // Object not returned, causes abandoned object created
exception
+            pool.borrowObject();
+            // pool.returnObject(s1); // Object not returned, causes abandoned object created
exception
 
-        final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
-        final DefaultPooledObjectInfo s1Info = strings.iterator().next();
-        final String lastBorrowTrace = s1Info.getLastBorrowTrace();
+            final Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+            final DefaultPooledObjectInfo s1Info = strings.iterator().next();
+            final String lastBorrowTrace = s1Info.getLastBorrowTrace();
 
-        Assert.assertTrue(lastBorrowTrace.startsWith("Pooled object created"));
+            Assert.assertTrue(lastBorrowTrace.startsWith("Pooled object created"));
+        }
     }
 }


Mime
View raw message