db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r986834 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests: jdbcapi/J2EEDataSourceTest.java lang/ConnectTest.java
Date Wed, 18 Aug 2010 18:21:29 GMT
Author: kmarsden
Date: Wed Aug 18 18:21:29 2010
New Revision: 986834

URL: http://svn.apache.org/viewvc?rev=986834&view=rev
Log:
DERBY-2026 Setting a login timeout in client driver can lead to query timeout

Change tests to set loginTimeout to 0 after test completes, so later tests won't be impacted.


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=986834&r1=986833&r2=986834&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Wed Aug 18 18:21:29 2010
@@ -2116,51 +2116,67 @@ public class J2EEDataSourceTest extends 
      * queries.
      */
     public void testDerby2026LoginTimeout() throws SQLException {
-        DataSource jds = JDBCDataSource.getDataSource();
-        jds.setLoginTimeout(10);
-        Connection conn = jds.getConnection();
-        CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
-        cs.execute();
-        //rollback to make sure our connection is ok.
-        conn.rollback();
-        
-        ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();   
    
-        cpds.setLoginTimeout(10);
-        PooledConnection pc = cpds.getPooledConnection();
-        conn = pc.getConnection();
-        cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
-        cs.execute();
-        //rollback to make sure our connection is ok.
-        conn.rollback();
-        
-        // Close the logical connection and get a new one.
-        // This will invoke reset which also needs its timeout reset
-        conn.close();
-        conn = pc.getConnection();
-        cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
-        cs.execute();
-        //rollback to make sure our connection is ok.
-        conn.rollback();
-        
-        
-        XADataSource xads = J2EEDataSource.getXADataSource();        
-        xads.setLoginTimeout(10);
-        XAConnection xac = xads.getXAConnection();
-        conn = pc.getConnection();
-        cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
-        cs.execute();
-        //rollback to make sure our connection is ok.
-        conn.rollback();
-        
-        // Close the logical connection and get a new one.
-        // This will invoke reset which also needs its timeout reset
-        conn.close();
-        conn = pc.getConnection();
-        cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
-        cs.execute();
-        //rollback to make sure our connection is ok.
-        conn.rollback();
-        
+        DataSource jds = null;
+        try {
+            jds = JDBCDataSource.getDataSource();
+            jds.setLoginTimeout(10);
+            Connection conn = jds.getConnection();
+            CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
+            cs.execute();
+            //rollback to make sure our connection is ok.
+            conn.rollback();
+        } finally {
+            if (jds != null)
+                jds.setLoginTimeout(0);
+        }
+
+        ConnectionPoolDataSource cpds = null;
+        try {
+            cpds = J2EEDataSource.getConnectionPoolDataSource();        
+            cpds.setLoginTimeout(10);
+            PooledConnection pc = cpds.getPooledConnection();
+            Connection conn = pc.getConnection();
+            CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
+            cs.execute();
+            //rollback to make sure our connection is ok.
+            conn.rollback();
+
+            // Close the logical connection and get a new one.
+            // This will invoke reset which also needs its timeout reset
+            conn.close();
+            conn = pc.getConnection();
+            cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
+            cs.execute();
+            //rollback to make sure our connection is ok.
+            conn.rollback();
+        } finally {
+            if (cpds != null)
+                cpds.setLoginTimeout(0);
+        }
+
+        XADataSource xads = null;
+        try {
+            xads = J2EEDataSource.getXADataSource();        
+            xads.setLoginTimeout(10);
+            XAConnection xac = xads.getXAConnection();
+            Connection conn = xac.getConnection();
+            CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
+            cs.execute();
+            //rollback to make sure our connection is ok.
+            conn.rollback();
+
+            // Close the logical connection and get a new one.
+            // This will invoke reset which also needs its timeout reset
+            conn.close();
+            conn = xac.getConnection();
+            cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
+            cs.execute();
+            //rollback to make sure our connection is ok.
+            conn.rollback();
+        } finally {
+            if (xads != null)
+                xads.setLoginTimeout(0);
+        }
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java?rev=986834&r1=986833&r2=986834&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
Wed Aug 18 18:21:29 2010
@@ -156,19 +156,23 @@ public class ConnectTest extends BaseJDB
     public void clientTestDerby2026LoginTimeout() throws SQLException  {
         String url = "jdbc:derby://" + TestConfiguration.getCurrent().getHostName() +":"
+
         TestConfiguration.getCurrent().getPort() + "/" + TestConfiguration.getCurrent().getDefaultDatabaseName();
-        DriverManager.setLoginTimeout(10);
-        //System.out.println(url);
         try {
-            Class.forName("org.apache.derby.jdbc.ClientDriver");
-        } catch (ClassNotFoundException e) {
-            fail(e.getMessage());
+            DriverManager.setLoginTimeout(10);
+            //System.out.println(url);
+            try {
+                Class.forName("org.apache.derby.jdbc.ClientDriver");
+            } catch (ClassNotFoundException e) {
+                fail(e.getMessage());
+            }
+            Connection conn = DriverManager.getConnection(url);
+            TestRoutines.installRoutines(conn);
+            CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
+            cs.execute();
+            //rollback to make sure our connection is ok.
+            conn.rollback();
+        } finally {
+            DriverManager.setLoginTimeout(0);
         }
-        Connection conn = DriverManager.getConnection(url);
-        TestRoutines.installRoutines(conn);
-        CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
-        cs.execute();
-        //rollback to make sure our connection is ok.
-        conn.rollback();
-    }
+    }   
     
 }
\ No newline at end of file



Mime
View raw message