Skip to content

Commit eab1c63

Browse files
authoredFeb 21, 2024··
SNOW-668836: Fix ConnectionLatestIt.testQueryStatusErrorMessageAndErrorCodeChangeOnAsyncQuery (#1644)
1 parent 7fdc8ef commit eab1c63

File tree

4 files changed

+53
-30
lines changed

4 files changed

+53
-30
lines changed
 

‎TestOnly/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1515
<arrow.version>10.0.1</arrow.version>
16+
<awaitility.version>4.2.0</awaitility.version>
1617
<jacksondatabind.version>2.13.4.2</jacksondatabind.version>
1718
<jacoco.version>0.8.4</jacoco.version>
1819
<jacoco.skip.instrument>true</jacoco.skip.instrument>
@@ -59,6 +60,12 @@
5960
<version>${mockito.version}</version>
6061
<scope>test</scope>
6162
</dependency>
63+
<dependency>
64+
<groupId>org.awaitility</groupId>
65+
<artifactId>awaitility</artifactId>
66+
<version>${awaitility.version}</version>
67+
<scope>test</scope>
68+
</dependency>
6269
<dependency>
6370
<groupId>commons-dbcp</groupId>
6471
<artifactId>commons-dbcp</artifactId>

‎parent-pom.xml

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<arrow.version>10.0.1</arrow.version>
2323
<asm.version>9.3</asm.version>
2424
<avro.version>1.8.1</avro.version>
25+
<awaitility.version>4.2.0</awaitility.version>
2526
<awssdk.version>1.12.501</awssdk.version>
2627
<azure.storage.version>5.0.0</azure.storage.version>
2728
<bouncycastle.version>1.74</bouncycastle.version>
@@ -475,6 +476,12 @@
475476
<version>${mockito.version}</version>
476477
<scope>test</scope>
477478
</dependency>
479+
<dependency>
480+
<groupId>org.awaitility</groupId>
481+
<artifactId>awaitility</artifactId>
482+
<version>${awaitility.version}</version>
483+
<scope>test</scope>
484+
</dependency>
478485
</dependencies>
479486
</dependencyManagement>
480487

@@ -704,5 +711,9 @@
704711
<groupId>org.mockito</groupId>
705712
<artifactId>mockito-inline</artifactId>
706713
</dependency>
714+
<dependency>
715+
<groupId>org.awaitility</groupId>
716+
<artifactId>awaitility</artifactId>
717+
</dependency>
707718
</dependencies>
708719
</project>

‎src/main/java/net/snowflake/client/core/QueryStatus.java

+16
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,34 @@ public String getDescription() {
3737
return this.description;
3838
}
3939

40+
/**
41+
* @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
42+
*/
43+
@Deprecated
4044
public String getErrorMessage() {
4145
return this.errorMessage;
4246
}
4347

48+
/**
49+
* @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
50+
*/
51+
@Deprecated
4452
public int getErrorCode() {
4553
return this.errorCode;
4654
}
4755

56+
/**
57+
* @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
58+
*/
59+
@Deprecated
4860
public void setErrorMessage(String message) {
4961
this.errorMessage = message;
5062
}
5163

64+
/**
65+
* @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
66+
*/
67+
@Deprecated
5268
public void setErrorCode(int errorCode) {
5369
this.errorCode = errorCode;
5470
}

‎src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java

+19-30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static net.snowflake.client.jdbc.ConnectionIT.BAD_REQUEST_GS_CODE;
88
import static net.snowflake.client.jdbc.ConnectionIT.INVALID_CONNECTION_INFO_CODE;
99
import static net.snowflake.client.jdbc.ConnectionIT.WAIT_FOR_TELEMETRY_REPORT_IN_MILLISECS;
10+
import static org.awaitility.Awaitility.await;
1011
import static org.hamcrest.CoreMatchers.equalTo;
1112
import static org.hamcrest.CoreMatchers.is;
1213
import static org.hamcrest.MatcherAssert.assertThat;
@@ -390,36 +391,24 @@ public void testAsyncAndSynchronousQueries() throws SQLException {
390391
con.close();
391392
}
392393

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+
}
423412
}
424413

425414
@Test

0 commit comments

Comments
 (0)
Please sign in to comment.