Skip to content

Commit 21df0c9

Browse files
committed
feat(gax): add ResumableUploadCallable, ResumableUploadFuture, and ResumableUploadCallSettings
Add ResumableUploadFuture interface for upload progress, session URL inspection, and cancellation. Update ResumableUploadCallable to return ResumableUploadFuture and include resumeCall(sessionUrl, payload, settings).
1 parent 49be37a commit 21df0c9

4 files changed

Lines changed: 272 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google LLC nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.rpc;
31+
32+
import com.google.api.core.BetaApi;
33+
import com.google.auto.value.AutoValue;
34+
35+
/**
36+
* A settings class to configure a {@link ResumableUploadCallable} for executing resumable
37+
* uploads. Encapsulates protocol options such as payload chunk size.
38+
*/
39+
@BetaApi
40+
@AutoValue
41+
public abstract class ResumableUploadCallSettings {
42+
private static final int DEFAULT_CHUNK_SIZE = 8 * 1024 * 1024; // 8 MB
43+
44+
/** Returns the configured chunk size in bytes (defaults to 8 MB / 8,388,608 bytes). */
45+
public abstract int getChunkSize();
46+
47+
/**
48+
* Merges another {@code ResumableUploadCallSettings} instance with this one.
49+
* Fields set in {@code other} override fields in this instance.
50+
*
51+
* @param other settings to overlay; may be {@code null}
52+
* @return a new, resolved {@code ResumableUploadCallSettings} instance
53+
*/
54+
public ResumableUploadCallSettings merge(ResumableUploadCallSettings other) {
55+
if (other == null) {
56+
return this;
57+
}
58+
return toBuilder().setChunkSize(other.getChunkSize()).build();
59+
}
60+
61+
public abstract Builder toBuilder();
62+
63+
public static Builder newBuilder() {
64+
return new AutoValue_ResumableUploadCallSettings.Builder()
65+
.setChunkSize(DEFAULT_CHUNK_SIZE);
66+
}
67+
68+
/** Builder for {@link ResumableUploadCallSettings}. */
69+
@AutoValue.Builder
70+
public abstract static class Builder {
71+
public abstract Builder setChunkSize(int chunkSize);
72+
73+
public abstract int getChunkSize();
74+
75+
public abstract ResumableUploadCallSettings build();
76+
}
77+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google LLC nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.rpc;
31+
32+
import com.google.api.core.BetaApi;
33+
import java.io.InputStream;
34+
35+
/**
36+
* A ResumableUploadCallable is an API-transport-independent wrapper for the Resumable Upload
37+
* protocol. Operates directly on the request object and input stream payload.
38+
*
39+
* @param <RequestT> request type
40+
* @param <ResponseT> response type
41+
*/
42+
@BetaApi
43+
public abstract class ResumableUploadCallable<RequestT, ResponseT> {
44+
45+
protected ResumableUploadCallable() {}
46+
47+
/**
48+
* Performs a new resumable upload asynchronously.
49+
*
50+
* @param request the request message
51+
* @param payload the data payload input stream
52+
* @param settings call settings overrides; may be {@code null}
53+
* @return future for tracking and controlling the upload
54+
*/
55+
public abstract ResumableUploadFuture<ResponseT> futureCall(
56+
RequestT request, InputStream payload, ResumableUploadCallSettings settings);
57+
58+
/**
59+
* Resumes an existing resumable upload session asynchronously using a saved session URL.
60+
*
61+
* @param sessionUrl the upload session URL
62+
* @param payload the data payload input stream
63+
* @param settings call settings overrides; may be {@code null}
64+
* @return future for tracking and controlling the upload
65+
*/
66+
public abstract ResumableUploadFuture<ResponseT> resumeCall(
67+
String sessionUrl, InputStream payload, ResumableUploadCallSettings settings);
68+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google LLC nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.rpc;
31+
32+
import com.google.api.core.ApiFuture;
33+
import com.google.api.core.BetaApi;
34+
35+
/**
36+
* A specialized {@link ApiFuture} for tracking and controlling an in-flight resumable upload.
37+
*
38+
* @param <ResponseT> response type
39+
*/
40+
@BetaApi
41+
public interface ResumableUploadFuture<ResponseT> extends ApiFuture<ResponseT> {
42+
43+
/**
44+
* Returns the upload session URL, or {@code null} if the session initiation is still in progress.
45+
*/
46+
String getUploadSessionUrl();
47+
48+
/** Returns the current committed byte offset reported by the server. */
49+
long getCommittedOffset();
50+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google LLC nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.google.api.gax.rpc;
31+
32+
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertSame;
34+
35+
import org.junit.jupiter.api.Test;
36+
37+
public class ResumableUploadCallSettingsTest {
38+
39+
@Test
40+
public void testDefaultChunkSizeInBuilder() {
41+
ResumableUploadCallSettings settings = ResumableUploadCallSettings.newBuilder().build();
42+
43+
assertEquals(8 * 1024 * 1024, settings.getChunkSize());
44+
}
45+
46+
@Test
47+
public void testCustomInitialization() {
48+
ResumableUploadCallSettings settings =
49+
ResumableUploadCallSettings.newBuilder().setChunkSize(16 * 1024 * 1024).build();
50+
51+
assertEquals(16 * 1024 * 1024, settings.getChunkSize());
52+
}
53+
54+
@Test
55+
public void testMerge_NullSettings() {
56+
ResumableUploadCallSettings stubSettings =
57+
ResumableUploadCallSettings.newBuilder().setChunkSize(4 * 1024 * 1024).build();
58+
59+
ResumableUploadCallSettings merged = stubSettings.merge(null);
60+
61+
assertSame(stubSettings, merged);
62+
}
63+
64+
@Test
65+
public void testMerge_SettingsOverrides() {
66+
ResumableUploadCallSettings stubSettings =
67+
ResumableUploadCallSettings.newBuilder().setChunkSize(4 * 1024 * 1024).build();
68+
69+
ResumableUploadCallSettings perRequestSettings =
70+
ResumableUploadCallSettings.newBuilder().setChunkSize(32 * 1024 * 1024).build();
71+
72+
ResumableUploadCallSettings merged = stubSettings.merge(perRequestSettings);
73+
74+
// Chunk size overridden by Tier-1 per-request settings
75+
assertEquals(32 * 1024 * 1024, merged.getChunkSize());
76+
}
77+
}

0 commit comments

Comments
 (0)