Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions google/cloud/storage/async/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ AsyncClient::ResumeAppendableObjectUpload(BucketName const& bucket_name,
append_object_spec.set_object(std::move(object_name));
append_object_spec.set_generation(generation);

return ResumeAppendableObjectUpload(std::move(request), std::move(opts));
}

future<StatusOr<std::pair<AsyncWriter, AsyncToken>>>
AsyncClient::ResumeAppendableObjectUpload(
google::storage::v2::BidiWriteObjectRequest request, Options opts) {
return connection_
->ResumeAppendableObjectUpload(
{std::move(request),
Expand Down
15 changes: 14 additions & 1 deletion google/cloud/storage/async/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,27 @@ class AsyncClient {
* @param bucket_name the name of the bucket that contains the object.
* @param object_name the name of the object to be uploaded.
* @param generation the object generation to be uploaded.
* @param opts options controlling the behaviour of this RPC, for example the
* @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(BucketName const& bucket_name,
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 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