@@ -1271,13 +1271,13 @@ public void testQueryMetrics() throws Exception {
12711271 .waitEndOfQuery (true )
12721272 .setQueryId (uuid );
12731273
1274- QueryResponse response = client .query ("SELECT * FROM " + DATASET_TABLE + " LIMIT 3" , settings ).get ();
1274+ try (QueryResponse response = client .query ("SELECT * FROM " + DATASET_TABLE + " LIMIT 3" , settings ).get ()) {
1275+ // Stats should be available after the query is done
1276+ OperationMetrics metrics = response .getMetrics ();
12751277
1276- // Stats should be available after the query is done
1277- OperationMetrics metrics = response .getMetrics ();
1278-
1279- Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), 10 ); // 10 rows in the table
1280- Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), 3 );
1278+ Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), 10 ); // 10 rows in the table
1279+ Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), 3 );
1280+ }
12811281
12821282 StringBuilder insertStmtBuilder = new StringBuilder ();
12831283 insertStmtBuilder .append ("INSERT INTO default." ).append (DATASET_TABLE ).append (" VALUES " );
@@ -1288,17 +1288,26 @@ public void testQueryMetrics() throws Exception {
12881288 insertStmtBuilder .setLength (insertStmtBuilder .length () - 2 );
12891289 insertStmtBuilder .append ("), " );
12901290 }
1291- response = client .query (insertStmtBuilder .toString (), settings ).get ();
1291+ try ( QueryResponse response = client .query (insertStmtBuilder .toString (), settings ).get ()) {
12921292
1293- metrics = response .getMetrics ();
1293+ OperationMetrics metrics = response .getMetrics ();
12941294
1295- Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), rowsToInsert ); // 10 rows in the table
1296- Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), rowsToInsert );
1297- Assert .assertEquals (response .getReadRows (), rowsToInsert );
1298- Assert .assertTrue (metrics .getMetric (ClientMetrics .OP_DURATION ).getLong () > 0 );
1299- Assert .assertEquals (metrics .getQueryId (), uuid );
1300- Assert .assertEquals (response .getQueryId (), uuid );
1295+ Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), rowsToInsert ); // 10 rows in the table
1296+ Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), rowsToInsert );
1297+ Assert .assertEquals (response .getReadRows (), rowsToInsert );
1298+ Assert .assertTrue (metrics .getMetric (ClientMetrics .OP_DURATION ).getLong () > 0 );
1299+ Assert .assertEquals (metrics .getQueryId (), uuid );
1300+ Assert .assertEquals (response .getQueryId (), uuid );
1301+ }
13011302
1303+ try (QueryResponse response = client .query ("SELECT number FROM system.numbers LIMIT 30" , settings ).get ()) {
1304+ // Stats should be available after the query is done
1305+ OperationMetrics metrics = response .getMetrics ();
1306+
1307+ Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), 30 );
1308+ Assert .assertTrue (metrics .getMetric (ServerMetrics .ELAPSED_TIME ).getLong () > 0 );
1309+ Assert .assertTrue (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong () > 0 );
1310+ }
13021311 }
13031312
13041313 private final static List <String > DATASET_COLUMNS = Arrays .asList (
0 commit comments