deniskuzZ commented on code in PR #6412:
URL: https://github.com/apache/hive/pull/6412#discussion_r3637316364


##########
itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java:
##########
@@ -2680,6 +2751,83 @@ public void testQueryTimeout() throws Exception {
     stmt.close();
   }
 
+  /**
+   * When the session timeout is configured via a {@code SET 
hive.query.timeout.seconds=...}
+   * statement and no {@link Statement#setQueryTimeout(int)} is called, the
+   * {@link SQLTimeoutException#getMessage()} must still reflect the real 
limit.
+   * Message must begin with {@link #QUERY_TIMED_OUT_AFTER_1_SECONDS};
+   * HS2 may append {@code ; Query ID: ...}.
+   */
+  @Test
+  public void testQueryTimeoutFromSetStatement() throws Exception {
+    String udfName = SleepMsUDF.class.getName();
+    Statement stmt1 = con.createStatement();
+    stmt1.execute("create temporary function sleepMsUDF as '" + udfName + "'");
+    stmt1.close();
+
+    Statement stmt = con.createStatement();
+    stmt.execute("set hive.query.timeout.seconds=1s");
+
+    try {
+      stmt.executeQuery("select sleepMsUDF(t1.under_col, 5) as u0, 
t1.under_col as u1, "
+          + "t2.under_col as u2 from " + tableName + " t1 join " + tableName
+          + " t2 on t1.under_col = t2.under_col");
+      fail("Expecting SQLTimeoutException");
+    } catch (SQLTimeoutException e) {
+      assertTimeoutMessageShowsOneSecond(
+          "Session query timeout (1s)", e);
+    } catch (SQLException e) {
+      fail("Expecting SQLTimeoutException, but got SQLException: " + e);
+    }
+    stmt.close();
+  }
+
+  /**
+   * Variant of {@link #testQueryTimeoutFromSetStatement}: the {@code SET} is 
issued on a separate,
+   * already-closed statement; the timed-out query runs on a brand-new 
statement with no
+   * {@link Statement#setQueryTimeout(int)} call. The timeout lives on the HS2 
session, so it
+   * persists across client statement instances and the server-supplied {@link 
SQLTimeoutException}
+   * message must still reflect it correctly.
+   */
+  @Test
+  public void testQueryTimeoutMessagePersistedAcrossStatements() throws 
Exception {
+    String udfName = SleepMsUDF.class.getName();
+    Statement stmt1 = con.createStatement();
+    stmt1.execute("create temporary function sleepMsUDF as '" + udfName + "'");
+    stmt1.close();
+
+    // SET is issued on stmt2, which is then closed – timeout must survive on 
the connection
+    Statement stmt2 = con.createStatement();
+    stmt2.execute("set hive.query.timeout.seconds=1s");
+    stmt2.close();
+
+    // Brand-new statement, no setQueryTimeout() call – relies solely on the 
HS2 session timeout
+    Statement stmt = con.createStatement();
+    System.err.println("Executing query (expecting timeout): ");
+    try {
+      stmt.executeQuery("select sleepMsUDF(t1.under_col, 5) as u0, 
t1.under_col as u1, "
+          + "t2.under_col as u2 from " + tableName + " t1 join " + tableName
+          + " t2 on t1.under_col = t2.under_col");
+      fail("Expecting SQLTimeoutException");
+    } catch (SQLTimeoutException e) {
+      assertTimeoutMessageShowsOneSecond("SET on closed stmt2, executeQuery on 
new stmt", e);
+      System.err.println(e.toString());
+    } catch (SQLException e) {
+      fail("Expecting SQLTimeoutException, but got SQLException: " + e);
+      e.printStackTrace();
+    }
+
+    // A fast query must still complete when the per-statement timeout 
overrides
+    stmt.setQueryTimeout(5);
+    try {
+      stmt.executeQuery("show tables");
+    } catch (SQLException e) {
+      fail("Unexpected SQLException: " + e);
+      e.printStackTrace();

Review Comment:
   what is the point of this? you already use fail with exception above?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to