db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r432029 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Wed, 16 Aug 2006 20:43:34 GMT
Author: kahatlen
Date: Wed Aug 16 13:43:34 2006
New Revision: 432029

URL: http://svn.apache.org/viewvc?rev=432029&view=rev
Log:
DERBY-1692: Client driver does not use the query timeout value set
using Statement.setQueryTimeout() for subsequent executions using the
same statement object

Make Statement resend the timeout value for each execution, and extend
SetQueryTimeoutTest with test cases for re-execution of Statement,
PreparedStatement and CallableStatement.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/SetQueryTimeoutTest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SetQueryTimeoutTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=432029&r1=432028&r2=432029&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Wed Aug 16 13:43:34
2006
@@ -1866,10 +1866,14 @@
             Section newSection = null;
             boolean repositionedCursor = false;
 
-            if (doWriteTimeout) {
+            // DERBY-1692: Statement objects need to send the timeout value for
+            // each execution since the server will create a new statement
+            // object each time. Since the server forgets the timeout value,
+            // doWriteTimeout should not be reset, and it is OK not to send the
+            // timeout value when it is zero.
+            if (doWriteTimeout && (timeout_ > 0)) {
                 timeoutArrayList.set(0, TIMEOUT_STATEMENT + timeout_);
                 writeSetSpecialRegister(timeoutArrayList);
-                doWriteTimeout = false;
                 timeoutSent = true;
             }
             switch (sqlMode_) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/SetQueryTimeoutTest.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/SetQueryTimeoutTest.out?rev=432029&r1=432028&r2=432029&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/SetQueryTimeoutTest.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/SetQueryTimeoutTest.out
Wed Aug 16 13:43:34 2006
@@ -12,5 +12,8 @@
 Testing setting a negative timeout value
 Negative timeout value caused exception, as expected
 Execute returned a ResultSet
+Testing that Statement remembers timeout.
+Testing that PreparedStatement remembers timeout.
+Testing that CallableStatement remembers timeout.
 Test SetQueryTimeoutTest PASSED
 Closed connections

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SetQueryTimeoutTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SetQueryTimeoutTest.java?rev=432029&r1=432028&r2=432029&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SetQueryTimeoutTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SetQueryTimeoutTest.java
Wed Aug 16 13:43:34 2006
@@ -21,6 +21,7 @@
 
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 
+import java.sql.CallableStatement;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -32,12 +33,11 @@
 import java.util.Collections;
 
 import org.apache.derby.tools.ij;
-import org.apache.derby.iapi.reference.SQLState;
 
 /**
  * Functional test for the Statement.setQueryTimeout() method.
  *
- * This test consists of three parts:
+ * This test consists of four parts:
  *
  * 1. Executes a SELECT query in 4 different threads concurrently.
  *    The query calls a user-defined, server-side function which
@@ -71,6 +71,8 @@
  * 3. Sets an invalid (negative) timeout. Verifies that the correct
  *    exception is thrown.
  *
+ * 4. Tests that the query timeout value is not forgotten after the execution
+ *    of a statement (DERBY-1692).
  */
 public class SetQueryTimeoutTest
 {
@@ -190,7 +192,7 @@
             TestFailedException
     {
         Collection ignore = new HashSet();
-        ignore.add(SQLState.LANG_OBJECT_DOES_NOT_EXIST.substring(0,5));
+        ignore.add("42Y55");
         
         exec(conn, "drop table " + tablePrefix + "_orig", ignore);
         exec(conn, "drop table " + tablePrefix + "_copy", ignore);
@@ -393,7 +395,7 @@
             throw new TestFailedException(failMsg);
         } else {
             String sqlState = sqlException.getSQLState();
-            if (!expectSqlState.startsWith(sqlState)) {
+            if (!expectSqlState.equals(sqlState)) {
                 throw new TestFailedException(sqlException);
             }
         }
@@ -475,7 +477,7 @@
          * in this class (note that the TIMEOUT constant is in seconds,
          * while the execution time is in milliseconds). 
          */
-        expectException(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT,
+        expectException("XCL52",
                         statementExecutor[0].getSQLException(),
                         "fetch did not time out. Highest execution time: "
                         + statementExecutor[0].getHighestRunTime() + " ms");
@@ -568,7 +570,7 @@
                 ? TIMEOUT
                 : 0;
             if (timeout > 0) {
-                expectException(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT,
+                expectException("XCL52",
                                 executors[i].getSQLException(),
                                 "exec did not time out. Execution time: "
                                 + executors[i].getHighestRunTime() + " ms");
@@ -615,7 +617,7 @@
         try {
             stmt.setQueryTimeout(-1);
         } catch (SQLException e) {
-            expectException(SQLState.INVALID_QUERYTIMEOUT_VALUE, e,
+            expectException("XJ074", e,
                         "negative timeout value should give exception");
         }
         
@@ -643,6 +645,63 @@
         }
     }
 
+    /** Test for DERBY-1692. */
+    private static void testRememberTimeoutValue(Connection conn)
+        throws TestFailedException
+    {
+        String sql = getFetchQuery("t");
+        try {
+            Statement stmt = conn.createStatement();
+            testStatementRemembersTimeout(stmt);
+            PreparedStatement ps = conn.prepareStatement(sql);
+            testStatementRemembersTimeout(ps);
+            CallableStatement cs = conn.prepareCall(sql);
+            testStatementRemembersTimeout(cs);
+        } catch (SQLException sqle) {
+            throw new TestFailedException("Should not happen", sqle);
+        }
+    }
+
+    /** Test that a statement remembers its timeout value when executed
+     * multiple times. */
+    private static void testStatementRemembersTimeout(Statement stmt)
+        throws SQLException, TestFailedException
+    {
+        System.out.println("Testing that Statement remembers timeout.");
+        stmt.setQueryTimeout(1);
+        for (int i = 0; i < 3; i++) {
+            try {
+                ResultSet rs = stmt.executeQuery(getFetchQuery("t"));
+                while (rs.next());
+                throw new TestFailedException("Should have timed out.");
+            } catch (SQLException sqle) {
+                expectException("XCL52", sqle, "Should have timed out.");
+            }
+        }
+        stmt.close();
+    }
+
+    /** Test that a prepared statement remembers its timeout value when
+     * executed multiple times. */
+    private static void testStatementRemembersTimeout(PreparedStatement ps)
+        throws SQLException, TestFailedException
+    {
+        String name = (ps instanceof CallableStatement) ?
+            "CallableStatement" : "PreparedStatement";
+        System.out.println("Testing that " + name + " remembers timeout.");
+        ps.setQueryTimeout(1);
+        for (int i = 0; i < 3; i++) {
+            try {
+                ResultSet rs = ps.executeQuery();
+                while (rs.next()); 
+                throw new TestFailedException("Should have timed out.");
+           } catch (SQLException sqle) {
+                expectException("XCL52", sqle, "Should have timed out.");
+            }
+        }
+        ps.close();
+    }
+
     /**
      * Main program, makes this class invocable from the command line
      */
@@ -654,7 +713,7 @@
     /**
      * The actual main bulk of this test.
      * Sets up the environment, prepares tables,
-     * runs part 1 and 2, and shuts down.
+     * runs the tests, and shuts down.
      */
     public void go(String[] args)
     {
@@ -684,6 +743,7 @@
             testTimeoutWithFetch(connections[0], connections[1]);
             testTimeoutWithExec(connections);
             testInvalidTimeoutValue(connections[0]);
+            testRememberTimeoutValue(connections[0]);
   
             System.out.println("Test SetQueryTimeoutTest PASSED");
         } catch (Throwable e) {



Mime
View raw message