Skip to content

Commit 3d93e58

Browse files
committed
Don't Checkin - API Implementation for ResumeAppendableObjectUpload
1 parent 2426f6e commit 3d93e58

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

google/cloud/storage/async/client.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ AsyncClient::ResumeAppendableObjectUpload(BucketName const& bucket_name,
165165
});
166166
}
167167

168+
future<StatusOr<std::pair<AsyncWriter, AsyncToken>>>
169+
AsyncClient::ResumeAppendableObjectUpload(
170+
google::storage::v2::BidiWriteObjectRequest request, Options opts) {
171+
return connection_
172+
->ResumeAppendableObjectUpload(
173+
{std::move(request),
174+
internal::MergeOptions(std::move(opts), connection_->options())})
175+
.then([](auto f) -> StatusOr<std::pair<AsyncWriter, AsyncToken>> {
176+
auto w = f.get();
177+
if (!w) return std::move(w).status();
178+
auto t = storage_internal::MakeAsyncToken(w->get());
179+
return std::make_pair(AsyncWriter(*std::move(w)), std::move(t));
180+
});
181+
}
182+
168183
future<StatusOr<std::pair<AsyncWriter, AsyncToken>>>
169184
AsyncClient::StartBufferedUpload(BucketName const& bucket_name,
170185
std::string object_name, Options opts) {

google/cloud/storage/async/client.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,19 @@ class AsyncClient {
440440
std::string object_name, std::int64_t generation,
441441
Options opts = {});
442442

443+
/**
444+
* Resume a resumable upload session for appendable objects and automatic
445+
* recovery from transient failures.
446+
*
447+
* @param request the request contents, it must include the bucket name,
448+
* object name, and generation. Many other fields are optional.
449+
* @param opts options controlling the behaviour of this RPC, for example the
450+
* application may change the retry policy.
451+
*/
452+
future<StatusOr<std::pair<AsyncWriter, AsyncToken>>>
453+
ResumeAppendableObjectUpload(
454+
google::storage::v2::BidiWriteObjectRequest request, Options opts = {});
455+
443456
/*
444457
[start-buffered-upload-common]
445458
This function always uses [resumable uploads][resumable-link]. The objects

google/cloud/storage/async/client_test.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,55 @@ TEST(AsyncClient, ResumeRewrite2) {
13981398
}
13991399

14001400
} // namespace
1401+
1402+
TEST(AsyncClient, ResumeAppendableObjectUpload2) {
1403+
auto constexpr kExpectedRequest = R"pb(
1404+
append_object_spec {
1405+
bucket: "projects/_/buckets/test-bucket",
1406+
object: "test-object",
1407+
generation: 42
1408+
}
1409+
flush: true
1410+
)pb";
1411+
auto mock = std::make_shared<MockAsyncConnection>();
1412+
EXPECT_CALL(*mock, options)
1413+
.WillRepeatedly(
1414+
Return(Options{}.set<TestOption<0>>("O0").set<TestOption<1>>("O1")));
1415+
1416+
EXPECT_CALL(*mock, ResumeAppendableObjectUpload)
1417+
.WillOnce([&](AsyncConnection::AppendableUploadParams const& p) {
1418+
EXPECT_THAT(p.options.get<TestOption<0>>(), "O0");
1419+
EXPECT_THAT(p.options.get<TestOption<1>>(), "O1-function");
1420+
EXPECT_THAT(p.options.get<TestOption<2>>(), "O2-function");
1421+
auto expected = google::storage::v2::BidiWriteObjectRequest{};
1422+
EXPECT_TRUE(TextFormat::ParseFromString(kExpectedRequest, &expected));
1423+
EXPECT_THAT(p.request, IsProtoEqual(expected));
1424+
auto writer = std::make_unique<MockAsyncWriterConnection>();
1425+
EXPECT_CALL(*writer, PersistedState)
1426+
.WillRepeatedly(Return(TestProtoObject()));
1427+
1428+
return make_ready_future(make_status_or(
1429+
std::unique_ptr<AsyncWriterConnection>(std::move(writer))));
1430+
});
1431+
1432+
auto client = AsyncClient(mock);
1433+
auto request = google::storage::v2::BidiWriteObjectRequest{};
1434+
ASSERT_TRUE(TextFormat::ParseFromString(kExpectedRequest, &request));
1435+
auto wt = client
1436+
.ResumeAppendableObjectUpload(
1437+
std::move(request), Options{}
1438+
.set<TestOption<1>>("O1-function")
1439+
.set<TestOption<2>>("O2-function"))
1440+
.get();
1441+
ASSERT_STATUS_OK(wt);
1442+
AsyncWriter w;
1443+
AsyncToken t;
1444+
std::tie(w, t) = *std::move(wt);
1445+
EXPECT_TRUE(t.valid());
1446+
EXPECT_THAT(w.PersistedState(), VariantWith<google::storage::v2::Object>(
1447+
IsProtoEqual(TestProtoObject())));
1448+
}
1449+
14011450
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
14021451
} // namespace storage_experimental
14031452
} // namespace cloud

0 commit comments

Comments
 (0)