Skip to content

Commit ef60ec3

Browse files
committed
fixing presubmits
1 parent f0acefb commit ef60ec3

2 files changed

Lines changed: 55 additions & 53 deletions

File tree

google/cloud/storage/async/client.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class AsyncClient {
371371
std::int64_t limit, Options opts = {});
372372

373373
/*
374-
[start-appendable-object-upload]
374+
create-and-write-appendable-object]
375375
Initiates a [resumable upload][resumable-link] for an appendable object.
376376
377377
Appendable objects allow you to create an object and upload data to it
@@ -385,21 +385,21 @@ class AsyncClient {
385385
closure of the streaming RPC used for the upload.
386386
387387
@par Example
388-
@snippet storage_async_samples.cc start-appendable-object-upload
388+
@snippet storage_async_samples.cc create-and-write-appendable-object
389389
390390
@par Idempotency
391391
This function is always treated as idempotent, and the library will
392392
automatically retry the function on transient errors.
393393
394394
[resumable-link]: https://cloud.google.com/storage/docs/resumable-uploads
395-
[start-appendable-object-upload]
395+
[create-and-write-appendable-object]
396396
*/
397397

398398
/**
399399
* Starts a new resumable upload session for appendable objects and
400400
* automatic recovery from transient failures.
401401
*
402-
* @snippet{doc} async/client.h start-appendable-object-upload
402+
* @snippet{doc} async/client.h create-and-write-appendable-object
403403
*
404404
* @param bucket_name the name of the bucket that contains the object.
405405
* @param object_name the name of the object to be uploaded.
@@ -414,7 +414,7 @@ class AsyncClient {
414414
* Starts a new resumable upload session for appendable objects and
415415
* automatic recovery from transient failures.
416416
*
417-
* @snippet{doc} async/client.h start-appendable-object-upload
417+
* @snippet{doc} async/client.h create-and-write-appendable-object
418418
*
419419
* @param request the request contents, it must include the bucket name and
420420
* object name. Many other fields are optional.

google/cloud/storage/examples/storage_async_samples.cc

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! [async-includes]
1919
#include "google/cloud/storage/async/client.h"
2020
#include "google/cloud/storage/async/read_all.h"
21-
#include "google/cloud/future.h"
21+
2222
//! [async-includes]
2323
#include "google/cloud/storage/examples/storage_examples_common.h"
2424
#include "google/cloud/internal/getenv.h"
@@ -155,14 +155,6 @@ void InsertObjectVectorVectors(
155155
(client, argv.at(0), argv.at(1));
156156
}
157157

158-
void OpenObjectMultipleRangedRead(
159-
google::cloud::storage_experimental::AsyncClient& client,
160-
std::vector<std::string> const& argv);
161-
162-
void OpenMultipleObjectRangedRead(
163-
google::cloud::storage_experimental::AsyncClient& client,
164-
std::vector<std::string> const& argv);
165-
166158
#if GOOGLE_CLOUD_CPP_HAVE_COROUTINES
167159
void OpenObjectSingleRangedRead(
168160
google::cloud::storage_experimental::AsyncClient& client,
@@ -325,9 +317,11 @@ void OpenMultipleObjectRangedRead(
325317
};
326318
auto coro = [&count_newlines](
327319
gcs_ex::AsyncClient& client, std::string bucket_name,
328-
std::string object_name1, std::string object_name2, std::string object_name3) -> google::cloud::future<void> {
320+
std::string object_name1, std::string object_name2,
321+
std::string object_name3) -> google::cloud::future<void> {
329322
// List of object names to read (passed as arguments)
330-
std::vector<std::string> object_names = {object_name1, object_name2, object_name3};
323+
std::vector<std::string> object_names = {object_name1, object_name2,
324+
object_name3};
331325
std::vector<google::cloud::future<std::uint64_t>> futures;
332326

333327
// Start ranged reads for all objects and collect futures
@@ -702,7 +696,8 @@ void CreateAndWriteAppendableObject(
702696
// [START storage_create_and_write_appendable_object]
703697
namespace gcs_ex = google::cloud::storage_experimental;
704698
auto coro = [](gcs_ex::AsyncClient& client, std::string bucket_name,
705-
std::string object_name) -> google::cloud::future<void> {
699+
std::string object_name)
700+
-> google::cloud::future<google::storage::v2::Object> {
706701
auto [writer, token] = (co_await client.StartAppendableObjectUpload(
707702
gcs_ex::BucketName(std::move(bucket_name)),
708703
std::move(object_name)))
@@ -731,12 +726,14 @@ void CreateAndWriteAppendableObject(
731726
std::cout << "Wrote more data.\n";
732727

733728
// Finalize the upload to make it a regular object.
734-
auto object = (co_await writer.Finalize(std::move(token))).value();
735-
std::cout << "Upload finalized: " << object.DebugString() << "\n";
729+
co_await writer.Finalize(std::move(token))).value();
736730
};
737731
// [END storage_create_and_write_appendable_object]
738732
//! [create-and-write-appendable-object]
739-
coro(client, argv.at(0), argv.at(1)).get();
733+
// The example is easier to test and run if we call the coroutine and block
734+
// until it completes..
735+
auto const object = coro(client, argv.at(0), argv.at(1)).get();
736+
std::cout << "File successfully uploaded " << object.DebugString() << "\n";
740737
}
741738

742739
void PauseAndResumeAppendableUpload(
@@ -790,7 +787,11 @@ void PauseAndResumeAppendableUpload(
790787
};
791788
// [END storage_pause_and_resume_appendable_upload]
792789
//! [pause-and-resume-appendable-upload]
793-
coro(client, argv.at(0), argv.at(1)).get();
790+
// The example is easier to test and run if we call the coroutine and block
791+
// until it completes.
792+
auto const object = coro(client, argv.at(0), argv.at(1)).get();
793+
std::cout << "File successfully uploaded and finalized "
794+
<< object.DebugString() << "\n";
794795
}
795796

796797
void FinalizeAppendableObjectUpload(
@@ -1019,7 +1020,7 @@ std::string SuspendBufferedUpload(
10191020
google::cloud::storage_experimental::AsyncClient&,
10201021
std::vector<std::string> const&) {
10211022
std::cerr
1022-
<< "AsyncClient::SuspendBufferedUpload() example requires coroutines\n";
1023+
<< "AsyncClient::StartBufferedUpload() example requires coroutines\n";
10231024
return {};
10241025
}
10251026

@@ -1052,27 +1053,27 @@ void ResumeUnbufferedUpload(google::cloud::storage_experimental::AsyncClient&,
10521053
void CreateAndWriteAppendableObject(
10531054
google::cloud::storage_experimental::AsyncClient&,
10541055
std::vector<std::string> const&) {
1055-
std::cerr << "create-and-write-appendable-object example requires "
1056+
std::cerr << "AsyncClient::CreateAndWriteAppendableObject() example requires "
10561057
"coroutines\n";
10571058
}
10581059

10591060
void PauseAndResumeAppendableUpload(
10601061
google::cloud::storage_experimental::AsyncClient&,
10611062
std::vector<std::string> const&) {
1062-
std::cerr << "pause-and-resume-appendable-upload example requires "
1063+
std::cerr << "AsyncClient::PauseAndResumeAppendableUpload() example requires "
10631064
"coroutines\n";
10641065
}
10651066

10661067
void FinalizeAppendableObjectUpload(
10671068
google::cloud::storage_experimental::AsyncClient&,
10681069
std::vector<std::string> const&) {
1069-
std::cerr << "finalize-appendable-object-upload example requires "
1070+
std::cerr << "AsyncClient::FinalizeAppendableObjectUpload() example requires "
10701071
"coroutines\n";
10711072
}
10721073

10731074
void ReadObjectTail(google::cloud::storage_experimental::AsyncClient&,
10741075
std::vector<std::string> const&) {
1075-
std::cerr << "read-object-tail example requires coroutines\n";
1076+
std::cerr << "AsyncClient::ReadObjectTail() example requires coroutines\n";
10761077
}
10771078

10781079
void RewriteObject(google::cloud::storage_experimental::AsyncClient&,
@@ -1084,7 +1085,7 @@ void ResumeRewrite(google::cloud::storage_experimental::AsyncClient&,
10841085
std::vector<std::string> const&) {
10851086
std::cerr << "AsyncClient::ResumeRewrite() example requires coroutines\n";
10861087
}
1087-
#endif // GOOGLE_CLOUD_CPP_HAVE_COROUTINES
1088+
#endif // GOOGLE_CLOUD_CPP
10881089

10891090
void ComposeObject(google::cloud::storage_experimental::AsyncClient& client,
10901091
std::vector<std::string> const& argv) {
@@ -1299,7 +1300,7 @@ void AutoRun(std::vector<std::string> const& argv) {
12991300
if (!response.ok()) throw std::move(response).status();
13001301

13011302
auto const metadata = response->metadata();
1302-
if (metadata.has_value()) {
1303+
if (!metadata.has_value()) {
13031304
std::cout << "Running the ReadObjectWithOptions() example" << std::endl;
13041305
ReadObjectWithOptions(client, {bucket_name, metadata->name(),
13051306
std::to_string(metadata->generation())});
@@ -1322,7 +1323,7 @@ void AutoRun(std::vector<std::string> const& argv) {
13221323
auto upload_id = SuspendBufferedUpload(client, {bucket_name, object_name});
13231324

13241325
std::cout << "Running the ResumeBufferedUpload() example" << std::endl;
1325-
ResumeBufferedUpload(client, {upload_id});
1326+
ResumeUnbufferedUpload(client, {upload_id});
13261327
scheduled_for_delete.push_back(std::move(object_name));
13271328
object_name = examples::MakeRandomObjectName(generator, "object-");
13281329

@@ -1338,11 +1339,33 @@ void AutoRun(std::vector<std::string> const& argv) {
13381339
std::cout << "Running the ResumeUnbufferedUpload() example" << std::endl;
13391340
ResumeUnbufferedUpload(client, {upload_id, filename});
13401341
scheduled_for_delete.push_back(std::move(object_name));
1342+
object_name = examples::MakeRandomObjectName(generator, "object-");
13411343

13421344
std::cout << "Removing local file" << std::endl;
13431345
(void)std::remove(filename.c_str());
13441346
}
13451347

1348+
std::cout << "Running the RewriteObject() example" << std::endl;
1349+
RewriteObject(client, {bucket_name, composed_name, object_name});
1350+
scheduled_for_delete.push_back(std::move(object_name));
1351+
object_name = examples::MakeRandomObjectName(generator, "object-");
1352+
1353+
std::cout << "Running the ResumeRewrite() example" << std::endl;
1354+
auto const rewrite_source = object_name;
1355+
(void)client
1356+
.InsertObject(
1357+
google::cloud::storage_experimental::BucketName(bucket_name),
1358+
object_name, std::string(4 * 1024 * 1024, 'A'))
1359+
.get()
1360+
.value();
1361+
scheduled_for_delete.push_back(std::move(object_name));
1362+
object_name = examples::MakeRandomObjectName(generator, "object-");
1363+
1364+
auto const dest = examples::MakeRandomObjectName(generator, "object-");
1365+
ResumeRewrite(client, {bucket_name, rewrite_source, object_name});
1366+
scheduled_for_delete.push_back(std::move(object_name));
1367+
object_name = examples::MakeRandomObjectName(generator, "object-");
1368+
13461369
if (examples::UsingEmulator()) {
13471370
std::cout << "\nRunning appendable object samples..." << std::endl;
13481371
object_name = examples::MakeRandomObjectName(generator, "object-");
@@ -1378,28 +1401,6 @@ void AutoRun(std::vector<std::string> const& argv) {
13781401
object_name = examples::MakeRandomObjectName(generator, "object-");
13791402
}
13801403

1381-
std::cout << "Running the RewriteObject() example" << std::endl;
1382-
// Create a large-ish source object for the rewrite.
1383-
auto const rewrite_source = object_name;
1384-
std::vector<char> data(2 * 1024 * 1024, 'A');
1385-
(void)client
1386-
.InsertObject(
1387-
google::cloud::storage_experimental::BucketName(bucket_name),
1388-
rewrite_source, std::string{data.begin(), data.end()})
1389-
.get()
1390-
.value();
1391-
scheduled_for_delete.push_back(rewrite_source);
1392-
object_name = examples::MakeRandomObjectName(generator, "object-");
1393-
1394-
RewriteObject(client, {bucket_name, rewrite_source, object_name});
1395-
scheduled_for_delete.push_back(std::move(object_name));
1396-
object_name = examples::MakeRandomObjectName(generator, "object-");
1397-
1398-
std::cout << "Running the ResumeRewrite() example" << std::endl;
1399-
ResumeRewrite(client, {bucket_name, rewrite_source, object_name});
1400-
scheduled_for_delete.push_back(std::move(object_name));
1401-
object_name = examples::MakeRandomObjectName(generator, "object-");
1402-
14031404
std::cout << "Running ComposeObjectRequest() example" << std::endl;
14041405
auto const to_delete = object_name;
14051406
ComposeObjectRequest(client, {bucket_name, object_name, o1, o2});
@@ -1480,7 +1481,8 @@ int main(int argc, char* argv[]) try {
14801481
make_entry("open-object-multiple-ranged-read", {},
14811482
OpenObjectMultipleRangedRead),
14821483
make_entry("open-object-read-full-object", {}, OpenObjectReadFullObject),
1483-
make_entry("open-multiple-object-ranged-read", {"<object-name-1>", "<object-name-2>", "<object-name-3>"},
1484+
make_entry("open-multiple-object-ranged-read",
1485+
{"<object-name-1>", "<object-name-2>", "<object-name-3>"},
14841486
OpenMultipleObjectRangedRead),
14851487
make_entry("read-object", {}, ReadObject),
14861488
make_entry("read-all", {}, ReadAll),
@@ -1496,7 +1498,7 @@ int main(int argc, char* argv[]) try {
14961498
make_resume_entry("resume-buffered-upload", {}, ResumeBufferedUpload),
14971499

14981500
make_entry("start-unbuffered-upload", {"<filename>"},
1499-
StartUnbufferedUpload),
1501+
StartBufferedUpload),
15001502
make_entry("suspend-unbuffered-upload", {}, SuspendUnbufferedUpload),
15011503
make_resume_entry("resume-unbuffered-upload", {"<filename>"},
15021504
ResumeUnbufferedUpload),

0 commit comments

Comments
 (0)