-
Notifications
You must be signed in to change notification settings - Fork 86
feat: add support for partial success in ListBuckets for json #3404
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
nidhiii-27
wants to merge
12
commits into
googleapis:main
Choose a base branch
from
nidhiii-27:list-buckets
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.
+197
−5
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6e7855b
feat: add support for partial list bucket for json
nidhiii-27 32e668b
chore: add tests
nidhiii-27 c8b7b1c
chore: modify tests
nidhiii-27 718869a
chore: change function name to a more apt name
nidhiii-27 8b6f8fc
chore: correct formatting
nidhiii-27 a32f7e6
check test failure
nidhiii-27 cbee8f5
fix lint error
nidhiii-27 45fedcf
chore: add unit test
nidhiii-27 41f9fbb
chore: review fixes
nidhiii-27 d3245b4
chore: review fixes
nidhiii-27 5180f5e
chore: review fixes
nidhiii-27 4eaa511
chore: review fixes
nidhiii-27 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
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
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
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
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
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
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
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
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
98 changes: 98 additions & 0 deletions
98
google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITListBucketTest.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 2025 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.it; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import com.google.api.gax.paging.Page; | ||
| import com.google.cloud.storage.Bucket; | ||
| import com.google.cloud.storage.BucketInfo; | ||
| import com.google.cloud.storage.Storage; | ||
| import com.google.cloud.storage.TransportCompatibility.Transport; | ||
| import com.google.cloud.storage.it.runner.StorageITRunner; | ||
| import com.google.cloud.storage.it.runner.annotations.Backend; | ||
| import com.google.cloud.storage.it.runner.annotations.CrossRun; | ||
| import com.google.cloud.storage.it.runner.annotations.Inject; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.Iterables; | ||
| import java.util.stream.StreamSupport; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(StorageITRunner.class) | ||
| @CrossRun( | ||
| backends = {Backend.TEST_BENCH}, | ||
| transports = {Transport.HTTP}) | ||
| public class ITListBucketTest { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a testcase with multiple unreachable buckets |
||
| @Inject public Storage storage; | ||
|
|
||
| private static final String NORMAL_BUCKET_NAME = "normal_bucket"; | ||
| // For testing purposes, the TESTBENCH considers a bucket to be unreachable if the bucket name | ||
| // contains "unreachable" | ||
| private static final String UNREACHABLE_BUCKET_NAME = "unreachable_bucket"; | ||
|
|
||
| // The unreachable buckets are returned as a list of bucket resource names in string form. (e.g. | ||
| // "projects/_/buckets/bucket1") | ||
| private static final String EXPECTED_UNREACHABLE_BUCKET_NAME = | ||
| "projects/_/buckets/" + UNREACHABLE_BUCKET_NAME; | ||
nidhiii-27 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Before | ||
| public void setup() { | ||
| Bucket normalBucket = storage.create(BucketInfo.of(NORMAL_BUCKET_NAME)); | ||
| Bucket unreachableBucket = storage.create(BucketInfo.of(UNREACHABLE_BUCKET_NAME)); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| BucketCleaner.doCleanup(NORMAL_BUCKET_NAME, storage); | ||
| BucketCleaner.doCleanup(UNREACHABLE_BUCKET_NAME, storage); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListBucketWithPartialSuccess() { | ||
| Page<Bucket> page = storage.list(Storage.BucketListOption.returnPartialSuccess(true)); | ||
| Iterable<Bucket> allBuckets = page.getValues(); | ||
|
|
||
| Bucket actualNormalBucket = | ||
| Iterables.getOnlyElement( | ||
| Iterables.filter(allBuckets, b -> b.getName().equals(NORMAL_BUCKET_NAME))); | ||
|
|
||
| Bucket actualUnreachableBucket = | ||
| Iterables.getOnlyElement( | ||
| Iterables.filter(allBuckets, b -> b.getName().contains(UNREACHABLE_BUCKET_NAME))); | ||
|
|
||
| assertThat(actualNormalBucket.getName()).isEqualTo(NORMAL_BUCKET_NAME); | ||
| assertThat(actualUnreachableBucket.getName()).isEqualTo(EXPECTED_UNREACHABLE_BUCKET_NAME); | ||
| assertTrue( | ||
| "The unreachable bucket must have the isUnreachable flag set to true", | ||
| actualUnreachableBucket.isUnreachable()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListBucketWithoutPartialSuccess() { | ||
| Page<Bucket> page = storage.list(); | ||
| ImmutableList<String> bucketNames = | ||
| StreamSupport.stream(page.iterateAll().spliterator(), false) | ||
| .map(Bucket::getName) | ||
| .collect(ImmutableList.toImmutableList()); | ||
| assertThat(bucketNames).contains(NORMAL_BUCKET_NAME); | ||
nidhiii-27 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assertThat(bucketNames).doesNotContain(EXPECTED_UNREACHABLE_BUCKET_NAME); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spoke about this offline as well, but we need to update the logic here to handle the bucket resource names the same way grpc does.
On line https://github.com/googleapis/java-storage/pull/3404/files#diff-02854c6353038f671563a52b22658f9dcb49e66d8eb45a822439e90aa60b11f6R612 we need to add change the first line to be
BucketInfo.Builder to = new BucketInfo.BuilderImpl(bucketNameCodec.decode(from.getName()));like injava-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java
Line 322 in 3a95990
Even in grpc we don't expose
projects/_/buckets/everything is normalized to json style bucket names.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this does deviate from how the API returns the value, and possibly how other languages have exposed things. This change does mean that the Storage sdk here is internally consistent, and customers can reliably use bucket names regardless of unavailability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in PR #3415