Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions google/cloud/storage/async/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ AsyncClient::ResumeAppendableObjectUpload(BucketName const& bucket_name,
});
}

future<StatusOr<std::pair<AsyncWriter, AsyncToken>>>
AsyncClient::ResumeAppendableObjectUpload(
google::storage::v2::BidiWriteObjectRequest request, Options opts) {
return connection_
->ResumeAppendableObjectUpload(
{std::move(request),
internal::MergeOptions(std::move(opts), connection_->options())})
.then([](auto f) -> StatusOr<std::pair<AsyncWriter, AsyncToken>> {
auto w = f.get();
if (!w) return std::move(w).status();
auto t = storage_internal::MakeAsyncToken(w->get());
return std::make_pair(AsyncWriter(*std::move(w)), std::move(t));
});
}

future<StatusOr<std::pair<AsyncWriter, AsyncToken>>>
AsyncClient::StartBufferedUpload(BucketName const& bucket_name,
std::string object_name, Options opts) {
Expand Down
13 changes: 13 additions & 0 deletions google/cloud/storage/async/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,19 @@ class AsyncClient {
std::string object_name, std::int64_t generation,
Options opts = {});

/**
* Resume a resumable upload session for appendable objects and automatic
* recovery from transient failures.
*
* @param request the request contents, it must include the bucket name,
* object name, and generation. Many other fields are optional.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention, append_object_spec is required, write_object_spec would not work here.

* @param opts options controlling the behaviour of this RPC, for example the
* application may change the retry policy.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a spelling inconsistency. This comment uses "behaviour" (British English), but other comments in this file and codebase use "behavior" (American English). For consistency, it's best to use one spelling throughout the project.

   * @param opts options controlling the behavior of this RPC, for example the
   * application may change the retry policy.

*/
future<StatusOr<std::pair<AsyncWriter, AsyncToken>>>
ResumeAppendableObjectUpload(
google::storage::v2::BidiWriteObjectRequest request, Options opts = {});

/*
[start-buffered-upload-common]
This function always uses [resumable uploads][resumable-link]. The objects
Expand Down
49 changes: 49 additions & 0 deletions google/cloud/storage/async/client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,55 @@ TEST(AsyncClient, ResumeRewrite2) {
}

} // namespace

TEST(AsyncClient, ResumeAppendableObjectUpload2) {
auto constexpr kExpectedRequest = R"pb(
append_object_spec {
bucket: "projects/_/buckets/test-bucket",
object: "test-object",
generation: 42
}
flush: true
)pb";
auto mock = std::make_shared<MockAsyncConnection>();
EXPECT_CALL(*mock, options)
.WillRepeatedly(
Return(Options{}.set<TestOption<0>>("O0").set<TestOption<1>>("O1")));

EXPECT_CALL(*mock, ResumeAppendableObjectUpload)
.WillOnce([&](AsyncConnection::AppendableUploadParams const& p) {
EXPECT_THAT(p.options.get<TestOption<0>>(), "O0");
EXPECT_THAT(p.options.get<TestOption<1>>(), "O1-function");
EXPECT_THAT(p.options.get<TestOption<2>>(), "O2-function");
auto expected = google::storage::v2::BidiWriteObjectRequest{};
EXPECT_TRUE(TextFormat::ParseFromString(kExpectedRequest, &expected));
EXPECT_THAT(p.request, IsProtoEqual(expected));
auto writer = std::make_unique<MockAsyncWriterConnection>();
EXPECT_CALL(*writer, PersistedState)
.WillRepeatedly(Return(TestProtoObject()));

return make_ready_future(make_status_or(
std::unique_ptr<AsyncWriterConnection>(std::move(writer))));
});

auto client = AsyncClient(mock);
auto request = google::storage::v2::BidiWriteObjectRequest{};
ASSERT_TRUE(TextFormat::ParseFromString(kExpectedRequest, &request));
auto wt = client
.ResumeAppendableObjectUpload(
std::move(request), Options{}
.set<TestOption<1>>("O1-function")
.set<TestOption<2>>("O2-function"))
.get();
ASSERT_STATUS_OK(wt);
AsyncWriter w;
AsyncToken t;
std::tie(w, t) = *std::move(wt);
EXPECT_TRUE(t.valid());
EXPECT_THAT(w.PersistedState(), VariantWith<google::storage::v2::Object>(
IsProtoEqual(TestProtoObject())));
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace storage_experimental
} // namespace cloud
Expand Down