Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,17 @@ public void testQueryInterruptGracefullyStopsExplicitJob()
SQLException e =
assertThrows(
SQLException.class, () -> bigQueryStatement.execute(query300Seconds));
System.out.println(e.getMessage());
assertTrue(e.getMessage().contains("User requested cancellation"));
Comment on lines +230 to 231

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The System.out.println statement appears to be a leftover debugging aid. It should be removed to keep the test output clean.

Suggested change
System.out.println(e.getMessage());
assertTrue(e.getMessage().contains("User requested cancellation"));
assertTrue(e.getMessage().contains("User requested cancellation"));

threadException.set(false);
});
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,9 @@ public void testSetTimeout() throws SQLException {
try {
statement.executeQuery(selectQuery);
} catch (SQLException e) {
assertTrue(true);
assertEquals("SQL execution canceled", e.getMessage());
assertEquals(
"BigQueryException during runQuery\nJob execution was cancelled: Job timed out",
e.getMessage());
}
Comment on lines 334 to 340

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using a try-catch block without an explicit fail statement means that if statement.executeQuery(selectQuery) unexpectedly succeeds without throwing an exception, the test will pass silently. Using assertThrows is a safer and more idiomatic way to assert that an exception is thrown.

    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();
Expand Down
Loading