Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1213117: Wrap connection, statement and result set in try with resources(4/4) #1724

Merged
merged 12 commits into from
Apr 26, 2024
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
Loading