-
Notifications
You must be signed in to change notification settings - Fork 88
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
Changes from 8 commits
6e7855b
32e668b
c8b7b1c
718869a
8b6f8fc
a32f7e6
cbee8f5
45fedcf
41f9fbb
d3245b4
5180f5e
4eaa511
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -674,6 +674,9 @@ private BucketInfo bucketInfoDecode(com.google.api.services.storage.model.Bucket | |||
| ifNonNull(from.getObjectRetention(), this::objectRetentionDecode, to::setObjectRetention); | ||||
| ifNonNull(from.getSoftDeletePolicy(), this::softDeletePolicyDecode, to::setSoftDeletePolicy); | ||||
| ifNonNull(from.getIpFilter(), ipFilterCodec::decode, to::setIpFilter); | ||||
| if (from.containsKey("isUnreachable")) { | ||||
| to.setIsUnreachable(Boolean.TRUE); | ||||
| } | ||||
|
Collaborator
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. 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 java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcConversions.java Line 322 in 3a95990
Even in grpc we don't expose
Collaborator
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. 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.
Contributor
Author
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. Done in PR #3415 |
||||
| return to.build(); | ||||
| } | ||||
|
|
||||
|
|
||||
| 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 { | ||
|
Collaborator
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)); | ||
| System.out.println("page: " + page); | ||
| Iterable<Bucket> allBuckets = page.getValues(); | ||
|
|
||
| Bucket actualNormalBucket = | ||
| Iterables.getOnlyElement( | ||
| Iterables.filter(allBuckets, b -> b.getName().equals(NORMAL_BUCKET_NAME))); | ||
| assertThat(actualNormalBucket.getName()).isEqualTo(NORMAL_BUCKET_NAME); | ||
|
|
||
| Bucket actualUnreachableBucket = | ||
| Iterables.getOnlyElement( | ||
| Iterables.filter(allBuckets, b -> b.getName().contains(UNREACHABLE_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); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.