From eab1c6319bf1e49f71fd371fa6e0504206143c45 Mon Sep 17 00:00:00 2001
From: Dominik Przybysz <132913826+sfc-gh-dprzybysz@users.noreply.github.com>
Date: Wed, 21 Feb 2024 09:12:56 +0100
Subject: [PATCH] SNOW-668836: Fix
ConnectionLatestIt.testQueryStatusErrorMessageAndErrorCodeChangeOnAsyncQuery
(#1644)
---
TestOnly/pom.xml | 7 +++
parent-pom.xml | 11 +++++
.../snowflake/client/core/QueryStatus.java | 16 ++++++
.../client/jdbc/ConnectionLatestIT.java | 49 +++++++------------
4 files changed, 53 insertions(+), 30 deletions(-)
diff --git a/TestOnly/pom.xml b/TestOnly/pom.xml
index 46d45b1cf..3188b89de 100644
--- a/TestOnly/pom.xml
+++ b/TestOnly/pom.xml
@@ -13,6 +13,7 @@
UTF-8
UTF-8
10.0.1
+ 4.2.0
2.13.4.2
0.8.4
true
@@ -59,6 +60,12 @@
${mockito.version}
test
+
+ org.awaitility
+ awaitility
+ ${awaitility.version}
+ test
+
commons-dbcp
commons-dbcp
diff --git a/parent-pom.xml b/parent-pom.xml
index 0b4b862c8..9a1882c2e 100644
--- a/parent-pom.xml
+++ b/parent-pom.xml
@@ -22,6 +22,7 @@
10.0.1
9.3
1.8.1
+ 4.2.0
1.12.501
5.0.0
1.74
@@ -475,6 +476,12 @@
${mockito.version}
test
+
+ org.awaitility
+ awaitility
+ ${awaitility.version}
+ test
+
@@ -704,5 +711,9 @@
org.mockito
mockito-inline
+
+ org.awaitility
+ awaitility
+
diff --git a/src/main/java/net/snowflake/client/core/QueryStatus.java b/src/main/java/net/snowflake/client/core/QueryStatus.java
index 73268cf43..bc16abf62 100644
--- a/src/main/java/net/snowflake/client/core/QueryStatus.java
+++ b/src/main/java/net/snowflake/client/core/QueryStatus.java
@@ -37,18 +37,34 @@ public String getDescription() {
return this.description;
}
+ /**
+ * @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
+ */
+ @Deprecated
public String getErrorMessage() {
return this.errorMessage;
}
+ /**
+ * @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
+ */
+ @Deprecated
public int getErrorCode() {
return this.errorCode;
}
+ /**
+ * @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
+ */
+ @Deprecated
public void setErrorMessage(String message) {
this.errorMessage = message;
}
+ /**
+ * @deprecated use {@link net.snowflake.client.jdbc.QueryStatusV2} instead
+ */
+ @Deprecated
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
index d91e8c3a3..15d8b2f80 100644
--- a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
+++ b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
@@ -7,6 +7,7 @@
import static net.snowflake.client.jdbc.ConnectionIT.BAD_REQUEST_GS_CODE;
import static net.snowflake.client.jdbc.ConnectionIT.INVALID_CONNECTION_INFO_CODE;
import static net.snowflake.client.jdbc.ConnectionIT.WAIT_FOR_TELEMETRY_REPORT_IN_MILLISECS;
+import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -390,36 +391,24 @@ public void testAsyncAndSynchronousQueries() throws SQLException {
con.close();
}
- /**
- * Tests that error message and error code are reset after an error. This test is not reliable as
- * it uses sleep() call. It works locally but failed with PR.
- *
- * @throws SQLException
- * @throws InterruptedException
- */
- // @Test
- public void testQueryStatusErrorMessageAndErrorCode() throws SQLException, InterruptedException {
- // open connection and run asynchronous query
- Connection con = getConnection();
- Statement statement = con.createStatement();
- statement.execute("create or replace table testTable(colA string, colB boolean)");
- statement.execute("insert into testTable values ('test', true)");
- ResultSet rs1 =
- statement.unwrap(SnowflakeStatement.class).executeAsyncQuery("select * from testTable");
- QueryStatus status = rs1.unwrap(SnowflakeResultSet.class).getStatus();
- // Set the error message and error code so we can confirm they are reset when getStatus() is
- // called.
- status.setErrorMessage(QueryStatus.FAILED_WITH_ERROR.toString());
- status.setErrorCode(2003);
- Thread.sleep(300);
- status = rs1.unwrap(SnowflakeResultSet.class).getStatus();
- // Assert status of query is a success
- assertEquals(QueryStatus.SUCCESS, status);
- assertEquals("No error reported", status.getErrorMessage());
- assertEquals(0, status.getErrorCode());
- statement.execute("drop table if exists testTable");
- statement.close();
- con.close();
+ /** Can be used in > 3.14.4 (when {@link QueryStatusV2} was added) */
+ @Test
+ public void testQueryStatusErrorMessageAndErrorCodeChangeOnAsyncQuery() throws SQLException {
+ try (Connection con = getConnection();
+ Statement statement = con.createStatement();
+ ResultSet rs1 =
+ statement
+ .unwrap(SnowflakeStatement.class)
+ .executeAsyncQuery("select count(*) from table(generator(timeLimit => 2))")) {
+ SnowflakeResultSet sfResultSet = rs1.unwrap(SnowflakeResultSet.class);
+ // status should change state to RUNNING and then to SUCCESS
+ await()
+ .atMost(Duration.ofSeconds(5))
+ .until(() -> sfResultSet.getStatusV2().getStatus(), equalTo(QueryStatus.RUNNING));
+ await()
+ .atMost(Duration.ofSeconds(5))
+ .until(() -> sfResultSet.getStatusV2().getStatus(), equalTo(QueryStatus.SUCCESS));
+ }
}
@Test