db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r987678 - in /db/derby/code/branches/10.6: ./ java/client/org/apache/derby/client/net/ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Sat, 21 Aug 2010 00:33:44 GMT
Author: kmarsden
Date: Sat Aug 21 00:33:44 2010
New Revision: 987678

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


Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/client/org/apache/derby/client/net/NetConnection.java
    db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
    db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Aug 21 00:33:44 2010
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,958163,958522,958555,958618,958939,959550,962716,963206,963705,964115,965647,967304,980684
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,958163,958522,958555,958618,958939,959550,962716,963206,963705,964115,965647,967304,980684,986689,986834
 /db/derby/docs/trunk:954344

Modified: db/derby/code/branches/10.6/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/client/org/apache/derby/client/net/NetConnection.java?rev=987678&r1=987677&r2=987678&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/client/org/apache/derby/client/net/NetConnection.java
(original)
+++ db/derby/code/branches/10.6/java/client/org/apache/derby/client/net/NetConnection.java
Sat Aug 21 00:33:44 2010
@@ -218,6 +218,8 @@ public class NetConnection extends org.a
         flowConnect(password, securityMechanism_);
         if(!isConnectionNull())
         	completeConnect();
+        //DERBY-2026. reset timeout after connection is made
+        netAgent_.setTimeout(0);
     }
 
     // For JDBC 2 Connections
@@ -304,14 +306,19 @@ public class NetConnection extends org.a
         // (which the InternalDriver assumes means there's a subsubprotocol)  
         // and it's not a subsubprotocol recognized by our drivers.
         // If so, bail out here.
-        if(!isConnectionNull())
+        if(!isConnectionNull()) {
             completeConnect();
+        }
         else
         {
             agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
                     new ClientMessageId(SQLState.PROPERTY_INVALID_VALUE),
                     Attribute.DBNAME_ATTR,databaseName_));
         }
+        // DERBY-2026
+        //reset timeout if previously set for login timeout
+        netAgent_.setTimeout(0);
+        
     }
 
     // preferably without password in the method signature.
@@ -339,6 +346,9 @@ public class NetConnection extends org.a
         boolean isDeferredReset = flowReconnect(getDeferredResetPassword(),
                                                 securityMechanism_);
         completeReset(isDeferredReset);
+        //DERBY-2026. Make sure soTimeout is set back to
+        // infinite after connection is made.
+        netAgent_.setTimeout(0);
     }
 
 

Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=987678&r1=987677&r2=987678&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
(original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Sat Aug 21 00:33:44 2010
@@ -55,6 +55,7 @@ import org.apache.derby.jdbc.ClientConne
 import org.apache.derby.jdbc.ClientXADataSource;
 import org.apache.derby.jdbc.EmbeddedSimpleDataSource;
 import org.apache.derbyTesting.functionTests.util.SecurityCheck;
+import org.apache.derbyTesting.functionTests.util.TestRoutines;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
@@ -170,6 +171,7 @@ public class J2EEDataSourceTest extends 
         suite.addTest(new J2EEDataSourceTest("testClientDSConnectionAttributes"));
         suite.addTest(new J2EEDataSourceTest(
                 "testClientTraceFileDSConnectionAttribute"));
+        suite.addTest(new J2EEDataSourceTest("testDerby2026LoginTimeout"));
         //DISABLED until DERBY-4067 is fixed.
         //suite.addTest(new J2EEDataSourceTest(
         //        "testClientMessageTextConnectionAttribute"));
@@ -229,6 +231,7 @@ public class J2EEDataSourceTest extends 
                  * @see org.apache.derbyTesting.junit.CleanDatabaseTestSetup#decorateSQL(java.sql.Statement)
                  */
                 protected void decorateSQL(Statement s) throws SQLException {
+                    TestRoutines.installRoutines(getConnection());
                     s.executeUpdate("create table autocommitxastart(i int)");
                     s.executeUpdate("insert into autocommitxastart values 1,2,3,4,5");
                     s.executeUpdate("create schema SCHEMA_Patricio");
@@ -2059,6 +2062,75 @@ public class J2EEDataSourceTest extends 
         pc.close();
     }
 
+
+    /**
+     * DERBY-2026 - Make sure login timeout does not impact 
+     * queries.
+     */
+    public void testDerby2026LoginTimeout() throws SQLException {
+        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);
+        }
+    }
+
     // test that an xastart in auto commit mode commits the existing work.
     // test fix of a bug ('beetle 5178') wherein XAresource.start() when 
     // auto-commit is true did not implictly commit any transaction

Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java?rev=987678&r1=987677&r2=987678&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
(original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
Sat Aug 21 00:33:44 2010
@@ -21,6 +21,7 @@
 */
 package org.apache.derbyTesting.functionTests.tests.lang;
 
+import java.sql.CallableStatement;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
@@ -29,7 +30,9 @@ import java.sql.Statement;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.derbyTesting.functionTests.util.TestRoutines;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -48,8 +51,15 @@ public class ConnectTest extends BaseJDB
             // is not supported with JSR169
             return 
             new TestSuite("empty ConnectTest:DriverManager not supported");
-        else
-            return TestConfiguration.defaultSuite(ConnectTest.class);
+        else  {
+                TestSuite suite = new TestSuite("ConnectTest suite");  
+                suite.addTest(TestConfiguration.defaultSuite(ConnectTest.class));
+                // Derby2026 test uses explicit client connection so not relevant to embedded
+                suite.addTest(TestConfiguration.
+                            clientServerDecorator(new ConnectTest("clientTestDerby2026LoginTimeout")));
+                return new CleanDatabaseTestSetup(suite);
+        }
+                  
     }
 
     /**
@@ -137,4 +147,32 @@ public class ConnectTest extends BaseJDB
         st.close();
         con.close();
     }
-}
+
+    /**
+     * DERBY-2026 make sure loginTimeout does not
+     * affect queries
+     * @throws SQLException
+     */
+    public void clientTestDerby2026LoginTimeout() throws SQLException  {
+        String url = "jdbc:derby://" + TestConfiguration.getCurrent().getHostName() +":"
+
+        TestConfiguration.getCurrent().getPort() + "/" + TestConfiguration.getCurrent().getDefaultDatabaseName();
+        try {
+            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);
+        }
+    }   
+    
+}
\ No newline at end of file



Mime
View raw message