Repository navigation
feat(storage): readSession can send first reads in the open request #14789
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
Open
Dhriti07
wants to merge
8
commits into
main
Choose a base branch
from
fast-open/01-first-reads-in-open
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+171
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
19a09bd
feat(storage): readSession can send fast open reads in the open request
50d6237
Merge branch 'main' into fast-open/01-first-reads-in-open
Dhriti07 80abfbf
Merge branch 'main' into fast-open/01-first-reads-in-open
Dhriti07 97b69f4
refactor(storage): rename fastOpenConfigs parameter to initialReadCon…
Dhriti07 90041a8
refactor(storage): accept bounded wildcard list in StorageDataClient.…
Dhriti07 a6a218a
test(storage): use try-with-resources for ObjectReadSession in ITFast…
Dhriti07 87c0da2
chore(storage): fix formatting of readSession javadoc in StorageDataC…
Dhriti07 d3d0e4a
Merge branch 'main' into fast-open/01-first-reads-in-open
Dhriti07 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
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
143 changes: 143 additions & 0 deletions
143
...orage/google-cloud-storage/src/test/java/com/google/cloud/storage/ITFastOpenFakeTest.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,143 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage; | ||
|
|
||
| import static com.google.cloud.storage.ByteSizeConstants._2MiB; | ||
| import static com.google.cloud.storage.ITObjectReadSessionFakeTest.getReadRange; | ||
| import static com.google.cloud.storage.PackagePrivateMethodWorkarounds.maybeGetStorageDataClient; | ||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
|
||
| import com.google.api.gax.grpc.GrpcCallContext; | ||
| import com.google.cloud.storage.ITObjectReadSessionFakeTest.FakeStorage; | ||
| import com.google.cloud.storage.it.ChecksummedTestContent; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.storage.v2.BidiReadObjectRequest; | ||
| import com.google.storage.v2.BidiReadObjectResponse; | ||
| import com.google.storage.v2.BidiReadObjectSpec; | ||
| import com.google.storage.v2.BucketName; | ||
| import com.google.storage.v2.Object; | ||
| import com.google.storage.v2.ObjectRangeData; | ||
| import io.grpc.stub.StreamObserver; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
| import org.junit.Test; | ||
|
|
||
| public final class ITFastOpenFakeTest { | ||
|
|
||
| private static final byte[] ALL_OBJECT_BYTES = DataGenerator.base64Characters().genBytes(64); | ||
| private static final Object METADATA = | ||
| Object.newBuilder() | ||
| .setBucket(BucketName.format("_", "b")) | ||
| .setName("o") | ||
| .setGeneration(1) | ||
| .setSize(_2MiB) | ||
| .build(); | ||
| private static final GrpcCallContext CTX = GrpcCallContext.createDefault(); | ||
|
|
||
| private static final BidiReadObjectRequest OPEN = | ||
| BidiReadObjectRequest.newBuilder() | ||
| .setReadObjectSpec( | ||
| BidiReadObjectSpec.newBuilder() | ||
| .setBucket(METADATA.getBucket()) | ||
| .setObject(METADATA.getName()) | ||
| .build()) | ||
| .build(); | ||
| private static final BidiReadObjectRequest OPEN_WITH_READ_OF_10_TO_20 = | ||
| OPEN.toBuilder().addReadRanges(getReadRange(1, 10, 10)).build(); | ||
|
|
||
| private static final ReadAsFutureBytes READ_10_TO_20 = | ||
| ReadProjectionConfigs.asFutureBytes().withRangeSpec(RangeSpec.of(10, 10)); | ||
|
|
||
| /** Every request the fake server received, in order. */ | ||
| private final List<BidiReadObjectRequest> requestsReceived = | ||
| Collections.synchronizedList(new ArrayList<>()); | ||
|
|
||
| @Test | ||
| public void openRequest_includesTheFastOpenRead() throws Exception { | ||
| FakeStorage server = | ||
| fakeServer(ImmutableMap.of(OPEN_WITH_READ_OF_10_TO_20, metadataAndBytes(1, 10, 10))); | ||
|
|
||
| try (FakeServer fakeServer = FakeServer.of(server); | ||
| Storage storage = fakeServer.getGrpcStorageOptions().getService()) { | ||
| StorageDataClient dataClient = maybeGetStorageDataClient(storage); | ||
|
|
||
| try (ObjectReadSession ignored = | ||
| dataClient.readSession(OPEN, CTX, ImmutableList.of(READ_10_TO_20)).get(5, SECONDS)) { | ||
| // open and close the session | ||
| } | ||
| } | ||
|
|
||
| assertThat(requestsReceived).containsExactly(OPEN_WITH_READ_OF_10_TO_20); | ||
| } | ||
|
|
||
| @Test | ||
| public void openRequest_withoutFastOpenReads_isUnchanged() throws Exception { | ||
| FakeStorage server = fakeServer(ImmutableMap.of(OPEN, metadataOnly())); | ||
|
|
||
| try (FakeServer fakeServer = FakeServer.of(server); | ||
| Storage storage = fakeServer.getGrpcStorageOptions().getService()) { | ||
| StorageDataClient dataClient = maybeGetStorageDataClient(storage); | ||
|
|
||
| try (ObjectReadSession ignored = | ||
| dataClient.readSession(OPEN, CTX, ImmutableList.of()).get(5, SECONDS)) { | ||
| // open and close the session | ||
| } | ||
| } | ||
|
|
||
| assertThat(requestsReceived).containsExactly(OPEN); | ||
| } | ||
|
|
||
| /** | ||
| * A fake server that answers each request in {@code responses} and adds it to {@link | ||
| * #requestsReceived}. Any other request is answered with an error. | ||
| */ | ||
| private FakeStorage fakeServer(Map<BidiReadObjectRequest, BidiReadObjectResponse> responses) { | ||
| ImmutableMap.Builder<BidiReadObjectRequest, Consumer<StreamObserver<BidiReadObjectResponse>>> | ||
| behaviour = ImmutableMap.builder(); | ||
| responses.forEach( | ||
| (request, response) -> | ||
| behaviour.put( | ||
| request, | ||
| client -> { | ||
| requestsReceived.add(request); | ||
| client.onNext(response); | ||
| })); | ||
| return FakeStorage.of(behaviour.buildOrThrow()); | ||
| } | ||
|
|
||
| private static BidiReadObjectResponse metadataOnly() { | ||
| return BidiReadObjectResponse.newBuilder().setMetadata(METADATA).build(); | ||
| } | ||
|
|
||
| /** The response to an open request that has a read of {@code [offset, offset + length)}. */ | ||
| private static BidiReadObjectResponse metadataAndBytes(int readId, int offset, int length) { | ||
| return BidiReadObjectResponse.newBuilder() | ||
| .setMetadata(METADATA) | ||
| .addObjectDataRanges( | ||
| ObjectRangeData.newBuilder() | ||
| .setChecksummedData( | ||
| ChecksummedTestContent.of(ALL_OBJECT_BYTES, offset, length).asChecksummedData()) | ||
| .setReadRange(getReadRange(readId, offset, length)) | ||
| .setRangeEnd(true)) | ||
| .build(); | ||
| } | ||
| } |
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.