File tree Expand file tree Collapse file tree
java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it
java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it
java-showcase-3.25.8/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626import com .google .api .client .json .GenericJson ;
2727import com .google .api .client .json .JsonFactory ;
2828import com .google .api .client .json .gson .GsonFactory ;
29+ import com .google .api .gax .core .BackgroundResource ;
2930import com .google .api .gax .core .FixedCredentialsProvider ;
3031import com .google .api .gax .rpc .ClientContext ;
3132import com .google .auth .Credentials ;
@@ -85,9 +86,25 @@ void setup(@TempDir Path tempDir) throws IOException {
8586
8687 @ AfterEach
8788 void tearDown () throws InterruptedException {
88- if (client != null ) {
89- client .close ();
90- client .awaitTermination (TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
89+ try {
90+ if (client != null ) {
91+ client .close ();
92+ client .awaitTermination (TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
93+ }
94+ } finally {
95+ if (context != null ) {
96+ // EchoStubSettings.newBuilder(context) configures a FixedTransportChannelProvider using the
97+ // channel from ClientContext. FixedTransportChannelProvider disables auto-closing
98+ // (shouldAutoClose() == false), so closing the client does not close the channel. We must
99+ // manually shut down the background resources owned by ClientContext.
100+ for (BackgroundResource resource : context .getBackgroundResources ()) {
101+ resource .shutdown ();
102+ }
103+ for (BackgroundResource resource : context .getBackgroundResources ()) {
104+ resource .awaitTermination (
105+ TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
106+ }
107+ }
91108 }
92109 }
93110
Original file line number Diff line number Diff line change 2626import com .google .api .client .json .GenericJson ;
2727import com .google .api .client .json .JsonFactory ;
2828import com .google .api .client .json .gson .GsonFactory ;
29+ import com .google .api .gax .core .BackgroundResource ;
2930import com .google .api .gax .core .FixedCredentialsProvider ;
3031import com .google .api .gax .rpc .ClientContext ;
3132import com .google .auth .Credentials ;
@@ -85,9 +86,25 @@ void setup(@TempDir Path tempDir) throws IOException {
8586
8687 @ AfterEach
8788 void tearDown () throws InterruptedException {
88- if (client != null ) {
89- client .close ();
90- client .awaitTermination (TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
89+ try {
90+ if (client != null ) {
91+ client .close ();
92+ client .awaitTermination (TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
93+ }
94+ } finally {
95+ if (context != null ) {
96+ // EchoStubSettings.newBuilder(context) configures a FixedTransportChannelProvider using the
97+ // channel from ClientContext. FixedTransportChannelProvider disables auto-closing
98+ // (shouldAutoClose() == false), so closing the client does not close the channel. We must
99+ // manually shut down the background resources owned by ClientContext.
100+ for (BackgroundResource resource : context .getBackgroundResources ()) {
101+ resource .shutdown ();
102+ }
103+ for (BackgroundResource resource : context .getBackgroundResources ()) {
104+ resource .awaitTermination (
105+ TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
106+ }
107+ }
91108 }
92109 }
93110
Original file line number Diff line number Diff line change 2626import com .google .api .client .json .GenericJson ;
2727import com .google .api .client .json .JsonFactory ;
2828import com .google .api .client .json .gson .GsonFactory ;
29+ import com .google .api .gax .core .BackgroundResource ;
2930import com .google .api .gax .core .FixedCredentialsProvider ;
3031import com .google .api .gax .rpc .ClientContext ;
3132import com .google .auth .Credentials ;
@@ -85,9 +86,25 @@ void setup(@TempDir Path tempDir) throws IOException {
8586
8687 @ AfterEach
8788 void tearDown () throws InterruptedException {
88- if (client != null ) {
89- client .close ();
90- client .awaitTermination (TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
89+ try {
90+ if (client != null ) {
91+ client .close ();
92+ client .awaitTermination (TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
93+ }
94+ } finally {
95+ if (context != null ) {
96+ // EchoStubSettings.newBuilder(context) configures a FixedTransportChannelProvider using the
97+ // channel from ClientContext. FixedTransportChannelProvider disables auto-closing
98+ // (shouldAutoClose() == false), so closing the client does not close the channel. We must
99+ // manually shut down the background resources owned by ClientContext.
100+ for (BackgroundResource resource : context .getBackgroundResources ()) {
101+ resource .shutdown ();
102+ }
103+ for (BackgroundResource resource : context .getBackgroundResources ()) {
104+ resource .awaitTermination (
105+ TestClientInitializer .AWAIT_TERMINATION_SECONDS , TimeUnit .SECONDS );
106+ }
107+ }
91108 }
92109 }
93110
You can’t perform that action at this time.
0 commit comments