4545import com .google .api .gax .resumable .QueryStatusRequest ;
4646import com .google .api .gax .resumable .QueryStatusResponse ;
4747import com .google .api .gax .resumable .ResumableUploadSession ;
48+ import com .google .api .gax .resumable .ResumableUploadStatus ;
4849import com .google .api .gax .rpc .AbortedException ;
4950import com .google .api .gax .rpc .ApiCallContext ;
50- import com .google .api .gax .rpc .ApiException ;
5151import com .google .api .gax .rpc .ClientContext ;
5252import com .google .api .gax .rpc .InternalException ;
5353import com .google .api .gax .rpc .NotFoundException ;
@@ -260,8 +260,8 @@ void uploadChunk_intermediateChunk_sendsUploadCommandAndReturnsActiveStatus() {
260260
261261 ChunkUploadResponse <String > response = client .uploadChunkCallable ().call (request );
262262
263- assertThat (response .isComplete ()).isFalse ();
264263 assertThat (response .getResponse ()).isNull ();
264+ assertThat (response .getUploadStatus ()).isEqualTo (ResumableUploadStatus .ACTIVE );
265265
266266 assertThat (transport .capturedUrl ).isEqualTo (TEST_UPLOAD_URL );
267267 assertThat (transport .capturedHeaders .get ("x-goog-upload-command" )).containsExactly ("upload" );
@@ -289,9 +289,9 @@ void uploadChunk_finalChunk_sendsUploadFinalizeAndReturnsResponseBody() {
289289
290290 ChunkUploadResponse <String > response = client .uploadChunkCallable ().call (request );
291291
292- assertThat (response .isComplete ()).isTrue ();
293292 assertThat (response .getResponse ())
294293 .isEqualTo ("{\" name\" :\" uploaded-file.txt\" ,\" size\" :524288}" );
294+ assertThat (response .getUploadStatus ()).isEqualTo (ResumableUploadStatus .FINAL );
295295
296296 assertThat (transport .capturedHeaders .get ("x-goog-upload-command" ))
297297 .containsExactly ("upload, finalize" );
@@ -318,9 +318,9 @@ void uploadChunk_emptyPayloadFinal_sendsFinalizeCommandAndReturnsResponseBody()
318318
319319 ChunkUploadResponse <String > response = client .uploadChunkCallable ().call (request );
320320
321- assertThat (response .isComplete ()).isTrue ();
322321 assertThat (response .getResponse ())
323322 .isEqualTo ("{\" name\" :\" uploaded-file.txt\" ,\" size\" :1048576}" );
323+ assertThat (response .getUploadStatus ()).isEqualTo (ResumableUploadStatus .FINAL );
324324
325325 assertThat (transport .capturedHeaders .get ("x-goog-upload-command" )).containsExactly ("finalize" );
326326 assertThat (transport .capturedHeaders ).doesNotContainKey ("x-goog-upload-offset" );
@@ -379,7 +379,7 @@ void uploadChunk_serverReturnsConflictOrError_throwsException() {
379379 }
380380
381381 @ Test
382- void uploadChunk_missingUploadStatusHeader_throwsInternalException () {
382+ void uploadChunk_missingUploadStatusHeader_returnsUnknownUploadStatusOnHttp200 () {
383383 MockLowLevelHttpResponse httpResponse = new MockLowLevelHttpResponse ();
384384 httpResponse .setStatusCode (200 );
385385
@@ -391,39 +391,10 @@ void uploadChunk_missingUploadStatusHeader_throwsInternalException() {
391391 .setOffset (0L )
392392 .build ();
393393
394- ExecutionException exception =
395- assertThrows (
396- ExecutionException .class , () -> client .uploadChunkCallable ().futureCall (request ).get ());
397-
398- assertThat (exception .getCause ()).isInstanceOf (InternalException .class );
399- assertThat (exception .getCause ())
400- .hasMessageThat ()
401- .contains ("Upload chunk response did not contain valid X-Goog-Upload-Status header" );
402- }
403-
404- @ Test
405- void uploadChunk_serverReturnsFinalStatusOnNon200_marksExceptionNonRetryable () {
406- MockLowLevelHttpResponse httpResponse = new MockLowLevelHttpResponse ();
407- httpResponse .setStatusCode (503 );
408- httpResponse .addHeader ("X-Goog-Upload-Status" , "final" );
409- httpResponse .setContent ("{\" error\" :{\" message\" :\" Upload rejected by backend\" }}" );
410-
411- HttpJsonResumableUploadClient <TestRequest , String > client = createClient (httpResponse );
412- ChunkUploadRequest request =
413- ChunkUploadRequest .newBuilder ()
414- .setUploadUrl (TEST_UPLOAD_URL )
415- .setPayload ("data" .getBytes (StandardCharsets .UTF_8 ))
416- .setOffset (0L )
417- .build ();
418-
419- ExecutionException exception =
420- assertThrows (
421- ExecutionException .class , () -> client .uploadChunkCallable ().futureCall (request ).get ());
394+ ChunkUploadResponse <String > response = client .uploadChunkCallable ().call (request );
422395
423- assertThat (exception .getCause ()).isInstanceOf (ApiException .class );
424- ApiException apiException = (ApiException ) exception .getCause ();
425- assertThat (apiException .isRetryable ()).isFalse ();
426- assertThat (apiException .getStatusCode ().getCode ()).isEqualTo (StatusCode .Code .UNAVAILABLE );
396+ assertThat (response .getResponse ()).isNull ();
397+ assertThat (response .getUploadStatus ()).isEqualTo (ResumableUploadStatus .UNKNOWN );
427398 }
428399
429400 @ Test
@@ -439,9 +410,9 @@ void queryStatus_activeUpload_returnsCommittedOffset() {
439410
440411 QueryStatusResponse <String > response = client .queryStatusCallable ().call (request );
441412
442- assertThat (response .isComplete ()).isFalse ();
443413 assertThat (response .getCommittedOffset ()).isEqualTo (524288L );
444414 assertThat (response .getResponse ()).isNull ();
415+ assertThat (response .getUploadStatus ()).isEqualTo (ResumableUploadStatus .ACTIVE );
445416
446417 assertThat (transport .capturedHeaders .get ("x-goog-upload-command" )).containsExactly ("query" );
447418 }
@@ -458,10 +429,10 @@ void queryStatus_finalUpload_returnsCompleteAndResponseBody() {
458429
459430 QueryStatusResponse <String > response = client .queryStatusCallable ().call (request );
460431
461- assertThat (response .isComplete ()).isTrue ();
462432 assertThat (response .getCommittedOffset ()).isNull ();
463433 assertThat (response .getResponse ())
464434 .isEqualTo ("{\" name\" :\" uploaded-file.txt\" ,\" size\" :1048576}" );
435+ assertThat (response .getUploadStatus ()).isEqualTo (ResumableUploadStatus .FINAL );
465436 }
466437
467438 @ Test
0 commit comments