You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by my...@apache.org on 2012/09/06 21:45:38 UTC

svn commit: r1381731 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/

Author: myrnavl
Date: Thu Sep  6 19:45:37 2012
New Revision: 1381731

URL: http://svn.apache.org/viewvc?rev=1381731&view=rev
Log:
DERBY-5912; testIsValidImplemented fails for NetworkServer in some slow running machines/configurations
  This commits the following changes:
  - changes the timeout in ConnectionMethodsTest from isValid(1) to isValid(200) and adds a comment
  - updates the comment in ConnectionTest so it refers to ConnectionMethodsTest
  - has commented out sleep code in DRDAConnThread that can be uncommented to test this
  - adds a fixture, testIsValidWithTimeout, that is disabled by having an 'x' in front of it, to ConnectionTest. 

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1381731&r1=1381730&r2=1381731&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Thu Sep  6 19:45:37 2012
@@ -827,6 +827,13 @@ class DRDAConnThread extends Thread {
                     break;
                 case CodePoint.OPNQRY:
                     try {
+                        // activate the following to run the isValid(timeout) test in jdbc4.ConnectionTest
+                        /*try { 
+                            Thread.sleep(2000);
+                        } catch (InterruptedException ie) {
+                            System.out.println("interrupted exception: " + ie.getMessage());
+                            ie.printStackTrace();
+                        }*/
                         if (PRPSQLSTTfailed) {
                             // read the command objects
                             // for ps with parameter

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java?rev=1381731&r1=1381730&r2=1381731&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java Thu Sep  6 19:45:37 2012
@@ -322,10 +322,12 @@ public class ConnectionMethodsTest exten
         }
 
        /*
-        * Test with a valid timeout
+        * Test with a valid timeout.
+        * The value is set very large; we expect
+        * to complete and succeed much sooner. See DERBY-5912
         */
-        if (!conn.isValid(1)) {
-            fail("FAIL: isValid(1): returned false");
+        if (!conn.isValid(200)) {
+            fail("FAIL: isValid(200): returned false");
         }
 
        /*

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java?rev=1381731&r1=1381730&r2=1381731&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionTest.java Thu Sep  6 19:45:37 2012
@@ -157,7 +157,7 @@ public class ConnectionTest
      * Tests that <code>isValid</code> is implemented and returns true
      * for the connection. This test is very limited but is tested
      * for all connection types. A more complete test of isValid is
-     * found in the TestConnectionMethods.java test that is run for
+     * found in the ConnectionMethodsTest.java test that is run for
      * embedded and network client connections.
      */
     public void testIsValidImplemented() throws SQLException {
@@ -177,6 +177,44 @@ public class ConnectionTest
                            "XJ081", sqle);
         }
     }
+    
+    /**
+     * Tests that <code>isValid</code> times out when expected.
+     * This test will need a modification to the source code;
+     * activate the commented out Thread.sleep(2000) (2 seconds) in 
+     * DRDAConnThread.ProcessCommands, case CodePoint.OPNQRY
+     * To activate the test, remove the extra 'x' before building
+     */
+    public void xtestIsValidWithTimeout() throws SQLException {
+        // isValid(timeoutvalue) is a no-op in Embedded
+        if (usingEmbedded()) {
+            return;
+        }
+        // Test with a large timeout, see DERBY-5912.
+        boolean convalid=true;
+        Connection conn=getConnection();
+
+        // with a longer time out, the isValid call should not
+        // time out when the sleep is shorter.
+        convalid=conn.isValid(200);
+        assertTrue(convalid);
+
+        // setting the timeout to 1 should timeout if the sleep
+        // is 2 seconds.
+        convalid=conn.isValid(1);
+        assertFalse(convalid);
+
+        // rollback should work even though isvalid timed out...
+        // But there's a bug in that the connection becomes invalid and
+        // it is not getting re-established, see DERBY-5919. 
+        // Catch the exception saying No current Connection and swallow.
+        try {
+            conn.rollback();
+            //conn.close();
+        } catch (Exception e) {
+            //println("exception: " + e.getStackTrace());
+        }
+    }
 
     /**
      * Tests that <code>getTypeMap()</code> returns an empty map when