From: Date: September 14 2006 7:40pm Subject: Connector/J commit: r5730 - in branches/branch_5_0/connector-j: . src/com/mysql/jdbc src/testsuite/regression src/testsuite/simple List-Archive: http://lists.mysql.com/commits/11954 X-Bug: 22359 Message-Id: <200609141740.k8EHeBoG015357@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java branches/branch_5_0/connector-j/src/testsuite/simple/StatementsTest.java Log: Fixed BUG#22359 - Driver was using milliseconds for Statement.setQueryTimeout() when specification says argument is to be in seconds. Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2006-09-14 00:01:06 UTC (rev 5729) +++ branches/branch_5_0/connector-j/CHANGES 2006-09-14 17:40:09 UTC (rev 5730) @@ -25,6 +25,10 @@ - Driver now supports {call sp} (without "()" if procedure has no arguments). + - Fixed BUG#22359 - Driver was using milliseconds for + Statement.setQueryTimeout() when specification says argument is + to be in seconds. + 07-26-06 - Version 5.0.3 - Fixed BUG#20650 - Statement.cancel() causes NullPointerException Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-09-14 00:01:06 UTC (rev 5729) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-09-14 17:40:09 UTC (rev 5730) @@ -1143,11 +1143,11 @@ CancelTask timeoutTask = null; try { - if (this.timeout != 0 + if (this.timeoutInMillis != 0 && locallyScopedConnection.versionMeetsMinimum(5, 0, 0)) { timeoutTask = new CancelTask(); Connection.getCancelTimer().schedule(timeoutTask, - this.timeout); + this.timeoutInMillis); } rs = locallyScopedConnection.execSQL(this, null, maxRowsToRetrieve, sendPacket, Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-09-14 00:01:06 UTC (rev 5729) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-09-14 17:40:09 UTC (rev 5730) @@ -1155,11 +1155,11 @@ CancelTask timeoutTask = null; try { - if (this.timeout != 0 + if (this.timeoutInMillis != 0 && this.connection.versionMeetsMinimum(5, 0, 0)) { timeoutTask = new CancelTask(); this.connection.getCancelTimer().schedule(timeoutTask, - this.timeout); + this.timeoutInMillis); } Buffer resultPacket = mysql.sendCommand(MysqlDefs.COM_EXECUTE, Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java 2006-09-14 00:01:06 UTC (rev 5729) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java 2006-09-14 17:40:09 UTC (rev 5730) @@ -215,7 +215,7 @@ protected int statementId; /** The timeout for a query */ - protected int timeout = 0; + protected int timeoutInMillis = 0; /** The update count for this statement */ protected long updateCount = -1; @@ -617,11 +617,11 @@ CancelTask timeoutTask = null; try { - if (this.timeout != 0 + if (this.timeoutInMillis != 0 && locallyScopedConn.versionMeetsMinimum(5, 0, 0)) { timeoutTask = new CancelTask(); Connection.getCancelTimer().schedule(timeoutTask, - this.timeout); + this.timeoutInMillis); } String oldCatalog = null; @@ -1098,11 +1098,11 @@ CancelTask timeoutTask = null; try { - if (this.timeout != 0 + if (this.timeoutInMillis != 0 && locallyScopedConn.versionMeetsMinimum(5, 0, 0)) { timeoutTask = new CancelTask(); Connection.getCancelTimer().schedule(timeoutTask, - this.timeout); + this.timeoutInMillis); } String oldCatalog = null; @@ -1284,11 +1284,11 @@ CancelTask timeoutTask = null; try { - if (this.timeout != 0 + if (this.timeoutInMillis != 0 && locallyScopedConn.versionMeetsMinimum(5, 0, 0)) { timeoutTask = new CancelTask(); Connection.getCancelTimer().schedule(timeoutTask, - this.timeout); + this.timeoutInMillis); } String oldCatalog = null; @@ -1747,7 +1747,7 @@ * if a database access error occurs */ public int getQueryTimeout() throws SQLException { - return this.timeout; + return this.timeoutInMillis / 1000; } /** @@ -2231,7 +2231,7 @@ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } - this.timeout = seconds; + this.timeoutInMillis = seconds * 1000; } /** Modified: branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-09-14 00:01:06 UTC (rev 5729) +++ branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2006-09-14 17:40:09 UTC (rev 5730) @@ -60,6 +60,7 @@ import com.mysql.jdbc.SQLError; import com.mysql.jdbc.ServerPreparedStatement; +import com.mysql.jdbc.exceptions.MySQLTimeoutException; /** * Regression tests for the Statement class @@ -3398,4 +3399,36 @@ closeMemberJDBCResources(); } } + + /** + * Tests fix for BUG#22359 - Driver was using millis for + * Statement.setQueryTimeout() when spec says argument is + * seconds. + * + * @throws Exception if the test fails. + */ + public void testBug22359() throws Exception { + if (versionMeetsMinimum(5, 0)) { + Statement timeoutStmt = null; + + try { + timeoutStmt = this.conn.createStatement(); + timeoutStmt.setQueryTimeout(2); + + long begin = System.currentTimeMillis(); + + try { + timeoutStmt.execute("SELECT SLEEP(30)"); + } catch (MySQLTimeoutException timeoutEx) { + long end = System.currentTimeMillis(); + + assertTrue((end - begin) > 1000); + } + } finally { + if (timeoutStmt != null) { + timeoutStmt.close(); + } + } + } + } } Modified: branches/branch_5_0/connector-j/src/testsuite/simple/StatementsTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/simple/StatementsTest.java 2006-09-14 00:01:06 UTC (rev 5729) +++ branches/branch_5_0/connector-j/src/testsuite/simple/StatementsTest.java 2006-09-14 17:40:09 UTC (rev 5730) @@ -533,7 +533,7 @@ cancelConn = getConnectionWithProps(null); final Statement cancelStmt = cancelConn.createStatement(); - cancelStmt.setQueryTimeout(10); + cancelStmt.setQueryTimeout(1); long begin = System.currentTimeMillis(); @@ -592,7 +592,7 @@ final PreparedStatement cancelPstmt = cancelConn.prepareStatement("SELECT SLEEP(30)"); - cancelPstmt.setQueryTimeout(10); + cancelPstmt.setQueryTimeout(1); begin = System.currentTimeMillis(); @@ -651,7 +651,7 @@ final PreparedStatement cancelClientPstmt = ((com.mysql.jdbc.Connection)cancelConn).clientPrepareStatement("SELECT SLEEP(30)"); - cancelClientPstmt.setQueryTimeout(10); + cancelClientPstmt.setQueryTimeout(1); begin = System.currentTimeMillis();