-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(gax): add ResumableUploadStatus and progress tracking support #14209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
whowes
wants to merge
1
commit into
whowes/resumable-upload-query
from
whowes/resumable-upload-status
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...-java/gax/src/main/java/com/google/api/gax/resumable/ResumableUploadProgressListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package com.google.api.gax.resumable; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** A callback listener for observing the progress and state transitions of a resumable upload. */ | ||
| @BetaApi | ||
| @FunctionalInterface | ||
| @NullMarked | ||
| public interface ResumableUploadProgressListener { | ||
|
|
||
| /** | ||
| * Invoked when upload progress or state changes. | ||
| * | ||
| * @param status the current status snapshot of the upload | ||
| */ | ||
| void onProgress(ResumableUploadStatus status); | ||
| } |
98 changes: 98 additions & 0 deletions
98
...m-java/gax-java/gax/src/main/java/com/google/api/gax/resumable/ResumableUploadStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package com.google.api.gax.resumable; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.auto.value.AutoValue; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** Status snapshot of an ongoing or completed resumable upload session. */ | ||
| @BetaApi | ||
| @NullMarked | ||
| @AutoValue | ||
| public abstract class ResumableUploadStatus { | ||
|
|
||
| /** The state of the resumable upload session. */ | ||
| public enum State { | ||
| /** Session initiation is in progress (acquiring upload session URL). */ | ||
| STARTING, | ||
|
|
||
| /** Transmitting chunk payloads to the server. */ | ||
| UPLOADING, | ||
|
|
||
| /** A recoverable error occurred; querying server status and resynchronizing offset. */ | ||
| RECOVERING, | ||
|
|
||
| /** The server query status succeeded and the committed offset was received. */ | ||
| OFFSET_RECEIVED, | ||
|
|
||
| /** The upload was successfully finalized by the server. */ | ||
| FINALIZED, | ||
|
|
||
| /** The upload failed unrecoverably or was cancelled. */ | ||
| FAILED | ||
| } | ||
|
|
||
| /** | ||
| * Returns the negotiated upload session URI, or {@code null} if session initiation is pending. | ||
| */ | ||
| public abstract @Nullable String getUploadUrl(); | ||
|
|
||
| /** Returns the number of bytes successfully uploaded to the server so far. */ | ||
| public abstract long getBytesUploaded(); | ||
|
|
||
| /** Returns the current state of the upload session. */ | ||
| public abstract State getState(); | ||
|
|
||
| /** Returns the exception that triggered recovery or caused failure, if any. */ | ||
| public abstract @Nullable Throwable getException(); | ||
|
|
||
| public abstract Builder toBuilder(); | ||
|
|
||
| public static Builder newBuilder() { | ||
| return new AutoValue_ResumableUploadStatus.Builder() | ||
| .setBytesUploaded(0L) | ||
| .setState(State.STARTING); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| public abstract Builder setUploadUrl(@Nullable String uploadUrl); | ||
|
|
||
| public abstract Builder setBytesUploaded(long bytesUploaded); | ||
|
|
||
| public abstract Builder setState(State state); | ||
|
|
||
| public abstract Builder setException(@Nullable Throwable exception); | ||
|
|
||
| public abstract ResumableUploadStatus build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...va/gax-java/gax/src/test/java/com/google/api/gax/resumable/ResumableUploadStatusTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package com.google.api.gax.resumable; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ResumableUploadStatusTest { | ||
|
|
||
| @Test | ||
| void builder_defaults() { | ||
| ResumableUploadStatus status = ResumableUploadStatus.newBuilder().build(); | ||
| assertThat(status.getUploadUrl()).isNull(); | ||
| assertThat(status.getBytesUploaded()).isEqualTo(0L); | ||
| assertThat(status.getState()).isEqualTo(ResumableUploadStatus.State.STARTING); | ||
| assertThat(status.getException()).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void builder_explicitValuesAndToBuilder() { | ||
| Exception ex = new RuntimeException("test error"); | ||
| ResumableUploadStatus status = | ||
| ResumableUploadStatus.newBuilder() | ||
| .setUploadUrl("https://upload.url/session-1") | ||
| .setBytesUploaded(1024L) | ||
| .setState(ResumableUploadStatus.State.UPLOADING) | ||
| .setException(ex) | ||
| .build(); | ||
|
|
||
| assertThat(status.getUploadUrl()).isEqualTo("https://upload.url/session-1"); | ||
| assertThat(status.getBytesUploaded()).isEqualTo(1024L); | ||
| assertThat(status.getState()).isEqualTo(ResumableUploadStatus.State.UPLOADING); | ||
| assertThat(status.getException()).isSameInstanceAs(ex); | ||
|
|
||
| ResumableUploadStatus modified = | ||
| status.toBuilder() | ||
| .setState(ResumableUploadStatus.State.FINALIZED) | ||
| .setBytesUploaded(2048L) | ||
| .build(); | ||
|
|
||
| assertThat(modified.getState()).isEqualTo(ResumableUploadStatus.State.FINALIZED); | ||
| assertThat(modified.getBytesUploaded()).isEqualTo(2048L); | ||
| assertThat(modified.getUploadUrl()).isEqualTo("https://upload.url/session-1"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.