commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r894641 - /commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
Date Wed, 30 Dec 2009 15:08:09 GMT
Author: sebb
Date: Wed Dec 30 15:08:09 2009
New Revision: 894641

URL: http://svn.apache.org/viewvc?rev=894641&view=rev
Log:
Fix multi-threading (data visibility) bugs in PoolTest nested class
Show details of Exception if it is not excepted
Improve failure message

Modified:
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java?rev=894641&r1=894640&r2=894641&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
Wed Dec 30 15:08:09 2009
@@ -373,11 +373,11 @@
     }
     
     public void testMultipleThreads() throws Exception {
-        assertTrue(multipleThreads(1));
-        assertTrue(!multipleThreads(2 * (int)(getMaxWait())));
+        assertTrue("Expected multiple threads to succeed with timeout=1",multipleThreads(1,
false));
+        assertTrue("Expected multiple threads to fail with timeout=2*maxWait",!multipleThreads(2
* (int)(getMaxWait()), true));
     }
 
-    private boolean multipleThreads(int holdTime) throws Exception {
+    private boolean multipleThreads(final int holdTime,final boolean expectError) throws
Exception {
         long startTime = System.currentTimeMillis();
         final boolean[] success = new boolean[1];
         success[0] = true;
@@ -394,7 +394,7 @@
                     pts[i].stop();
                 }
 
-                //e.printStackTrace();
+                if (!expectError) e.printStackTrace();
                 success[0] = false;
             }
         };
@@ -420,11 +420,11 @@
         /**
          * The number of milliseconds to hold onto a database connection
          */
-        private int connHoldTime;
+        private final int connHoldTime;
 
-        private boolean isRun;
+        private volatile boolean isRun;
 
-        private String state;
+        private volatile String state;
 
         protected PoolTest(ThreadGroup threadGroup, int connHoldTime) {
             this.connHoldTime = connHoldTime;
@@ -458,7 +458,7 @@
                 } catch (RuntimeException e) {
                     throw e;
                 } catch (Exception e) {
-                    throw new RuntimeException(e.toString());
+                    throw (RuntimeException) new RuntimeException(e.toString()).initCause(e);
                 }
             }
         }



Mime
View raw message