Skip to content

Commit

Permalink
SNOW-1213117: Wrap connection, statement and result set in try with r…
Browse files Browse the repository at this point in the history
…esources(4/4) (#1724)
  • Loading branch information
sfc-gh-ext-simba-jy committed Apr 26, 2024
1 parent 7cb73ff commit ff0adbd
Show file tree
Hide file tree
Showing 18 changed files with 4,129 additions and 4,600 deletions.
21 changes: 13 additions & 8 deletions src/test/java/net/snowflake/client/jdbc/ServiceNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,21 @@ public void testAddServiceNameToRequestHeader() throws Throwable {
props.setProperty(SFSessionProperty.USER.getPropertyKey(), "fakeuser");
props.setProperty(SFSessionProperty.PASSWORD.getPropertyKey(), "fakepassword");
props.setProperty(SFSessionProperty.INSECURE_MODE.getPropertyKey(), Boolean.TRUE.toString());
SnowflakeConnectionV1 con =
try (SnowflakeConnectionV1 con =
new SnowflakeConnectionV1(
"jdbc:snowflake://http://fakeaccount.snowflakecomputing.com", props);
assertThat(con.getSfSession().getServiceName(), is(INITIAL_SERVICE_NAME));
"jdbc:snowflake://http://fakeaccount.snowflakecomputing.com", props)) {
assertThat(con.getSfSession().getServiceName(), is(INITIAL_SERVICE_NAME));

SnowflakeStatementV1 stmt = (SnowflakeStatementV1) con.createStatement();
stmt.execute("SELECT 1");
assertThat(
stmt.getConnection().unwrap(SnowflakeConnectionV1.class).getSfSession().getServiceName(),
is(NEW_SERVICE_NAME));
try (SnowflakeStatementV1 stmt = (SnowflakeStatementV1) con.createStatement()) {
stmt.execute("SELECT 1");
assertThat(
stmt.getConnection()
.unwrap(SnowflakeConnectionV1.class)
.getSfSession()
.getServiceName(),
is(NEW_SERVICE_NAME));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ public void testChunkDownloaderRetry() throws SQLException, InterruptedException

SnowflakeChunkDownloader snowflakeChunkDownloaderSpy = null;

try (Connection connection = getConnection(properties)) {
Statement statement = connection.createStatement();
try (Connection connection = getConnection(properties);
Statement statement = connection.createStatement()) {
// execute a query that will require chunk downloading
ResultSet resultSet =
try (ResultSet resultSet =
statement.executeQuery(
"select seq8(), randstr(1000, random()) from table(generator(rowcount => 10000))");
List<SnowflakeResultSetSerializable> resultSetSerializables =
((SnowflakeResultSet) resultSet).getResultSetSerializables(100 * 1024 * 1024);
SnowflakeResultSetSerializable resultSetSerializable = resultSetSerializables.get(0);
SnowflakeChunkDownloader downloader =
new SnowflakeChunkDownloader((SnowflakeResultSetSerializableV1) resultSetSerializable);
snowflakeChunkDownloaderSpy = Mockito.spy(downloader);
snowflakeChunkDownloaderSpy.getNextChunkToConsume();
"select seq8(), randstr(1000, random()) from table(generator(rowcount => 10000))")) {
List<SnowflakeResultSetSerializable> resultSetSerializables =
((SnowflakeResultSet) resultSet).getResultSetSerializables(100 * 1024 * 1024);
SnowflakeResultSetSerializable resultSetSerializable = resultSetSerializables.get(0);
SnowflakeChunkDownloader downloader =
new SnowflakeChunkDownloader((SnowflakeResultSetSerializableV1) resultSetSerializable);
snowflakeChunkDownloaderSpy = Mockito.spy(downloader);
snowflakeChunkDownloaderSpy.getNextChunkToConsume();
}
} catch (SnowflakeSQLException exception) {
// verify that request was retried twice before reaching max retries
Mockito.verify(snowflakeChunkDownloaderSpy, Mockito.times(2)).getResultStreamProvider();
Expand Down
Loading

0 comments on commit ff0adbd

Please sign in to comment.