From c3e92303adfaca9ab73a947070668dc83b64bf56 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Mon, 4 Nov 2024 10:30:26 -0500 Subject: [PATCH] chore(test): remove some warnings from tests (#2398) Make sure to close the ephemeral stubs to avoid polluting the logs with unclosed channel errors --- .../v2/stub/sql/ExecuteQueryCallableTest.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java index deedfbaba1..1ddac33720 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/sql/ExecuteQueryCallableTest.java @@ -124,15 +124,16 @@ public void testExecuteQueryRequestsIgnoreOverriddenMaxAttempts() throws IOExcep .stubSettings() .executeQuerySettings() .setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(10).build()); - EnhancedBigtableStub overrideStub = - EnhancedBigtableStub.create(overrideSettings.build().getStubSettings()); - SqlServerStream stream = - overrideStub.executeQueryCallable().call(Statement.of("SELECT * FROM table")); - Iterator iterator = stream.rows().iterator(); + try (EnhancedBigtableStub overrideStub = + EnhancedBigtableStub.create(overrideSettings.build().getStubSettings())) { + SqlServerStream stream = + overrideStub.executeQueryCallable().call(Statement.of("SELECT * FROM table")); + Iterator iterator = stream.rows().iterator(); - assertThrows(UnavailableException.class, iterator::next).getCause(); - assertThat(fakeService.attempts).isEqualTo(1); + assertThrows(UnavailableException.class, iterator::next).getCause(); + assertThat(fakeService.attempts).isEqualTo(1); + } } @Test @@ -160,13 +161,15 @@ public void testExecuteQueryRequestsRespectDeadline() throws IOException { .setInitialRpcTimeout(Duration.ofMillis(10)) .setMaxRpcTimeout(Duration.ofMillis(10)) .build()); - EnhancedBigtableStub overrideDeadline = - EnhancedBigtableStub.create(overrideSettings.build().getStubSettings()); - SqlServerStream streamOverride = - overrideDeadline.executeQueryCallable().call(Statement.of("SELECT * FROM table")); - Iterator overrideIterator = streamOverride.rows().iterator(); - // We don't care about this but are reusing the fake service that tests retries - assertThrows(DeadlineExceededException.class, overrideIterator::next).getCause(); + + try (EnhancedBigtableStub overrideDeadline = + EnhancedBigtableStub.create(overrideSettings.build().getStubSettings())) { + SqlServerStream streamOverride = + overrideDeadline.executeQueryCallable().call(Statement.of("SELECT * FROM table")); + Iterator overrideIterator = streamOverride.rows().iterator(); + // We don't care about this but are reusing the fake service that tests retries + assertThrows(DeadlineExceededException.class, overrideIterator::next).getCause(); + } } private static class FakeService extends BigtableGrpc.BigtableImplBase {