@@ -755,44 +755,52 @@ public void testCancelQueryWithSession() throws Exception {
755755 throw new SkipException ("Cloud + HTTP doesn't work well. Enough to test locally" );
756756 }
757757
758- // Regression test for #2690: cancelling a query that runs inside a session must not fail with
759- // "Session is locked by a concurrent client" (SESSION_IS_LOCKED). The KILL QUERY request issued by
760- // cancel() must not carry the session id of the query being cancelled.
761758 String sessionId = "test-session-" + UUID .randomUUID ();
762759 Properties properties = new Properties ();
763760 Session session = new Session ();
764761 session .setSessionId (sessionId );
765762 session .applyTo (properties );
766763 try (Connection conn = getJdbcConnection (properties )) {
767- try (StatementImpl stmt = (StatementImpl ) conn .createStatement ()) {
768- stmt .getLocalSettings ().setSessionId (sessionId );
769- stmt .setQueryTimeout (30 ); // safety net so a failed cancel cannot hang the test
764+ testCancelQueryWithSessionValidation (conn , sessionId );
765+ }
770766
771- final AtomicReference <Throwable > threadError = new AtomicReference <>();
772- final CountDownLatch started = new CountDownLatch (1 );
773- Thread worker = new Thread (() -> {
774- started .countDown ();
775- // Long-running query that only completes when killed.
776- try (ResultSet rs = stmt .executeQuery ("SELECT count() FROM system.numbers_mt" )) {
777- rs .next ();
778- } catch (Throwable t ) {
779- System .out .println ("Error: " + t .getMessage ());
780- threadError .set (t );
781- }
782- });
783- worker .start ();
784- started .await ();
767+ // Test case when session id is in custom_http_header
768+ properties = new Properties ();
769+ properties .put (DriverProperties .CUSTOM_HTTP_PARAMS .getKey (), "session_id=" + sessionId );
770+ try (Connection conn = getJdbcConnection (properties )) {
771+ testCancelQueryWithSessionValidation (conn , sessionId );
772+ }
773+ }
785774
786- String queryId = waitForQueryId (stmt , 15 );
787- assertNotNull (queryId , "Query id was not assigned in time" );
788- assertTrue (waitForQueryToStart (queryId , 15 ), "Query did not start on the server in time" );
775+ private void testCancelQueryWithSessionValidation (Connection conn , String sessionId ) throws Exception {
776+ try (StatementImpl stmt = (StatementImpl ) conn .createStatement ()) {
777+ stmt .getLocalSettings ().setSessionId (sessionId );
778+ stmt .setQueryTimeout (30 ); // safety net so a failed cancel cannot hang the test
779+
780+ final AtomicReference <Throwable > threadError = new AtomicReference <>();
781+ final CountDownLatch started = new CountDownLatch (1 );
782+ Thread worker = new Thread (() -> {
783+ started .countDown ();
784+ // Long-running query that only completes when killed.
785+ try (ResultSet rs = stmt .executeQuery ("SELECT count() FROM system.numbers_mt" )) {
786+ rs .next ();
787+ } catch (Throwable t ) {
788+ System .out .println ("Error: " + t .getMessage ());
789+ threadError .set (t );
790+ }
791+ });
792+ worker .start ();
793+ started .await ();
789794
790- // Cancel from the main thread - must not throw SESSION_IS_LOCKED.
791- stmt .cancel ();
795+ String queryId = waitForQueryId (stmt , 15 );
796+ assertNotNull (queryId , "Query id was not assigned in time" );
797+ assertTrue (waitForQueryToStart (queryId , 15 ), "Query did not start on the server in time" );
792798
793- worker .join (TimeUnit .SECONDS .toMillis (20 ));
794- assertFalse (worker .isAlive (), "Query was not cancelled and is still running" );
795- }
799+ // Cancel from the main thread - must not throw SESSION_IS_LOCKED.
800+ stmt .cancel ();
801+
802+ worker .join (TimeUnit .SECONDS .toMillis (20 ));
803+ assertFalse (worker .isAlive (), "Query was not cancelled and is still running" );
796804 }
797805 }
798806
0 commit comments