You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/12/30 16:08:09 UTC

svn commit: r894641 - /commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java

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);
                 }
             }
         }



Re: svn commit: r894641 - /commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java

Posted by sebb <se...@gmail.com>.
On 30/12/2009, Phil Steitz <ph...@gmail.com> wrote:
> sebb@apache.org wrote:
>  > 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

[...]

> After this change, you see no failures?  Thanks.

Unfortunately not - I still see the same occasional failures

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r894641 - /commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java

Posted by Phil Steitz <ph...@gmail.com>.
sebb@apache.org wrote:
> 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;

After this change, you see no failures?  Thanks.

>  
>          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);
>                  }
>              }
>          }
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org