From 3a21cd7e80f11cff7a8da023f34d3365b822da97 Mon Sep 17 00:00:00 2001 From: Kirill Logachev Date: Wed, 24 Jun 2026 07:41:15 +0000 Subject: [PATCH 1/5] chore(bigquery-jdbc): fix flaky testSetTimeout test --- .../google/cloud/bigquery/jdbc/it/ITBase.java | 5 +++++ .../bigquery/jdbc/it/ITNightlyBigQueryTest.java | 16 +++------------- .../cloud/bigquery/jdbc/it/ITStatementTest.java | 17 +++-------------- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java index 87446355d4ca..4ae9501e2652 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java @@ -33,6 +33,11 @@ public class ITBase extends BigQueryJdbcBaseTest { + // This query takes 300 seconds to complete + protected final String query300seconds = + "DECLARE DELAY_TIME DATETIME; SET DELAY_TIME = DATETIME_ADD(CURRENT_DATETIME, INTERVAL 300" + + " SECOND); WHILE CURRENT_DATETIME < DELAY_TIME DO END WHILE;"; + private static String sharedDataset; private static String sharedDataset2; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java index f98d6a8d46ca..b9ab4b4723f3 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java @@ -56,7 +56,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -public class ITNightlyBigQueryTest { +public class ITNightlyBigQueryTest extends ITBase { static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); static Connection bigQueryConnection; static Statement bigQueryStatement; @@ -215,18 +215,13 @@ public void testQueryInterruptGracefullyStopsExplicitJob() DriverManager.getConnection(connection_uri + ";JobCreationMode=1", new Properties()); Statement bigQueryStatement = bigQueryConnection.createStatement(); - // This query takes 300 seconds to complete - String query300Seconds = - "DECLARE DELAY_TIME DATETIME; SET DELAY_TIME = DATETIME_ADD(CURRENT_DATETIME, INTERVAL 300" - + " SECOND); WHILE CURRENT_DATETIME < DELAY_TIME DO END WHILE;"; - // Query will be started in the background thread & we will call cancel from current thread. Thread t = new Thread( () -> { SQLException e = assertThrows( - SQLException.class, () -> bigQueryStatement.execute(query300Seconds)); + SQLException.class, () -> bigQueryStatement.execute(query300seconds)); assertTrue(e.getMessage().contains("User requested cancellation")); threadException.set(false); }); @@ -254,18 +249,13 @@ public void testQueryInterruptGracefullyStopsOptionalJob() DriverManager.getConnection(connection_uri + ";JobCreationMode=2", new Properties()); Statement bigQueryStatement = bigQueryConnection.createStatement(); - // This query takes 300 seconds to complete - String query300Seconds = - "DECLARE DELAY_TIME DATETIME; SET DELAY_TIME = DATETIME_ADD(CURRENT_DATETIME, INTERVAL 300" - + " SECOND); WHILE CURRENT_DATETIME < DELAY_TIME DO END WHILE;"; - // Query will be started in the background thread & we will call cancel from current thread. Thread t = new Thread( () -> { SQLException e = assertThrows( - SQLException.class, () -> bigQueryStatement.execute(query300Seconds)); + SQLException.class, () -> bigQueryStatement.execute(query300seconds)); assertTrue(e.getMessage().contains("Query was cancelled.")); threadException.set(false); }); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java index 35f3284bab1b..b7a272325805 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java @@ -48,7 +48,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -public class ITStatementTest { +public class ITStatementTest extends ITBase { private static final String DEFAULT_CATALOG = ServiceOptions.getDefaultProjectId(); private static String DATASET; private static Random random = new Random(); @@ -323,15 +323,12 @@ public void testSetTimeout() throws SQLException { Connection connection = DriverManager.getConnection(ITBase.connectionUrl); Statement statement = connection.createStatement(); - String selectQuery = - "SELECT views FROM bigquery-public-data.wikipedia.pageviews_2020 WHERE datehour >=" - + " '2020-01-01' LIMIT 9000000"; - // statement.execute(selectQuery); assertEquals(0, statement.getQueryTimeout()); statement.setQueryTimeout(1); assertEquals(1, statement.getQueryTimeout()); - SQLException e = assertThrows(SQLException.class, () -> statement.executeQuery(selectQuery)); + SQLException e = + assertThrows(SQLException.class, () -> statement.executeQuery(query300seconds)); assertEquals( "BigQueryException during runQuery\nJob execution was cancelled: Job timed out", e.getMessage()); @@ -388,14 +385,6 @@ public void testRangeSelectDataset() throws SQLException { connection.close(); } - int getSizeOfResultSet(ResultSet resultSet) throws SQLException { - int count = 0; - while (resultSet.next()) { - count++; - } - return count; - } - @Test public void testTemporaryDatasetLocation() throws SQLException, InterruptedException { String projectId = DEFAULT_CATALOG; From 224a49f44bf87a6ff10969d81dca58f216c3abee Mon Sep 17 00:00:00 2001 From: Kirill Logachev Date: Wed, 24 Jun 2026 08:10:32 +0000 Subject: [PATCH 2/5] feedback --- .../test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java | 2 +- .../google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java | 4 ++-- .../com/google/cloud/bigquery/jdbc/it/ITStatementTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java index 4ae9501e2652..0f4cda735e5f 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java @@ -34,7 +34,7 @@ public class ITBase extends BigQueryJdbcBaseTest { // This query takes 300 seconds to complete - protected final String query300seconds = + public static final String query300seconds = "DECLARE DELAY_TIME DATETIME; SET DELAY_TIME = DATETIME_ADD(CURRENT_DATETIME, INTERVAL 300" + " SECOND); WHILE CURRENT_DATETIME < DELAY_TIME DO END WHILE;"; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java index b9ab4b4723f3..90b5376d17e1 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java @@ -221,7 +221,7 @@ public void testQueryInterruptGracefullyStopsExplicitJob() () -> { SQLException e = assertThrows( - SQLException.class, () -> bigQueryStatement.execute(query300seconds)); + SQLException.class, () -> bigQueryStatement.execute(ITBase.query300seconds)); assertTrue(e.getMessage().contains("User requested cancellation")); threadException.set(false); }); @@ -255,7 +255,7 @@ public void testQueryInterruptGracefullyStopsOptionalJob() () -> { SQLException e = assertThrows( - SQLException.class, () -> bigQueryStatement.execute(query300seconds)); + SQLException.class, () -> bigQueryStatement.execute(ITBase.query300seconds)); assertTrue(e.getMessage().contains("Query was cancelled.")); threadException.set(false); }); diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java index b7a272325805..7ea3bb2072c4 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java @@ -328,7 +328,7 @@ public void testSetTimeout() throws SQLException { statement.setQueryTimeout(1); assertEquals(1, statement.getQueryTimeout()); SQLException e = - assertThrows(SQLException.class, () -> statement.executeQuery(query300seconds)); + assertThrows(SQLException.class, () -> statement.executeQuery(ITBase.query300seconds)); assertEquals( "BigQueryException during runQuery\nJob execution was cancelled: Job timed out", e.getMessage()); From d0aba84c826f92d2bfb275593f9260c4e39ab635 Mon Sep 17 00:00:00 2001 From: Kirill Logachev Date: Wed, 24 Jun 2026 08:19:29 +0000 Subject: [PATCH 3/5] cleanup --- .../cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java | 8 -------- .../google/cloud/bigquery/jdbc/it/ITStatementTest.java | 8 -------- 2 files changed, 16 deletions(-) diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java index 90b5376d17e1..94e538b3ae4b 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java @@ -1674,12 +1674,4 @@ private String getSessionId() throws InterruptedException { Job stubJob = bigQuery.getJob(job.getJobId()); return stubJob.getStatistics().getSessionInfo().getSessionId(); } - - private int resultSetRowCount(ResultSet resultSet) throws SQLException { - int rowCount = 0; - while (resultSet.next()) { - rowCount++; - } - return rowCount; - } } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java index 7ea3bb2072c4..a9b3a3630f9c 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java @@ -244,14 +244,6 @@ public void testScript() throws SQLException { connection.close(); } - private int resultSetRowCount(ResultSet resultSet) throws SQLException { - int rowCount = 0; - while (resultSet.next()) { - rowCount++; - } - return rowCount; - } - @Test public void testStringColumnLength() throws SQLException { String TABLE_NAME = "StringColumnLengthTable"; From 1e167a8739e62ac451307a225bd05e3363d99ead Mon Sep 17 00:00:00 2001 From: Kirill Logachev Date: Wed, 24 Jun 2026 17:38:20 +0000 Subject: [PATCH 4/5] fix test --- .../java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java index a9b3a3630f9c..2f45e6579a09 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java @@ -122,7 +122,7 @@ public void testExecuteQuery() throws SQLException { // setMaxRows Test statement.setMaxRows(5); ResultSet maxRowsResultSet = statement.executeQuery(selectQuery); - assertEquals(5, getSizeOfResultSet(maxRowsResultSet)); + assertEquals(5, resultSetRowCount(maxRowsResultSet)); try { statement.setMaxRows(0); From de6eb36cf51c135d2b950f817bfcf1b63ab8ea8b Mon Sep 17 00:00:00 2001 From: Kirill Logachev Date: Wed, 24 Jun 2026 18:08:47 +0000 Subject: [PATCH 5/5] fix error msg --- .../com/google/cloud/bigquery/jdbc/it/ITStatementTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java index 2f45e6579a09..addbbb3f0b27 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java @@ -16,6 +16,7 @@ package com.google.cloud.bigquery.jdbc.it; +import static com.google.common.truth.Truth.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -321,9 +322,7 @@ public void testSetTimeout() throws SQLException { assertEquals(1, statement.getQueryTimeout()); SQLException e = assertThrows(SQLException.class, () -> statement.executeQuery(ITBase.query300seconds)); - assertEquals( - "BigQueryException during runQuery\nJob execution was cancelled: Job timed out", - e.getMessage()); + assertThat(e.getMessage()).contains("Job execution was cancelled: Job timed out"); statement.close(); connection.close(); }