This repository was archived by the owner on Feb 24, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
google-cloud-bigquerystorage/src
main/java/com/google/cloud/bigquery/storage/v1
test/java/com/google/cloud/bigquery/storage/v1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -353,7 +353,7 @@ public void run() {
353353 } finally {
354354 lock .unlock ();
355355 }
356- cleanupInflightRequests ( );
356+ cleanup ( /* waitForDone= */ false );
357357 });
358358 this .appendThread .start ();
359359 }
@@ -812,7 +812,10 @@ private void appendLoop() {
812812 this .streamConnection .send (originalRequestBuilder .build ());
813813 }
814814 }
815+ cleanup (/* waitForDone= */ true );
816+ }
815817
818+ private void cleanup (boolean waitForDone ) {
816819 log .info (
817820 "Cleanup starts. Stream: "
818821 + streamName
@@ -828,7 +831,9 @@ private void appendLoop() {
828831 // We can close the stream connection and handle the remaining inflight requests.
829832 if (streamConnection != null ) {
830833 this .streamConnection .close ();
831- waitForDoneCallback (3 , TimeUnit .MINUTES );
834+ if (waitForDone ) {
835+ waitForDoneCallback (3 , TimeUnit .MINUTES );
836+ }
832837 }
833838
834839 // At this point, there cannot be more callback. It is safe to clean up all inflight requests.
Original file line number Diff line number Diff line change @@ -650,9 +650,9 @@ public void testThrowExceptionWhileWithinAppendLoop_MaxWaitTimeExceed() throws E
650650 null ,
651651 client .getSettings (),
652652 retrySettings );
653- testBigQueryWrite .setResponseSleep (org .threeten .bp .Duration .ofSeconds (3 ));
653+ testBigQueryWrite .setResponseSleep (org .threeten .bp .Duration .ofSeconds (2 ));
654654
655- long appendCount = 10 ;
655+ long appendCount = 2 ;
656656 for (int i = 0 ; i < appendCount ; i ++) {
657657 testBigQueryWrite .addResponse (createAppendResponse (i ));
658658 }
@@ -691,6 +691,10 @@ public void testThrowExceptionWhileWithinAppendLoop_MaxWaitTimeExceed() throws E
691691 100 )
692692 .get ());
693693 assertThat (ex .getCause ()).hasMessageThat ().contains ("Request has waited in inflight queue" );
694+
695+ // Verify we can shutdown normally.
696+ connectionWorker .close ();
697+ assertTrue (connectionWorker .isUserClosed ());
694698 }
695699
696700 @ Test
You can’t perform that action at this time.
0 commit comments