Skip to content

Commit 5d0d507

Browse files
committed
Fix grpc test failure
1 parent 68edf95 commit 5d0d507

12 files changed

+89
-45
lines changed

ci/cloudbuild/builds/lib/integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ source module ci/lib/io.sh
3131
export PATH="${HOME}/.local/bin:${PATH}"
3232
python3 -m pip uninstall -y --quiet googleapis-storage-testbench
3333
python3 -m pip install --upgrade --user --quiet --disable-pip-version-check \
34-
"git+https://github.com/googleapis/storage-testbench@v0.58.0"
34+
"git+https://github.com/googleapis/storage-testbench@v0.59.0"
3535

3636
# Some of the tests will need a valid roots.pem file.
3737
rm -f /dev/shm/roots.pem

google/cloud/storage/client.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "google/cloud/storage/internal/signed_url_requests.h"
2222
#include "google/cloud/storage/internal/storage_connection.h"
2323
#include "google/cloud/storage/internal/tuple_filter.h"
24-
#include "google/cloud/storage/list_buckets_partial_reader.h"
24+
#include "google/cloud/storage/list_buckets_extended_reader.h"
2525
#include "google/cloud/storage/list_buckets_reader.h"
2626
#include "google/cloud/storage/list_hmac_keys_reader.h"
2727
#include "google/cloud/storage/list_objects_and_prefixes_reader.h"
@@ -392,28 +392,28 @@ class Client {
392392
* @snippet storage_bucket_samples.cc list buckets partial result
393393
*/
394394
template <typename... Options>
395-
ListBucketsPartialReader ListBucketsPartial(Options&&... options) {
395+
ListBucketsExtendedReader ListBucketsExtended(Options&&... options) {
396396
auto opts = SpanOptions(std::forward<Options>(options)...);
397397
auto project_id = storage_internal::RequestProjectId(
398398
GCP_ERROR_INFO(), opts, std::forward<Options>(options)...);
399399
if (!project_id) {
400400
return google::cloud::internal::MakeErrorPaginationRange<
401-
ListBucketsPartialReader>(std::move(project_id).status());
401+
ListBucketsExtendedReader>(std::move(project_id).status());
402402
}
403403
google::cloud::internal::OptionsSpan const span(std::move(opts));
404404

405405
internal::ListBucketsRequest request(*std::move(project_id));
406406
request.set_multiple_options(std::forward<Options>(options)...);
407407
auto& client = connection_;
408408
return google::cloud::internal::MakePaginationRange<
409-
ListBucketsPartialReader>(
409+
ListBucketsExtendedReader>(
410410
request,
411411
[client](internal::ListBucketsRequest const& r) {
412412
return client->ListBuckets(r);
413413
},
414-
[](internal::ListBucketsResponse r) {
415-
return std::vector<BucketsPartial>{
416-
BucketsPartial{std::move(r.items), std::move(r.unreachable)}};
414+
[](internal::ListBucketsResponse res) {
415+
return std::vector<BucketsExtended>{
416+
BucketsExtended{std::move(res.items), std::move(res.unreachable)}};
417417
});
418418
}
419419

google/cloud/storage/examples/storage_bucket_samples.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "google/cloud/storage/client.h"
1616
#include "google/cloud/storage/examples/storage_examples_common.h"
17-
#include "google/cloud/storage/list_buckets_partial_reader.h"
17+
#include "google/cloud/storage/list_buckets_extended_reader.h"
1818
#include "google/cloud/internal/getenv.h"
1919
#include <functional>
2020
#include <iostream>
@@ -49,14 +49,14 @@ void ListBuckets(google::cloud::storage::Client client,
4949
(std::move(client));
5050
}
5151

52-
void ListBucketsPartial(google::cloud::storage::Client client,
53-
std::vector<std::string> const& /*argv*/) {
52+
void ListBucketsExtended(google::cloud::storage::Client client,
53+
std::vector<std::string> const& /*argv*/) {
5454
//! [list buckets partial result] [START storage_list_buckets_partial_success]
5555
namespace gcs = ::google::cloud::storage;
5656
using ::google::cloud::StatusOr;
5757
[](gcs::Client client) {
5858
int count = 0;
59-
gcs::ListBucketsPartialReader bucket_list = client.ListBucketsPartial();
59+
gcs::ListBucketsExtendedReader bucket_list = client.ListBucketsExtended();
6060
for (auto&& result : bucket_list) {
6161
if (!result) throw std::move(result).status();
6262

@@ -712,8 +712,8 @@ void RunAll(std::vector<std::string> const& argv) {
712712
std::cout << "\nRunning ListBuckets() example" << std::endl;
713713
ListBuckets(client, {});
714714

715-
std::cout << "\nRunning ListBucketsPartial() example" << std::endl;
716-
ListBucketsPartial(client, {});
715+
std::cout << "\nRunning ListBucketsExtended() example" << std::endl;
716+
ListBucketsExtended(client, {});
717717

718718
std::cout << "\nRunning CreateBucket() example" << std::endl;
719719
CreateBucket(client, {bucket_name});
@@ -758,8 +758,8 @@ int main(int argc, char* argv[]) {
758758

759759
examples::Example example({
760760
examples::CreateCommandEntry("list-buckets", {}, ListBuckets),
761-
examples::CreateCommandEntry("list-buckets-partial", {},
762-
ListBucketsPartial),
761+
examples::CreateCommandEntry("list-buckets-extended", {},
762+
ListBucketsExtended),
763763
examples::CreateCommandEntry("list-buckets-for-project", {"<project-id>"},
764764
ListBucketsForProject),
765765
make_entry("create-bucket", {}, CreateBucket),

google/cloud/storage/google_cloud_cpp_storage.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ google_cloud_cpp_storage_hdrs = [
116116
"internal/unified_rest_credentials.h",
117117
"internal/well_known_parameters_impl.h",
118118
"lifecycle_rule.h",
119-
"list_buckets_partial_reader.h",
119+
"list_buckets_extended_reader.h",
120120
"list_buckets_reader.h",
121121
"list_hmac_keys_reader.h",
122122
"list_objects_and_prefixes_reader.h",

google/cloud/storage/google_cloud_cpp_storage.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ add_library(
198198
internal/win32/hash_function_impl.cc
199199
lifecycle_rule.cc
200200
lifecycle_rule.h
201-
list_buckets_partial_reader.h
201+
list_buckets_extended_reader.h
202202
list_buckets_reader.cc
203203
list_buckets_reader.h
204204
list_hmac_keys_reader.cc
@@ -507,7 +507,7 @@ if (BUILD_TESTING)
507507
internal/tuple_filter_test.cc
508508
internal/unified_rest_credentials_test.cc
509509
lifecycle_rule_test.cc
510-
list_buckets_partial_reader_test.cc
510+
list_buckets_extended_reader_test.cc
511511
list_buckets_reader_test.cc
512512
list_hmac_keys_reader_test.cc
513513
list_objects_and_prefixes_reader_test.cc

google/cloud/storage/internal/connection_impl_bucket_test.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ TEST(StorageConnectionImpl, ListBucketPermanentFailure) {
6666
EXPECT_THAT(permanent.captured_authority_options(), RetryLoopUsesOptions());
6767
}
6868

69+
TEST(StorageConnectionImpl, ListBucketsPartialResult) {
70+
auto mock = std::make_unique<MockGenericStub>();
71+
EXPECT_CALL(*mock, options);
72+
EXPECT_CALL(*mock, ListBuckets)
73+
.WillOnce([](rest_internal::RestContext&, Options const&,
74+
ListBucketsRequest const& r) {
75+
EXPECT_TRUE(r.return_partial_success());
76+
ListBucketsResponse response;
77+
response.items.emplace_back(BucketMetadata{});
78+
response.unreachable.emplace_back("projects/_/buckets/bucket1");
79+
return response;
80+
});
81+
auto client =
82+
StorageConnectionImpl::Create(std::move(mock), RetryTestOptions());
83+
google::cloud::internal::OptionsSpan span(client->options());
84+
auto response = client->ListBuckets(
85+
ListBucketsRequest("test-project").set_option(ReturnPartialSuccess(true)));
86+
ASSERT_TRUE(response.ok());
87+
EXPECT_EQ(1, response->items.size());
88+
EXPECT_THAT(response->unreachable, ::testing::ElementsAre("projects/_/buckets/bucket1"));
89+
}
90+
6991
TEST(StorageConnectionImpl, CreateBucketTooManyFailures) {
7092
auto transient = MockRetryClientFunction(TransientError());
7193
auto mock = std::make_unique<MockGenericStub>();

google/cloud/storage/internal/grpc/bucket_request_parser.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ storage::internal::ListBucketsResponse FromProto(
427427
[&](google::storage::v2::Bucket const& b) {
428428
return storage_internal::FromProto(b, current_options);
429429
});
430+
for (auto const& u : response.unreachable()) {
431+
result.unreachable.push_back(u);
432+
}
430433
return result;
431434
}
432435

google/cloud/storage/internal/grpc/bucket_request_parser_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,25 @@ TEST(GrpcBucketRequestParser, ListBucketsResponse) {
229229
EXPECT_THAT(names, ElementsAre("test-bucket-1", "test-bucket-2"));
230230
}
231231

232+
TEST(GrpcBucketRequestParser, ListBucketsPartialResult) {
233+
google::storage::v2::ListBucketsResponse input;
234+
ASSERT_TRUE(TextFormat::ParseFromString(
235+
R"pb(
236+
buckets {
237+
name: "projects/_/buckets/test-bucket-1"
238+
bucket_id: "test-bucket-1"
239+
}
240+
next_page_token: "test-token"
241+
unreachable: "projects/_/buckets/unreachable-bucket-1"
242+
unreachable: "projects/_/buckets/unreachable-bucket-2"
243+
)pb",
244+
&input));
245+
246+
auto const actual = FromProto(input);
247+
EXPECT_EQ(actual.next_page_token, "test-token");
248+
EXPECT_THAT(actual.unreachable, ElementsAre("projects/_/buckets/unreachable-bucket-1", "projects/_/buckets/unreachable-bucket-2"));
249+
}
250+
232251
TEST(GrpcBucketRequestParser, LockBucketRetentionPolicyRequestAllOptions) {
233252
google::storage::v2::LockBucketRetentionPolicyRequest expected;
234253
ASSERT_TRUE(TextFormat::ParseFromString(

google/cloud/storage/list_buckets_partial_reader.h renamed to google/cloud/storage/list_buckets_extended_reader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_LIST_BUCKETS_PARTIAL_READER_H
16-
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_LIST_BUCKETS_PARTIAL_READER_H
15+
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_LIST_BUCKETS_EXTENDED_READER_H
16+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_LIST_BUCKETS_EXTENDED_READER_H
1717

1818
#include "google/cloud/storage/bucket_metadata.h"
1919
#include "google/cloud/storage/version.h"
@@ -26,15 +26,15 @@ namespace cloud {
2626
namespace storage {
2727
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2828

29-
struct BucketsPartial {
29+
struct BucketsExtended {
3030
std::vector<BucketMetadata> buckets;
3131
std::vector<std::string> unreachable;
3232
};
3333

34-
using ListBucketsPartialReader =
35-
google::cloud::internal::PaginationRange<BucketsPartial>;
34+
using ListBucketsExtendedReader =
35+
google::cloud::internal::PaginationRange<BucketsExtended>;
3636

37-
using ListBucketsPartialIterator = ListBucketsPartialReader::iterator;
37+
using ListBucketsExtendedIterator = ListBucketsExtendedReader::iterator;
3838

3939
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
4040
} // namespace storage

google/cloud/storage/list_buckets_partial_reader_test.cc renamed to google/cloud/storage/list_buckets_extended_reader_test.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "google/cloud/storage/list_buckets_partial_reader.h"
15+
#include "google/cloud/storage/list_buckets_extended_reader.h"
1616
#include "google/cloud/storage/internal/bucket_metadata_parser.h"
1717
#include "google/cloud/storage/testing/canonical_errors.h"
1818
#include "google/cloud/storage/testing/mock_client.h"
@@ -47,13 +47,13 @@ BucketMetadata CreateElement(int index) {
4747
return internal::BucketMetadataParser::FromJson(metadata).value();
4848
}
4949

50-
TEST(ListBucketsPartialReaderTest, Basic) {
50+
TEST(ListBucketsExtendedReaderTest, Basic) {
5151
// We will have 3 pages.
5252
// Page 0: 2 buckets, 1 unreachable
5353
// Page 1: 1 bucket, 0 unreachable
5454
// Page 2: 0 buckets, 1 unreachable
5555

56-
std::vector<BucketsPartial> expected;
56+
std::vector<BucketsExtended> expected;
5757

5858
// Page 0
5959
expected.push_back({{CreateElement(0), CreateElement(1)}, {"region-a"}});
@@ -84,18 +84,18 @@ TEST(ListBucketsPartialReaderTest, Basic) {
8484
.WillOnce(create_mock(2));
8585

8686
auto reader =
87-
google::cloud::internal::MakePaginationRange<ListBucketsPartialReader>(
87+
google::cloud::internal::MakePaginationRange<ListBucketsExtendedReader>(
8888
ListBucketsRequest("test-project"),
8989
[mock](ListBucketsRequest const& r) { return mock->ListBuckets(r); },
9090
[](internal::ListBucketsResponse r) {
91-
std::vector<BucketsPartial> result;
91+
std::vector<BucketsExtended> result;
9292
if (r.items.empty() && r.unreachable.empty()) return result;
9393
result.push_back(
94-
BucketsPartial{std::move(r.items), std::move(r.unreachable)});
94+
BucketsExtended{std::move(r.items), std::move(r.unreachable)});
9595
return result;
9696
});
9797

98-
std::vector<BucketsPartial> actual;
98+
std::vector<BucketsExtended> actual;
9999
for (auto&& page : reader) {
100100
ASSERT_STATUS_OK(page);
101101
actual.push_back(*std::move(page));
@@ -108,30 +108,30 @@ TEST(ListBucketsPartialReaderTest, Basic) {
108108
}
109109
}
110110

111-
TEST(ListBucketsPartialReaderTest, Empty) {
111+
TEST(ListBucketsExtendedReaderTest, Empty) {
112112
auto mock = std::make_shared<MockClient>();
113113
EXPECT_CALL(*mock, ListBuckets)
114114
.WillOnce(Return(make_status_or(ListBucketsResponse())));
115115

116116
auto reader =
117-
google::cloud::internal::MakePaginationRange<ListBucketsPartialReader>(
117+
google::cloud::internal::MakePaginationRange<ListBucketsExtendedReader>(
118118
ListBucketsRequest("test-project"),
119119
[mock](ListBucketsRequest const& r) { return mock->ListBuckets(r); },
120120
[](internal::ListBucketsResponse r) {
121-
std::vector<BucketsPartial> result;
121+
std::vector<BucketsExtended> result;
122122
if (r.items.empty() && r.unreachable.empty()) return result;
123123
result.push_back(
124-
BucketsPartial{std::move(r.items), std::move(r.unreachable)});
124+
BucketsExtended{std::move(r.items), std::move(r.unreachable)});
125125
return result;
126126
});
127127

128128
auto count = std::distance(reader.begin(), reader.end());
129129
EXPECT_EQ(0, count);
130130
}
131131

132-
TEST(ListBucketsPartialReaderTest, PermanentFailure) {
133-
// Create a synthetic list of BucketsPartial elements.
134-
std::vector<BucketsPartial> expected;
132+
TEST(ListBucketsExtendedReaderTest, PermanentFailure) {
133+
// Create a synthetic list of BucketsExtended elements.
134+
std::vector<BucketsExtended> expected;
135135

136136
// Page 0
137137
expected.push_back({{CreateElement(0), CreateElement(1)}, {"region-a"}});
@@ -157,17 +157,17 @@ TEST(ListBucketsPartialReaderTest, PermanentFailure) {
157157
});
158158

159159
auto reader =
160-
google::cloud::internal::MakePaginationRange<ListBucketsPartialReader>(
160+
google::cloud::internal::MakePaginationRange<ListBucketsExtendedReader>(
161161
ListBucketsRequest("test-project"),
162162
[mock](ListBucketsRequest const& r) { return mock->ListBuckets(r); },
163163
[](internal::ListBucketsResponse r) {
164-
std::vector<BucketsPartial> result;
164+
std::vector<BucketsExtended> result;
165165
if (r.items.empty() && r.unreachable.empty()) return result;
166166
result.push_back(
167-
BucketsPartial{std::move(r.items), std::move(r.unreachable)});
167+
BucketsExtended{std::move(r.items), std::move(r.unreachable)});
168168
return result;
169169
});
170-
std::vector<BucketsPartial> actual;
170+
std::vector<BucketsExtended> actual;
171171
bool has_status_or_error = false;
172172
for (auto&& page : reader) {
173173
if (page.ok()) {

0 commit comments

Comments
 (0)