Skip to content

Commit 2cf5521

Browse files
committed
feat(gax): add ResumableUploadCallable and ResumableUploadCallSettings
Clean up ResumableUploadCallSettingsTest JUnit 5 test suite by removing redundant equals/hashCode test for @autovalue. Add ResumableUploadCallable abstract base class.
1 parent 49be37a commit 2cf5521

3 files changed

Lines changed: 214 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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
import java.io.InputStream;
35+
36+
/**
37+
* A ResumableUploadCallable is an API-transport-independent wrapper for the Resumable Upload
38+
* protocol. Operates directly on the request object and input stream payload.
39+
*
40+
* @param <RequestT> request type
41+
* @param <ResponseT> response type
42+
*/
43+
@BetaApi
44+
public abstract class ResumableUploadCallable<RequestT, ResponseT> {
45+
46+
protected ResumableUploadCallable() {}
47+
48+
/**
49+
* Performs the resumable upload asynchronously with custom call settings.
50+
*
51+
* @param request the request message
52+
* @param payload the data payload input stream
53+
* @param settings call settings overrides; may be {@code null}
54+
* @return future for the response
55+
*/
56+
public abstract ApiFuture<ResponseT> futureCall(
57+
RequestT request,
58+
InputStream payload,
59+
ResumableUploadCallSettings settings);
60+
}
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)