@@ -1163,4 +1163,45 @@ public void testOldCustomSettingsParameter() throws Exception {
11631163 }
11641164 }
11651165 }
1166+
1167+ @ Test (groups = {"integration" })
1168+ public void testSessionTimeout () throws Exception {
1169+ if (isCloud ()) {
1170+ return ; // HTTP sessions require server affinity
1171+ }
1172+
1173+ for (int timeout : new int []{5 , 10 }) {
1174+ String sessionId = "test_session_" + UUID .randomUUID ().toString ();
1175+ Properties properties = new Properties ();
1176+ properties .put (ClientConfigProperties .serverSetting ("session_id" ), sessionId );
1177+ properties .put (ClientConfigProperties .serverSetting ("session_timeout" ), String .valueOf (timeout ));
1178+
1179+ // Create session and temp table
1180+ try (Connection conn = getJdbcConnection (properties )) {
1181+ try (Statement stmt = conn .createStatement ()) {
1182+ stmt .execute ("CREATE TEMPORARY TABLE test_session_table_" + timeout + " (id Int32)" );
1183+ stmt .execute ("INSERT INTO test_session_table_" + timeout + " VALUES (1)" );
1184+
1185+ try (ResultSet rs = stmt .executeQuery ("SELECT * FROM test_session_table_" + timeout )) {
1186+ Assert .assertTrue (rs .next ());
1187+ Assert .assertEquals (rs .getInt (1 ), 1 );
1188+ }
1189+ }
1190+ }
1191+
1192+ // Wait for session timeout
1193+ Thread .sleep ((timeout + 2 ) * 1000L );
1194+
1195+ // Reconnect with same session_id and verify table is gone
1196+ try (Connection conn = getJdbcConnection (properties )) {
1197+ try (Statement stmt = conn .createStatement ()) {
1198+ try (ResultSet rs = stmt .executeQuery ("SELECT * FROM test_session_table_" + timeout )) {
1199+ fail ("Table should not be accessible as session has timed out" );
1200+ } catch (SQLException e ) {
1201+ Assert .assertTrue (e .getMessage ().contains ("Unknown table" ) || e .getMessage ().contains ("does not exist" ));
1202+ }
1203+ }
1204+ }
1205+ }
1206+ }
11661207}
0 commit comments