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 km...@apache.org on 2010/08/21 19:12:58 UTC
svn commit: r987794 - in /db/derby/code/branches/10.5: ./
java/client/org/apache/derby/client/net/
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
java/testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: kmarsden
Date: Sat Aug 21 17:12:58 2010
New Revision: 987794
URL: http://svn.apache.org/viewvc?rev=987794&view=rev
Log:
DERBY-2026
Setting a login timeout in client driver can lead to query timeout
Modified:
db/derby/code/branches/10.5/ (props changed)
db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetConnection.java
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Aug 21 17:12:58 2010
@@ -1,2 +1,2 @@
-/db/derby/code/branches/10.6:942027,957000,962738,965351
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915733,916075,916897,918152,918359,921028,927430,928065,929085,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716,965647,967304,980684
+/db/derby/code/branches/10.6:942027,957000,962738,965351,987678
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915733,916075,916897,918152,918359,921028,927430,928065,929085,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716,965647,967304,980684,986689,986834
Modified: db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetConnection.java?rev=987794&r1=987793&r2=987794&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/branches/10.5/java/client/org/apache/derby/client/net/NetConnection.java Sat Aug 21 17:12:58 2010
@@ -219,6 +219,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
@@ -305,14 +307,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.
@@ -340,6 +347,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.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=987794&r1=987793&r2=987794&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java Sat Aug 21 17:12:58 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");
@@ -2032,6 +2035,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.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java?rev=987794&r1=987793&r2=987794&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java Sat Aug 21 17:12:58 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