db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r1336349 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit: CleanDatabaseTestSetup.java DatabasePropertyTestSetup.java
Date Wed, 09 May 2012 18:49:41 GMT
Author: myrnavl
Date: Wed May  9 18:49:41 2012
New Revision: 1336349

URL: http://svn.apache.org/viewvc?rev=1336349&view=rev
Log:
DERBY-5686; multiple intermittent errors in nightly tests during DriverMgrAuthenticationTest
test. reason: An SQL data change is not permitted for a read-only connection, user or database.

  updating retry logic in DatabasePropertyTestSetup
  also adding code to CleanDatabaseTestSetup to catch any test leaving a
  connection in read-only mode and making it fail.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java?rev=1336349&r1=1336348&r2=1336349&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
Wed May  9 18:49:41 2012
@@ -150,7 +150,17 @@ public class CleanDatabaseTestSetup exte
      */
     protected void tearDown() throws Exception {
         Connection conn = getConnection();
+        // See DERBY-5686 - perhaps there's a test that leaves a 
+        // connection in read-only state - let's check here and 
+        // if there's a conn that's read-only, unset it, and make
+        // the test fail so we find it.
         conn.setAutoCommit(false);
+        boolean ok=true;
+        if (conn.isReadOnly())
+        {
+            conn.setReadOnly(false);
+            ok=false;
+        }
         
         // Clean the database, ensures that any failure dropping
         // objects can easily be linked to test fixtures that
@@ -162,6 +172,8 @@ public class CleanDatabaseTestSetup exte
         // Compress is a somewhat expensive operation so avoid it if possible.
         CleanDatabaseTestSetup.cleanDatabase(conn, false);       
         super.tearDown();
+        if (!ok)
+            fail("the test that was just run left the conn read-only");
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java?rev=1336349&r1=1336348&r2=1336349&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
Wed May  9 18:49:41 2012
@@ -300,7 +300,19 @@ public class DatabasePropertyTestSetup e
                 System.out.println("conn.getAutoCommit: " + conn.getAutoCommit());
                 // now try to close the connection, then try open a new one, 
                 // and try to executeUpdate again.
-                conn.close();
+                try {
+                    conn.close();
+                } catch (SQLException isqle) {
+                    if (sqle.getSQLState()=="25001")
+                    {
+                        // the transaction is still active. let's commit what we have.
+                        conn.commit();
+                        conn.close();
+                    } else {
+                        System.out.println("close failed - see SQLState.");
+                        throw sqle;
+                    }
+                }
                 Connection conn2 = getConnection();
                 // check if this second connection is read-only
                 if (conn2.isReadOnly())
@@ -369,8 +381,21 @@ public class DatabasePropertyTestSetup e
                 System.out.println("conn.getAutoCommit: " + conn.getAutoCommit());
                 // now try to close the connection, then try open a new one, 
                 // and try to executeUpdate again.
-                conn.close();
+                try {
+                    conn.close();
+                } catch (SQLException isqle) {
+                    if (sqle.getSQLState()=="25001")
+                    {
+                        // the transaction is still active. let's commit what we have.
+                        conn.commit();
+                        conn.close();
+                    } else {
+                        System.out.println("close failed - see SQLState.");
+                        throw sqle;
+                    }
+                }
                 Connection conn2 = getConnection();
+
                 // check if this second connection is read-only
                 if (conn2.isReadOnly())
                 {



Mime
View raw message