|
7 | 7 | import static net.snowflake.client.jdbc.ConnectionIT.BAD_REQUEST_GS_CODE;
|
8 | 8 | import static net.snowflake.client.jdbc.ConnectionIT.INVALID_CONNECTION_INFO_CODE;
|
9 | 9 | import static net.snowflake.client.jdbc.ConnectionIT.WAIT_FOR_TELEMETRY_REPORT_IN_MILLISECS;
|
| 10 | +import static org.awaitility.Awaitility.await; |
10 | 11 | import static org.hamcrest.CoreMatchers.equalTo;
|
11 | 12 | import static org.hamcrest.CoreMatchers.is;
|
12 | 13 | import static org.hamcrest.MatcherAssert.assertThat;
|
@@ -390,36 +391,24 @@ public void testAsyncAndSynchronousQueries() throws SQLException {
|
390 | 391 | con.close();
|
391 | 392 | }
|
392 | 393 |
|
393 |
| - /** |
394 |
| - * Tests that error message and error code are reset after an error. This test is not reliable as |
395 |
| - * it uses sleep() call. It works locally but failed with PR. |
396 |
| - * |
397 |
| - * @throws SQLException |
398 |
| - * @throws InterruptedException |
399 |
| - */ |
400 |
| - // @Test |
401 |
| - public void testQueryStatusErrorMessageAndErrorCode() throws SQLException, InterruptedException { |
402 |
| - // open connection and run asynchronous query |
403 |
| - Connection con = getConnection(); |
404 |
| - Statement statement = con.createStatement(); |
405 |
| - statement.execute("create or replace table testTable(colA string, colB boolean)"); |
406 |
| - statement.execute("insert into testTable values ('test', true)"); |
407 |
| - ResultSet rs1 = |
408 |
| - statement.unwrap(SnowflakeStatement.class).executeAsyncQuery("select * from testTable"); |
409 |
| - QueryStatus status = rs1.unwrap(SnowflakeResultSet.class).getStatus(); |
410 |
| - // Set the error message and error code so we can confirm they are reset when getStatus() is |
411 |
| - // called. |
412 |
| - status.setErrorMessage(QueryStatus.FAILED_WITH_ERROR.toString()); |
413 |
| - status.setErrorCode(2003); |
414 |
| - Thread.sleep(300); |
415 |
| - status = rs1.unwrap(SnowflakeResultSet.class).getStatus(); |
416 |
| - // Assert status of query is a success |
417 |
| - assertEquals(QueryStatus.SUCCESS, status); |
418 |
| - assertEquals("No error reported", status.getErrorMessage()); |
419 |
| - assertEquals(0, status.getErrorCode()); |
420 |
| - statement.execute("drop table if exists testTable"); |
421 |
| - statement.close(); |
422 |
| - con.close(); |
| 394 | + /** Can be used in > 3.14.4 (when {@link QueryStatusV2} was added) */ |
| 395 | + @Test |
| 396 | + public void testQueryStatusErrorMessageAndErrorCodeChangeOnAsyncQuery() throws SQLException { |
| 397 | + try (Connection con = getConnection(); |
| 398 | + Statement statement = con.createStatement(); |
| 399 | + ResultSet rs1 = |
| 400 | + statement |
| 401 | + .unwrap(SnowflakeStatement.class) |
| 402 | + .executeAsyncQuery("select count(*) from table(generator(timeLimit => 2))")) { |
| 403 | + SnowflakeResultSet sfResultSet = rs1.unwrap(SnowflakeResultSet.class); |
| 404 | + // status should change state to RUNNING and then to SUCCESS |
| 405 | + await() |
| 406 | + .atMost(Duration.ofSeconds(5)) |
| 407 | + .until(() -> sfResultSet.getStatusV2().getStatus(), equalTo(QueryStatus.RUNNING)); |
| 408 | + await() |
| 409 | + .atMost(Duration.ofSeconds(5)) |
| 410 | + .until(() -> sfResultSet.getStatusV2().getStatus(), equalTo(QueryStatus.SUCCESS)); |
| 411 | + } |
423 | 412 | }
|
424 | 413 |
|
425 | 414 | @Test
|
|
0 commit comments