db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r986689 - in /db/derby/code/trunk/java: client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Wed, 18 Aug 2010 14:11:40 GMT
Author: kmarsden
Date: Wed Aug 18 14:11:39 2010
New Revision: 986689

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


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
    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/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java?rev=986689&r1=986688&r2=986689&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java Wed Aug
18 14:11:39 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/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=986689&r1=986688&r2=986689&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 14:11:39 2010
@@ -59,6 +59,7 @@ import org.apache.derby.jdbc.ClientXADat
 import org.apache.derby.jdbc.EmbeddedSimpleDataSource;
 import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
 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;
@@ -180,6 +181,7 @@ public class J2EEDataSourceTest extends 
                 "testClientMessageTextConnectionAttribute"));
         suite.addTest(new J2EEDataSourceTest("testConnectionFlowCommit"));
         suite.addTest(new J2EEDataSourceTest("testConnectionFlowCommitAlt"));
+        suite.addTest(new J2EEDataSourceTest("testDerby2026LoginTimeout"));
         // Disabled because rollback flow optimization hasn't been implemented.
         // See DERBY-4687
         //suite.addTest(new J2EEDataSourceTest("testConnectionFlowRollbackAlt"));
@@ -239,6 +241,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");
@@ -2109,6 +2112,58 @@ public class J2EEDataSourceTest extends 
     }
 
     /**
+     * DERBY-2026 - Make sure login timeout does not impact 
+     * 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();
+        
+    }
+    
+    /**
      * Doing the work for test Connection.flowcommit() and Connection.flowrollback()
      * @param conn
      * @throws SQLException

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=986689&r1=986688&r2=986689&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 14:11:39 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,28 @@ 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();
+        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();
+    }
+    
+}
\ No newline at end of file



Mime
View raw message