Skip to content

Commit 3a21cd7

Browse files
committed
chore(bigquery-jdbc): fix flaky testSetTimeout test
1 parent fa81a5e commit 3a21cd7

3 files changed

Lines changed: 11 additions & 27 deletions

File tree

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
public class ITBase extends BigQueryJdbcBaseTest {
3535

36+
// This query takes 300 seconds to complete
37+
protected final String query300seconds =
38+
"DECLARE DELAY_TIME DATETIME; SET DELAY_TIME = DATETIME_ADD(CURRENT_DATETIME, INTERVAL 300"
39+
+ " SECOND); WHILE CURRENT_DATETIME < DELAY_TIME DO END WHILE;";
40+
3641
private static String sharedDataset;
3742
private static String sharedDataset2;
3843

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITNightlyBigQueryTest.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import org.junit.jupiter.api.BeforeAll;
5757
import org.junit.jupiter.api.Test;
5858

59-
public class ITNightlyBigQueryTest {
59+
public class ITNightlyBigQueryTest extends ITBase {
6060
static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
6161
static Connection bigQueryConnection;
6262
static Statement bigQueryStatement;
@@ -215,18 +215,13 @@ public void testQueryInterruptGracefullyStopsExplicitJob()
215215
DriverManager.getConnection(connection_uri + ";JobCreationMode=1", new Properties());
216216
Statement bigQueryStatement = bigQueryConnection.createStatement();
217217

218-
// This query takes 300 seconds to complete
219-
String query300Seconds =
220-
"DECLARE DELAY_TIME DATETIME; SET DELAY_TIME = DATETIME_ADD(CURRENT_DATETIME, INTERVAL 300"
221-
+ " SECOND); WHILE CURRENT_DATETIME < DELAY_TIME DO END WHILE;";
222-
223218
// Query will be started in the background thread & we will call cancel from current thread.
224219
Thread t =
225220
new Thread(
226221
() -> {
227222
SQLException e =
228223
assertThrows(
229-
SQLException.class, () -> bigQueryStatement.execute(query300Seconds));
224+
SQLException.class, () -> bigQueryStatement.execute(query300seconds));
230225
assertTrue(e.getMessage().contains("User requested cancellation"));
231226
threadException.set(false);
232227
});
@@ -254,18 +249,13 @@ public void testQueryInterruptGracefullyStopsOptionalJob()
254249
DriverManager.getConnection(connection_uri + ";JobCreationMode=2", new Properties());
255250
Statement bigQueryStatement = bigQueryConnection.createStatement();
256251

257-
// This query takes 300 seconds to complete
258-
String query300Seconds =
259-
"DECLARE DELAY_TIME DATETIME; SET DELAY_TIME = DATETIME_ADD(CURRENT_DATETIME, INTERVAL 300"
260-
+ " SECOND); WHILE CURRENT_DATETIME < DELAY_TIME DO END WHILE;";
261-
262252
// Query will be started in the background thread & we will call cancel from current thread.
263253
Thread t =
264254
new Thread(
265255
() -> {
266256
SQLException e =
267257
assertThrows(
268-
SQLException.class, () -> bigQueryStatement.execute(query300Seconds));
258+
SQLException.class, () -> bigQueryStatement.execute(query300seconds));
269259
assertTrue(e.getMessage().contains("Query was cancelled."));
270260
threadException.set(false);
271261
});

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITStatementTest.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.junit.jupiter.api.Disabled;
4949
import org.junit.jupiter.api.Test;
5050

51-
public class ITStatementTest {
51+
public class ITStatementTest extends ITBase {
5252
private static final String DEFAULT_CATALOG = ServiceOptions.getDefaultProjectId();
5353
private static String DATASET;
5454
private static Random random = new Random();
@@ -323,15 +323,12 @@ public void testSetTimeout() throws SQLException {
323323
Connection connection = DriverManager.getConnection(ITBase.connectionUrl);
324324
Statement statement = connection.createStatement();
325325

326-
String selectQuery =
327-
"SELECT views FROM bigquery-public-data.wikipedia.pageviews_2020 WHERE datehour >="
328-
+ " '2020-01-01' LIMIT 9000000";
329-
330326
// statement.execute(selectQuery);
331327
assertEquals(0, statement.getQueryTimeout());
332328
statement.setQueryTimeout(1);
333329
assertEquals(1, statement.getQueryTimeout());
334-
SQLException e = assertThrows(SQLException.class, () -> statement.executeQuery(selectQuery));
330+
SQLException e =
331+
assertThrows(SQLException.class, () -> statement.executeQuery(query300seconds));
335332
assertEquals(
336333
"BigQueryException during runQuery\nJob execution was cancelled: Job timed out",
337334
e.getMessage());
@@ -388,14 +385,6 @@ public void testRangeSelectDataset() throws SQLException {
388385
connection.close();
389386
}
390387

391-
int getSizeOfResultSet(ResultSet resultSet) throws SQLException {
392-
int count = 0;
393-
while (resultSet.next()) {
394-
count++;
395-
}
396-
return count;
397-
}
398-
399388
@Test
400389
public void testTemporaryDatasetLocation() throws SQLException, InterruptedException {
401390
String projectId = DEFAULT_CATALOG;

0 commit comments

Comments
 (0)