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

psteitz 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 4b902aaf Cleanup.
     new 2801f56b Merge branch 'master' of 
https://github.com/apache/commons-pool
4b902aaf is described below

commit 4b902aaf8697baaf129495bb435b10c73d74f34c
Author: Phil Steitz <phil.ste...@gmail.com>
AuthorDate: Fri May 31 19:48:22 2024 -0700

    Cleanup.
---
 .../pool3/impl/ResilientPooledObjectFactory.java   | 73 +++++++++++++++-------
 .../impl/TestResilientPooledObjectFactory.java     | 41 +++++++++++-
 2 files changed, 90 insertions(+), 24 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java 
b/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
index 6cc8877e..b8c2cb96 100644
--- 
a/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
+++ 
b/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
@@ -123,6 +123,7 @@ public class ResilientPooledObjectFactory<T, E extends 
Exception> implements Poo
             return obj;
         } catch (Throwable t) {
             makeEvent.setSuccess(false);
+            makeEvent.setException(t);
             exceptionCounts.put(t.getClass(), exceptionCounts.getOrDefault(t, 
0) + 1);
             throw t;
         } finally {
@@ -273,11 +274,7 @@ public class ResilientPooledObjectFactory<T, E extends 
Exception> implements Poo
                     try {
                         Thread.sleep(delay.toMillis());
                     } catch (InterruptedException e) {
-                        // Ignore
-                    } catch (Throwable e) {
                         killed = true;
-                        running = false;
-                        throw (e);
                     }
                 }
             }
@@ -285,13 +282,6 @@ public class ResilientPooledObjectFactory<T, E extends 
Exception> implements Poo
             running = false;
         }
 
-        public void start() {
-            if (killed) {
-                killed = false;
-            }
-            run();
-        }
-
         public boolean isRunning() {
             return running;
         }
@@ -309,7 +299,6 @@ public class ResilientPooledObjectFactory<T, E extends 
Exception> implements Poo
         private Instant endTime;
         private boolean success;
         private Throwable exception;
-        private String message;
 
         /**
          * Constructor set statTime to now.
@@ -348,15 +337,6 @@ public class ResilientPooledObjectFactory<T, E extends 
Exception> implements Poo
         public Instant getStartTime() {
             return startTime;
         }
-
-        public String getMessage() {
-            return message;
-        }
-
-        public void setMessage(String message) {
-            this.message = message;
-        }
-
     }
 
     class Monitor extends Thread {
@@ -370,10 +350,59 @@ public class ResilientPooledObjectFactory<T, E extends 
Exception> implements Poo
                     monitoring = false;
                 } catch (Throwable e) {
                     monitoring = false;
-                    throw (e);
+                    throw e;
                 }
             }
             monitoring = false;
         }
     }
+
+    public static int getDefaultLogSize() {
+        return DEFAULT_LOG_SIZE;
+    }
+
+    public static Duration getDefaultDelay() {
+        return DEFAULT_DELAY;
+    }
+
+    public static Duration getDefaultLookBack() {
+        return DEFAULT_LOOK_BACK;
+    }
+
+    public static Duration getDefaultTimeBetweenChecks() {
+        return DEFAULT_TIME_BETWEEN_CHECKS;
+    }
+
+    public int getLogSize() {
+        return logSize;
+    }
+
+    public Duration getLookBack() {
+        return lookBack;
+    }
+
+    public ConcurrentLinkedQueue<MakeEvent> getMakeObjectLog() {
+        return makeObjectLog;
+    }
+
+    public Instant getDownStart() {
+        return downStart;
+    }
+
+    public Instant getUpStart() {
+        return upStart;
+    }
+
+    public ConcurrentHashMap<Class, Integer> getExceptionCounts() {
+        return exceptionCounts;
+    }
+
+    public Duration getDelay() {
+        return delay;
+    }
+
+    public Duration getTimeBetweenChecks() {
+        return timeBetweenChecks;
+    }
+
 }
diff --git 
a/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
 
b/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
index 29b03665..3d3cc371 100644
--- 
a/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
+++ 
b/src/test/java/org/apache/commons/pool3/impl/TestResilientPooledObjectFactory.java
@@ -220,8 +220,6 @@ public class TestResilientPooledObjectFactory {
                 try {
                     final String s = pool.borrowObject();
                 } catch (Exception e) {
-                } finally {
-                    System.out.println("Borrower done");
                 }
             }
         }.start();
@@ -271,6 +269,45 @@ public class TestResilientPooledObjectFactory {
         assertFalse(rf.isAdderRunning());
     }
 
+    @Test
+    public void testIsMonitorRunning() throws Exception {
+        FailingFactory ff = new FailingFactory();
+        // Make the factory fail with exception immmmediately on make
+        ff.setSilentFail(true);
+        ResilientPooledObjectFactory<String, Exception> rf = new 
ResilientPooledObjectFactory<String, Exception>(ff,
+                5, Duration.ofMillis(200), Duration.ofMinutes(10), 
Duration.ofMillis(20));
+        GenericObjectPool<String, Exception> pool = new 
GenericObjectPool<>(rf);
+        rf.setPool(pool);
+        rf.startMonitor();
+        assertTrue(rf.isMonitorRunning());
+        rf.stopMonitor();
+        assertFalse(rf.isMonitorRunning());
+        rf.startMonitor();
+        pool.close();
+        // Wait for monitor to run so it can kill itself
+        try {
+            Thread.sleep(200);
+        } catch (InterruptedException e) {
+        }
+        assertFalse(rf.isMonitorRunning());
+    }
+
+    @Test
+    public void testConstructorWithDefaults() {
+        FailingFactory ff = new FailingFactory();
+        ResilientPooledObjectFactory<String, Exception> rf = new 
ResilientPooledObjectFactory<String, Exception>(ff);
+        assertFalse(rf.isMonitorRunning());
+        assertFalse(rf.isAdderRunning());
+        assertEquals(ResilientPooledObjectFactory.getDefaultLogSize(), 
rf.getLogSize());
+        
assertEquals(ResilientPooledObjectFactory.getDefaultTimeBetweenChecks(), 
rf.getTimeBetweenChecks());
+        assertEquals(ResilientPooledObjectFactory.getDefaultDelay(), 
rf.getDelay());
+        assertEquals(ResilientPooledObjectFactory.getDefaultLookBack(), 
rf.getLookBack());
+        assertEquals(0, rf.getMakeObjectLog().size());
+        rf.setLogSize(5);
+        assertEquals(5, rf.getLogSize());
+        rf.setTimeBetweenChecks(Duration.ofMillis(200));
+    }
+
     /**
      * Factory that suffers outages and fails in configurable ways when it is 
down.
      */

Reply via email to