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 ff9dbf0e7060..f98d6a8d46ca 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 @@ -232,7 +232,11 @@ public void testQueryInterruptGracefullyStopsExplicitJob() }); t.start(); // Allow thread to actually initiate the query - Thread.sleep(3000); + // Even when job is created, we might be using `query` API which means if we cancle within first + // 10 seconds, + // it is similar to Optional job cancellation. Need to wait until after we're in "Wait for job + // completion" mode. + Thread.sleep(15000); bigQueryStatement.cancel(); // Wait until background thread is finished t.join(); 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 7094e944893d..35f3284bab1b 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 @@ -331,12 +331,10 @@ public void testSetTimeout() throws SQLException { assertEquals(0, statement.getQueryTimeout()); statement.setQueryTimeout(1); assertEquals(1, statement.getQueryTimeout()); - try { - statement.executeQuery(selectQuery); - } catch (SQLException e) { - assertTrue(true); - assertEquals("SQL execution canceled", e.getMessage()); - } + SQLException e = assertThrows(SQLException.class, () -> statement.executeQuery(selectQuery)); + assertEquals( + "BigQueryException during runQuery\nJob execution was cancelled: Job timed out", + e.getMessage()); statement.close(); connection.close(); }