commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [commons-pool] branch master updated: Fix compiler warnings.
Date Sun, 03 Feb 2019 21:19:31 GMT
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 65c994a  Fix compiler warnings.
65c994a is described below

commit 65c994ad3c1e6bcd5bbb66da2b05d9e224517aa2
Author: Gary Gregory <ggregory@rocketsoftware.com>
AuthorDate: Sun Feb 3 16:19:29 2019 -0500

    Fix compiler warnings.
---
 .../TestGenericObjectPoolFactoryCreateFailure.java | 107 +++++++++++----------
 1 file changed, 56 insertions(+), 51 deletions(-)

diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolFactoryCreateFailure.java
b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolFactoryCreateFailure.java
index 5bbf2bc..20e62a1 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolFactoryCreateFailure.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPoolFactoryCreateFailure.java
@@ -30,52 +30,9 @@ import org.junit.Test;
  */
 public class TestGenericObjectPoolFactoryCreateFailure {
 
-    @Test(timeout = 10_000)
-    public void testBorrowObjectStuck() {
-        SingleObjectFactory factory = new SingleObjectFactory();
-        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
-        config.setMaxIdle(1);
-        config.setMaxTotal(1);
-        config.setBlockWhenExhausted(true);
-        config.setMinIdle(0);
-        config.setTestOnBorrow(true);
-        config.setTestOnReturn(true);
-        config.setTestWhileIdle(false);
-        config.setTimeBetweenEvictionRunsMillis(-1);
-        config.setMinEvictableIdleTimeMillis(-1);
-        config.setSoftMinEvictableIdleTimeMillis(-1);
-
-        config.setMaxWaitMillis(-1);
-        GenericObjectPool<Object> pool = new GenericObjectPool<>(factory, config);
-
-        AtomicBoolean failed = new AtomicBoolean();
-        CountDownLatch barrier = new CountDownLatch(1);
-        Thread thread1 = new Thread(new WinnerRunnable(pool, barrier, failed));
-        thread1.start();
-
-        // wait for object to be created
-        while(!factory.created.get()) {
-            sleepIgnoreException(5);
-        }
-
-        // now borrow
-        barrier.countDown();
-        try {
-            System.out.println("try borrow in main thread");
-
-            Object o = pool.borrowObject();
-            System.out.println("Success borrow in main thread " + o);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        Assert.assertFalse(failed.get());
-
-    }
-
     private static class SingleObjectFactory extends BasePooledObjectFactory<Object>
{
         private final AtomicBoolean created = new AtomicBoolean();
-        private final AtomicBoolean validated = new AtomicBoolean();
+        
         @Override
         public Object create() throws Exception {
             if (!created.getAndSet(true)) {
@@ -85,20 +42,20 @@ public class TestGenericObjectPoolFactoryCreateFailure {
         }
 
         @Override
-        public PooledObject<Object> wrap(Object obj) {
-            return new DefaultPooledObject<>(new Object());
+        public boolean validateObject(PooledObject<Object> p) {
+            return true;
         }
 
         @Override
-        public boolean validateObject(PooledObject<Object> p) {
-            return true;
+        public PooledObject<Object> wrap(Object obj) {
+            return new DefaultPooledObject<>(new Object());
         }
     }
 
     private static class WinnerRunnable implements Runnable {
-        private final GenericObjectPool<Object> pool;
-        private final AtomicBoolean failed;
         private final CountDownLatch barrier;
+        private final AtomicBoolean failed;
+        private final GenericObjectPool<Object> pool;
         private WinnerRunnable(GenericObjectPool<Object> pool, CountDownLatch barrier,
AtomicBoolean failed) {
             this.pool = pool;
             this.failed = failed;
@@ -120,7 +77,7 @@ public class TestGenericObjectPoolFactoryCreateFailure {
                 }
 
                 pool.returnObject(obj);
-                System.out.println("ended borrowing in parallel thread");
+                println("ended borrowing in parallel thread");
             } catch (Exception e) {
                 failed.set(true);
                 e.printStackTrace();
@@ -128,6 +85,10 @@ public class TestGenericObjectPoolFactoryCreateFailure {
         }
     }
 
+    private static void println(final String msg) {
+        System.out.println(msg);
+    }
+
     private static void sleepIgnoreException(long millis) {
         try {
             Thread.sleep(millis);
@@ -135,4 +96,48 @@ public class TestGenericObjectPoolFactoryCreateFailure {
             // ignore
         }
     }
+    
+    @Test(timeout = 10_000)
+    public void testBorrowObjectStuck() {
+        SingleObjectFactory factory = new SingleObjectFactory();
+        GenericObjectPoolConfig<Object> config = new GenericObjectPoolConfig<>();
+        config.setMaxIdle(1);
+        config.setMaxTotal(1);
+        config.setBlockWhenExhausted(true);
+        config.setMinIdle(0);
+        config.setTestOnBorrow(true);
+        config.setTestOnReturn(true);
+        config.setTestWhileIdle(false);
+        config.setTimeBetweenEvictionRunsMillis(-1);
+        config.setMinEvictableIdleTimeMillis(-1);
+        config.setSoftMinEvictableIdleTimeMillis(-1);
+
+        config.setMaxWaitMillis(-1);
+        try (GenericObjectPool<Object> pool = new GenericObjectPool<>(factory,
config)) {
+
+            AtomicBoolean failed = new AtomicBoolean();
+            CountDownLatch barrier = new CountDownLatch(1);
+            Thread thread1 = new Thread(new WinnerRunnable(pool, barrier, failed));
+            thread1.start();
+
+            // wait for object to be created
+            while (!factory.created.get()) {
+                sleepIgnoreException(5);
+            }
+
+            // now borrow
+            barrier.countDown();
+            try {
+                println("try borrow in main thread");
+
+                Object o = pool.borrowObject();
+                println("Success borrow in main thread " + o);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+            Assert.assertFalse(failed.get());
+        }
+
+    }
 }
\ No newline at end of file


Mime
View raw message