You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/07/14 16:22:40 UTC

[commons-pool] branch master updated (40ec36fa -> 7621c40e)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git


    from 40ec36fa Javadoc tweaks
     new 9f87273f Flip conditional in test
     new e4f93724 Use the diamond notation
     new d88a1992 Use try-with-resources in test
     new 521154fa Remove unused exception in test
     new 16ba105c Use modern JUnit API
     new 7621c40e Use modern JUnit API

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/commons/pool2/TestKeyedObjectPool.java  |  7 +---
 .../pool2/impl/DisconnectingWaiterFactory.java     | 22 ++++++------
 .../pool2/impl/TestGenericKeyedObjectPool.java     | 39 ++++++++--------------
 3 files changed, 24 insertions(+), 44 deletions(-)


[commons-pool] 03/06: Use try-with-resources in test

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit d88a1992240c5ee143a19f872789d6aa269c3dd5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 14 11:44:28 2023 -0400

    Use try-with-resources in test
---
 .../pool2/impl/TestGenericKeyedObjectPool.java     | 52 +++++++++++-----------
 1 file changed, 27 insertions(+), 25 deletions(-)

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 cb6712b5..94f7c32b 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -2445,37 +2445,39 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
     @Test
     @Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
     public void testNPEOnFactoryNull() throws InterruptedException {
+        // @formatter:off
         final DisconnectingWaiterFactory<String> factory = new DisconnectingWaiterFactory<>(
             () -> null,  // Override default to always return null from makeObject
             DisconnectingWaiterFactory.DEFAULT_DISCONNECTED_LIFECYCLE_ACTION,
             DisconnectingWaiterFactory.DEFAULT_DISCONNECTED_VALIDATION_ACTION
         );
-        final GenericKeyedObjectPool<String,Waiter,RuntimeException> pool = new GenericKeyedObjectPool<>(factory);
-        final String key = "one";
-        pool.setTestOnBorrow(true);
-        pool.setMaxTotal(-1);
-        pool.setMinIdlePerKey(1);
-        // Disconnect the factory - will always return null in this state
-        factory.disconnect();
-        try {
-            pool.borrowObject(key);
-            fail("Expecting NullPointerException");
-        } catch (final NullPointerException ex) {
-            // expected
-        }
-        try {
-            pool.addObject(key);
-            fail("Expecting NullPointerException");
-        } catch (final NullPointerException ex2) {
-            // expected
-        }
-        try {
-            pool.ensureMinIdle();
-            fail("Expecting NullPointerException");
-        } catch (final NullPointerException ex3) {
-            // expected
+        // @formatter:on
+        try (final GenericKeyedObjectPool<String, Waiter, RuntimeException> pool = new GenericKeyedObjectPool<>(factory)) {
+            final String key = "one";
+            pool.setTestOnBorrow(true);
+            pool.setMaxTotal(-1);
+            pool.setMinIdlePerKey(1);
+            // Disconnect the factory - will always return null in this state
+            factory.disconnect();
+            try {
+                pool.borrowObject(key);
+                fail("Expecting NullPointerException");
+            } catch (final NullPointerException ex) {
+                // expected
+            }
+            try {
+                pool.addObject(key);
+                fail("Expecting NullPointerException");
+            } catch (final NullPointerException ex2) {
+                // expected
+            }
+            try {
+                pool.ensureMinIdle();
+                fail("Expecting NullPointerException");
+            } catch (final NullPointerException ex3) {
+                // expected
+            }
         }
-        pool.close();
     }
 
     @Test


[commons-pool] 01/06: Flip conditional in test

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 9f87273f988b71ce1dfa378a15190b99ead252b0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 14 11:37:08 2023 -0400

    Flip conditional in test
    
    Reduce nesting
---
 .../pool2/impl/DisconnectingWaiterFactory.java       | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java b/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java
index 94a38993..1385130b 100644
--- a/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java
+++ b/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java
@@ -141,9 +141,8 @@ public class DisconnectingWaiterFactory<K> extends WaiterFactory<K> {
     private boolean validate(final PooledObject<Waiter> obj) {
         if (connected.get()) {
             return super.validateObject(obj);
-        } else {
-            return disconnectedValidationAction.test(obj);
         }
+        return disconnectedValidationAction.test(obj);
     }
 
     @Override
@@ -157,18 +156,18 @@ public class DisconnectingWaiterFactory<K> extends WaiterFactory<K> {
     }
 
     private void activate(final PooledObject<Waiter> obj) {
-        if (!connected.get()) {
-            disconnectedLifcycleAction.accept(obj);
-        } else {
+        if (connected.get()) {
             super.activateObject(obj);
+        } else {
+            disconnectedLifcycleAction.accept(obj);
         }
     }
 
     private void passivate(final PooledObject<Waiter> obj) {
-        if (!connected.get()) {
-            disconnectedLifcycleAction.accept(obj);
-        } else {
+        if (connected.get()) {
             super.passivateObject(obj);
+        } else {
+            disconnectedLifcycleAction.accept(obj);
         }
     }
 
@@ -203,11 +202,10 @@ public class DisconnectingWaiterFactory<K> extends WaiterFactory<K> {
     }
 
     private PooledObject<Waiter> make() {
-        if (!connected.get()) {
-            return disconnectedCreateAction.get();
-        } else {
+        if (connected.get()) {
             return super.makeObject();
         }
+        return disconnectedCreateAction.get();
     }
 
     /**


[commons-pool] 05/06: Use modern JUnit API

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 16ba105c13ce65c0f6926e8151a7ee2e97ce3bed
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 14 11:46:46 2023 -0400

    Use modern JUnit API
---
 .../pool2/impl/TestGenericKeyedObjectPool.java      | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

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 9bca8bc1..c10dcdb4 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -2459,24 +2459,9 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
             pool.setMinIdlePerKey(1);
             // Disconnect the factory - will always return null in this state
             factory.disconnect();
-            try {
-                pool.borrowObject(key);
-                fail("Expecting NullPointerException");
-            } catch (final NullPointerException ex) {
-                // expected
-            }
-            try {
-                pool.addObject(key);
-                fail("Expecting NullPointerException");
-            } catch (final NullPointerException ex2) {
-                // expected
-            }
-            try {
-                pool.ensureMinIdle();
-                fail("Expecting NullPointerException");
-            } catch (final NullPointerException ex3) {
-                // expected
-            }
+            assertThrows(NullPointerException.class, () -> pool.borrowObject(key));
+            assertThrows(NullPointerException.class, () -> pool.addObject(key));
+            assertThrows(NullPointerException.class, pool::ensureMinIdle);
         }
     }
 


[commons-pool] 04/06: Remove unused exception in test

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 521154fad4055e90dde4195b2d1a8ac5d3b492fe
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 14 11:44:39 2023 -0400

    Remove unused exception in test
---
 .../java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 94f7c32b..9bca8bc1 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -2444,7 +2444,7 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
      */
     @Test
     @Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
-    public void testNPEOnFactoryNull() throws InterruptedException {
+    public void testNPEOnFactoryNull() {
         // @formatter:off
         final DisconnectingWaiterFactory<String> factory = new DisconnectingWaiterFactory<>(
             () -> null,  // Override default to always return null from makeObject


[commons-pool] 02/06: Use the diamond notation

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit e4f937249e8fcafe68a9ace0916d39e76696fdf6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 14 11:37:28 2023 -0400

    Use the diamond notation
---
 .../java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java b/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java
index 1385130b..36c6cfad 100644
--- a/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java
+++ b/src/test/java/org/apache/commons/pool2/impl/DisconnectingWaiterFactory.java
@@ -59,7 +59,7 @@ public class DisconnectingWaiterFactory<K> extends WaiterFactory<K> {
      */
     protected static final Supplier<PooledObject<Waiter>> DEFAULT_DISCONNECTED_CREATE_ACTION = () -> {
         waitForConnection(null, DEFAULT_TIME_BETWEEN_CONNECTION_CHECKS, DEFAULT_MAX_WAIT);
-        return new DefaultPooledObject<Waiter>(new Waiter(true, true, 0));
+        return new DefaultPooledObject<>(new Waiter(true, true, 0));
     };
 
     /**


[commons-pool] 06/06: Use modern JUnit API

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit 7621c40eaa0ceadaffd7112e1090e429abd75cb6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 14 11:52:06 2023 -0400

    Use modern JUnit API
---
 src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java
index 86c0fd79..bcdde1a4 100644
--- a/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/TestKeyedObjectPool.java
@@ -573,12 +573,7 @@ public abstract class TestKeyedObjectPool {
 
         // makeObject Exceptions should be propagated to client code from borrowObject
         factory.setMakeObjectFail(true);
-        try {
-            obj = pool.borrowObject(KEY);
-            fail("Expected borrowObject to propagate makeObject exception.");
-        } catch (final PrivateException pe) {
-            // expected
-        }
+        assertThrows(PrivateException.class, () -> pool.borrowObject(KEY), "Expected borrowObject to propagate makeObject exception.");
         expectedMethods.add(new MethodCall("makeObject", KEY));
         assertEquals(expectedMethods, factory.getMethodCalls());