@@ -1248,13 +1248,13 @@ public void testQueryMetrics() throws Exception {
12481248 .waitEndOfQuery (true )
12491249 .setQueryId (uuid );
12501250
1251- QueryResponse response = client .query ("SELECT * FROM " + DATASET_TABLE + " LIMIT 3" , settings ).get ();
1251+ try (QueryResponse response = client .query ("SELECT * FROM " + DATASET_TABLE + " LIMIT 3" , settings ).get ()) {
1252+ // Stats should be available after the query is done
1253+ OperationMetrics metrics = response .getMetrics ();
12521254
1253- // Stats should be available after the query is done
1254- OperationMetrics metrics = response .getMetrics ();
1255-
1256- Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), 10 ); // 10 rows in the table
1257- Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), 3 );
1255+ Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), 10 ); // 10 rows in the table
1256+ Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), 3 );
1257+ }
12581258
12591259 StringBuilder insertStmtBuilder = new StringBuilder ();
12601260 insertStmtBuilder .append ("INSERT INTO default." ).append (DATASET_TABLE ).append (" VALUES " );
@@ -1265,17 +1265,26 @@ public void testQueryMetrics() throws Exception {
12651265 insertStmtBuilder .setLength (insertStmtBuilder .length () - 2 );
12661266 insertStmtBuilder .append ("), " );
12671267 }
1268- response = client .query (insertStmtBuilder .toString (), settings ).get ();
1268+ try ( QueryResponse response = client .query (insertStmtBuilder .toString (), settings ).get ()) {
12691269
1270- metrics = response .getMetrics ();
1270+ OperationMetrics metrics = response .getMetrics ();
12711271
1272- Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), rowsToInsert ); // 10 rows in the table
1273- Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), rowsToInsert );
1274- Assert .assertEquals (response .getReadRows (), rowsToInsert );
1275- Assert .assertTrue (metrics .getMetric (ClientMetrics .OP_DURATION ).getLong () > 0 );
1276- Assert .assertEquals (metrics .getQueryId (), uuid );
1277- Assert .assertEquals (response .getQueryId (), uuid );
1272+ Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), rowsToInsert ); // 10 rows in the table
1273+ Assert .assertEquals (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong (), rowsToInsert );
1274+ Assert .assertEquals (response .getReadRows (), rowsToInsert );
1275+ Assert .assertTrue (metrics .getMetric (ClientMetrics .OP_DURATION ).getLong () > 0 );
1276+ Assert .assertEquals (metrics .getQueryId (), uuid );
1277+ Assert .assertEquals (response .getQueryId (), uuid );
1278+ }
12781279
1280+ try (QueryResponse response = client .query ("SELECT number FROM system.numbers LIMIT 30" , settings ).get ()) {
1281+ // Stats should be available after the query is done
1282+ OperationMetrics metrics = response .getMetrics ();
1283+
1284+ Assert .assertEquals (metrics .getMetric (ServerMetrics .NUM_ROWS_READ ).getLong (), 30 );
1285+ Assert .assertTrue (metrics .getMetric (ServerMetrics .ELAPSED_TIME ).getLong () > 0 );
1286+ Assert .assertTrue (metrics .getMetric (ServerMetrics .RESULT_ROWS ).getLong () > 0 );
1287+ }
12791288 }
12801289
12811290 private final static List <String > DATASET_COLUMNS = Arrays .asList (
0 commit comments