commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1692943 - in /commons/proper/pool/trunk/src: changes/changes.xml main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
Date Mon, 27 Jul 2015 20:21:39 GMT
Author: psteitz
Date: Mon Jul 27 20:21:38 2015
New Revision: 1692943

URL: http://svn.apache.org/r1692943
Log:
Added PrintWriter flush to DefaultPooledObject's printStackTrace method. JIRA: POOL-300.

Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1692943&r1=1692942&r2=1692943&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Mon Jul 27 20:21:38 2015
@@ -43,7 +43,10 @@ The <action> type attribute can be add,u
     <title>Apache Commons Pool Changes</title>
   </properties>
   <body>
-  <release version="2.5" date="TBD" description="TBD">
+  <release version="2.4.2" date="TBD" description="TBD">
+    <action dev="psteitz" issue="POOL-300" type="fix">
+      Added PrintWriter flush to DefaultPooledObject's printStackTrace method.
+    </action>
   </release>
   <release version="2.4.1" date="2015-05-30" description=
  "This is a patch release, replacing a defective binary jar in version 2.4. Other

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java?rev=1692943&r1=1692942&r2=1692943&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java
(original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java
Mon Jul 27 20:21:38 2015
@@ -243,13 +243,19 @@ public class DefaultPooledObject<T> impl
 
     @Override
     public void printStackTrace(PrintWriter writer) {
+        boolean written = false;
         Exception borrowedByCopy = this.borrowedBy;
         if (borrowedByCopy != null) {
             borrowedByCopy.printStackTrace(writer);
+            written = true;
         }
         Exception usedByCopy = this.usedBy;
         if (usedByCopy != null) {
             usedByCopy.printStackTrace(writer);
+            written = true;
+        }
+        if (written) {
+            writer.flush();
         }
     }
 

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java?rev=1692943&r1=1692942&r2=1692943&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java
Mon Jul 27 20:21:38 2015
@@ -17,6 +17,9 @@
 
 package org.apache.commons.pool2.impl;
 
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
 import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Set;
@@ -261,6 +264,25 @@ public class TestAbandonedObjectPool {
 
         Assert.assertTrue (end - start < 5000);
     }
+    
+    /**
+     * JIRA: POOL-300
+     */
+    @Test
+    public void testStackTrace() throws Exception {
+        abandonedConfig.setRemoveAbandonedOnMaintenance(true);
+        abandonedConfig.setLogAbandoned(true);
+        abandonedConfig.setRemoveAbandonedTimeout(1);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        PrintWriter pw = new PrintWriter(new BufferedOutputStream(baos));
+        abandonedConfig.setLogWriter(pw);
+        pool.setAbandonedConfig(abandonedConfig);
+        pool.setTimeBetweenEvictionRunsMillis(100);
+        PooledTestObject o1 = pool.borrowObject();
+        Thread.sleep(2000);
+        Assert.assertTrue(o1.isDestroyed());
+        Assert.assertTrue(baos.toString().indexOf("Pooled object") >= 0);
+    }
 
     class ConcurrentBorrower extends Thread {
         private final ArrayList<PooledTestObject> _borrowed;



Mime
View raw message