@@ -46,15 +46,14 @@ public class HeartbeatIT extends AbstractDriverIT {
46
46
@ BeforeClass
47
47
public static void setUpClass () throws Exception {
48
48
if (!RunningOnGithubAction .isRunningOnGithubAction ()) {
49
- Connection connection = getSnowflakeAdminConnection ();
50
- connection
51
- .createStatement ()
52
- .execute (
53
- "alter system set"
54
- + " master_token_validity=60"
55
- + ",session_token_validity=20"
56
- + ",SESSION_RECORD_ACCESS_INTERVAL_SECS=1" );
57
- connection .close ();
49
+ try (Connection connection = getSnowflakeAdminConnection ();
50
+ Statement statement = connection .createStatement ()) {
51
+ statement .execute (
52
+ "alter system set"
53
+ + " master_token_validity=60"
54
+ + ",session_token_validity=20"
55
+ + ",SESSION_RECORD_ACCESS_INTERVAL_SECS=1" );
56
+ }
58
57
}
59
58
}
60
59
@@ -65,15 +64,14 @@ public static void setUpClass() throws Exception {
65
64
@ AfterClass
66
65
public static void tearDownClass () throws Exception {
67
66
if (!RunningOnGithubAction .isRunningOnGithubAction ()) {
68
- Connection connection = getSnowflakeAdminConnection ();
69
- connection
70
- .createStatement ()
71
- .execute (
72
- "alter system set"
73
- + " master_token_validity=default"
74
- + ",session_token_validity=default"
75
- + ",SESSION_RECORD_ACCESS_INTERVAL_SECS=default" );
76
- connection .close ();
67
+ try (Connection connection = getSnowflakeAdminConnection ();
68
+ Statement statement = connection .createStatement ()) {
69
+ statement .execute (
70
+ "alter system set"
71
+ + " master_token_validity=default"
72
+ + ",session_token_validity=default"
73
+ + ",SESSION_RECORD_ACCESS_INTERVAL_SECS=default" );
74
+ }
77
75
}
78
76
}
79
77
@@ -87,34 +85,28 @@ public static void tearDownClass() throws Exception {
87
85
*/
88
86
protected void submitQuery (boolean useKeepAliveSession , int queryIdx )
89
87
throws SQLException , InterruptedException {
90
- Connection connection = null ;
91
- Statement statement = null ;
92
- ResultSet resultSet = null ;
93
88
ResultSetMetaData resultSetMetaData ;
94
89
95
- try {
96
- Properties sessionParams = new Properties ();
97
- sessionParams .put (
98
- "CLIENT_SESSION_KEEP_ALIVE" ,
99
- useKeepAliveSession ? Boolean .TRUE .toString () : Boolean .FALSE .toString ());
90
+ Properties sessionParams = new Properties ();
91
+ sessionParams .put (
92
+ "CLIENT_SESSION_KEEP_ALIVE" ,
93
+ useKeepAliveSession ? Boolean .TRUE .toString () : Boolean .FALSE .toString ());
100
94
101
- connection = getConnection (sessionParams );
102
- statement = connection .createStatement ();
95
+ try ( Connection connection = getConnection (sessionParams );
96
+ Statement statement = connection .createStatement ()) {
103
97
104
98
Thread .sleep (61000 ); // sleep 61 seconds
105
- resultSet = statement .executeQuery ("SELECT 1" );
106
- resultSetMetaData = resultSet .getMetaData ();
99
+ try ( ResultSet resultSet = statement .executeQuery ("SELECT 1" )) {
100
+ resultSetMetaData = resultSet .getMetaData ();
107
101
108
- // assert column count
109
- assertEquals (1 , resultSetMetaData .getColumnCount ());
102
+ // assert column count
103
+ assertEquals (1 , resultSetMetaData .getColumnCount ());
110
104
111
- // assert we get 1 row
112
- assertTrue (resultSet .next ());
105
+ // assert we get 1 row
106
+ assertTrue (resultSet .next ());
113
107
114
- logger .fine ("Query " + queryIdx + " passed " );
115
- statement .close ();
116
- } finally {
117
- closeSQLObjects (resultSet , statement , connection );
108
+ logger .fine ("Query " + queryIdx + " passed " );
109
+ }
118
110
}
119
111
}
120
112
0 commit comments