Skip to content

Commit ff0adbd

Browse files
SNOW-1213117: Wrap connection, statement and result set in try with resources(4/4) (#1724)
1 parent 7cb73ff commit ff0adbd

18 files changed

+4129
-4600
lines changed

src/test/java/net/snowflake/client/jdbc/ServiceNameTest.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,21 @@ public void testAddServiceNameToRequestHeader() throws Throwable {
127127
props.setProperty(SFSessionProperty.USER.getPropertyKey(), "fakeuser");
128128
props.setProperty(SFSessionProperty.PASSWORD.getPropertyKey(), "fakepassword");
129129
props.setProperty(SFSessionProperty.INSECURE_MODE.getPropertyKey(), Boolean.TRUE.toString());
130-
SnowflakeConnectionV1 con =
130+
try (SnowflakeConnectionV1 con =
131131
new SnowflakeConnectionV1(
132-
"jdbc:snowflake://http://fakeaccount.snowflakecomputing.com", props);
133-
assertThat(con.getSfSession().getServiceName(), is(INITIAL_SERVICE_NAME));
132+
"jdbc:snowflake://http://fakeaccount.snowflakecomputing.com", props)) {
133+
assertThat(con.getSfSession().getServiceName(), is(INITIAL_SERVICE_NAME));
134134

135-
SnowflakeStatementV1 stmt = (SnowflakeStatementV1) con.createStatement();
136-
stmt.execute("SELECT 1");
137-
assertThat(
138-
stmt.getConnection().unwrap(SnowflakeConnectionV1.class).getSfSession().getServiceName(),
139-
is(NEW_SERVICE_NAME));
135+
try (SnowflakeStatementV1 stmt = (SnowflakeStatementV1) con.createStatement()) {
136+
stmt.execute("SELECT 1");
137+
assertThat(
138+
stmt.getConnection()
139+
.unwrap(SnowflakeConnectionV1.class)
140+
.getSfSession()
141+
.getServiceName(),
142+
is(NEW_SERVICE_NAME));
143+
}
144+
}
140145
}
141146
}
142147
}

src/test/java/net/snowflake/client/jdbc/SnowflakeChunkDownloaderLatestIT.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@ public void testChunkDownloaderRetry() throws SQLException, InterruptedException
3737

3838
SnowflakeChunkDownloader snowflakeChunkDownloaderSpy = null;
3939

40-
try (Connection connection = getConnection(properties)) {
41-
Statement statement = connection.createStatement();
40+
try (Connection connection = getConnection(properties);
41+
Statement statement = connection.createStatement()) {
4242
// execute a query that will require chunk downloading
43-
ResultSet resultSet =
43+
try (ResultSet resultSet =
4444
statement.executeQuery(
45-
"select seq8(), randstr(1000, random()) from table(generator(rowcount => 10000))");
46-
List<SnowflakeResultSetSerializable> resultSetSerializables =
47-
((SnowflakeResultSet) resultSet).getResultSetSerializables(100 * 1024 * 1024);
48-
SnowflakeResultSetSerializable resultSetSerializable = resultSetSerializables.get(0);
49-
SnowflakeChunkDownloader downloader =
50-
new SnowflakeChunkDownloader((SnowflakeResultSetSerializableV1) resultSetSerializable);
51-
snowflakeChunkDownloaderSpy = Mockito.spy(downloader);
52-
snowflakeChunkDownloaderSpy.getNextChunkToConsume();
45+
"select seq8(), randstr(1000, random()) from table(generator(rowcount => 10000))")) {
46+
List<SnowflakeResultSetSerializable> resultSetSerializables =
47+
((SnowflakeResultSet) resultSet).getResultSetSerializables(100 * 1024 * 1024);
48+
SnowflakeResultSetSerializable resultSetSerializable = resultSetSerializables.get(0);
49+
SnowflakeChunkDownloader downloader =
50+
new SnowflakeChunkDownloader((SnowflakeResultSetSerializableV1) resultSetSerializable);
51+
snowflakeChunkDownloaderSpy = Mockito.spy(downloader);
52+
snowflakeChunkDownloaderSpy.getNextChunkToConsume();
53+
}
5354
} catch (SnowflakeSQLException exception) {
5455
// verify that request was retried twice before reaching max retries
5556
Mockito.verify(snowflakeChunkDownloaderSpy, Mockito.times(2)).getResultStreamProvider();

0 commit comments

Comments
 (0)