Skip to content

Commit 73eebcf

Browse files
committed
HIVE-28265: Add JDBC URL query timeout test (like testURLWithFetchSize)
testURLWithHiveQueryTimeoutSeconds sets hive.query.timeout.seconds via the URL query string (getConnection postfix), matching the driver doc for db;sess?hive_conf. Asserts timeout message shows 1s (HIVE-28265). Made-with: Cursor
1 parent d717638 commit 73eebcf

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,41 @@ public void testURLWithFetchSize() throws SQLException {
381381
con.close();
382382
}
383383

384+
/**
385+
* Same idea as {@link #testURLWithFetchSize}: drive session behavior from the JDBC URL instead of
386+
* only {@link Statement#setQueryTimeout(int)} or an explicit {@code SET}. The timeout is supplied
387+
* in the URL query ({@code ?hive_conf_list}) per the driver format
388+
* {@code jdbc:hive2://.../db;sess?hive_conf#hive_var}.
389+
* <p>
390+
* HIVE-28265: {@link SQLTimeoutException#getMessage()} must reflect the configured limit (1s),
391+
* not {@code after 0 seconds}.
392+
*/
393+
@Test
394+
public void testURLWithHiveQueryTimeoutSeconds() throws Exception {
395+
String udfName = SleepMsUDF.class.getName();
396+
// Postfix appends to the query string after test overlay / lock manager settings.
397+
Connection con = getConnection(testDbName, "hive.query.timeout.seconds=1");
398+
try {
399+
Statement stmt1 = con.createStatement();
400+
stmt1.execute("create temporary function sleepMsUDF as '" + udfName + "'");
401+
stmt1.close();
402+
Statement stmt = con.createStatement();
403+
try {
404+
stmt.executeQuery("select sleepMsUDF(t1.under_col, 5) as u0, t1.under_col as u1, "
405+
+ "t2.under_col as u2 from " + tableName + " t1 join " + tableName
406+
+ " t2 on t1.under_col = t2.under_col");
407+
fail("Expecting SQLTimeoutException");
408+
} catch (SQLTimeoutException e) {
409+
assertTimeoutMessageShowsOneSecond("JDBC URL hive.query.timeout.seconds=1 (query string)", e);
410+
} catch (SQLException e) {
411+
fail("Expecting SQLTimeoutException, but got SQLException: " + e);
412+
}
413+
stmt.close();
414+
} finally {
415+
con.close();
416+
}
417+
}
418+
384419
@Test
385420
/**
386421
* Test setting create external purge table by default in jdbc config

0 commit comments

Comments
 (0)