Skip to content

Commit 3c174b0

Browse files
authored
impl: prepare for next Protobuf release (#11518)
On Windows, `GetCurrentTime()` is a macro. The current and previous releases of Protobuf undefine this macro in one of its headers. That was probably a bug in Protobuf. We use `TimeUtil::GetCurrentTime()`. With the next release of Protobuf that will expand the macro. We either need to prevent the macro expansion, using something like `(TimeUtil::GetCurrentTime)()`, or we need to avoid the function altogether.
1 parent cc61532 commit 3c174b0

6 files changed

Lines changed: 24 additions & 24 deletions

File tree

google/cloud/bigtable/admin/integration_tests/admin_backup_integration_test.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "google/cloud/internal/time_utils.h"
2222
#include "google/cloud/testing_util/chrono_literals.h"
2323
#include "google/cloud/testing_util/contains_once.h"
24+
#include "google/cloud/testing_util/is_proto_equal.h"
2425
#include "google/cloud/testing_util/status_matchers.h"
2526
#include <google/protobuf/util/time_util.h>
2627
#include <gmock/gmock.h>
@@ -33,8 +34,9 @@ namespace bigtable_admin {
3334
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3435
namespace {
3536

37+
using ::google::cloud::internal::ToProtoTimestamp;
3638
using ::google::cloud::testing_util::ContainsOnce;
37-
using ::google::protobuf::util::TimeUtil;
39+
using ::google::cloud::testing_util::IsProtoEqual;
3840
using ::testing::Contains;
3941
using ::testing::Not;
4042
namespace btadmin = ::google::bigtable::admin::v2;
@@ -97,12 +99,11 @@ TEST_F(AdminBackupIntegrationTest, CreateListGetUpdateRestoreDeleteBackup) {
9799
auto const backup_name = cluster_name + "/backups/" + backup_id;
98100

99101
// Create backup
100-
google::protobuf::Timestamp expire_time =
101-
TimeUtil::GetCurrentTime() + TimeUtil::HoursToDuration(12);
102+
auto expire_time = std::chrono::system_clock::now() + std::chrono::hours(12);
102103

103104
btadmin::Backup b;
104105
b.set_source_table(table_name);
105-
*b.mutable_expire_time() = expire_time;
106+
*b.mutable_expire_time() = ToProtoTimestamp(expire_time);
106107
auto backup =
107108
client_.CreateBackup(cluster_name, backup_id, std::move(b)).get();
108109
ASSERT_STATUS_OK(backup);
@@ -119,16 +120,17 @@ TEST_F(AdminBackupIntegrationTest, CreateListGetUpdateRestoreDeleteBackup) {
119120
EXPECT_EQ(backup->name(), backup_name);
120121

121122
// Update backup
122-
expire_time = expire_time + TimeUtil::HoursToDuration(12);
123-
*backup->mutable_expire_time() = expire_time;
123+
expire_time += std::chrono::hours(12);
124+
*backup->mutable_expire_time() = ToProtoTimestamp(expire_time);
124125
backup = client_.UpdateBackup(*backup, Mask("expire_time"));
125126
ASSERT_STATUS_OK(backup);
126127

127128
// Verify the update
128129
backup = client_.GetBackup(backup_name);
129130
ASSERT_STATUS_OK(backup);
130131
EXPECT_EQ(backup->name(), backup_name);
131-
EXPECT_EQ(backup->expire_time(), expire_time);
132+
EXPECT_THAT(backup->expire_time(),
133+
IsProtoEqual(ToProtoTimestamp(expire_time)));
132134

133135
// Delete table
134136
EXPECT_STATUS_OK(client_.DeleteTable(table_name));

google/cloud/bigtable/tests/admin_backup_integration_test.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "google/cloud/internal/time_utils.h"
2121
#include "google/cloud/testing_util/chrono_literals.h"
2222
#include "google/cloud/testing_util/contains_once.h"
23+
#include "google/cloud/testing_util/is_proto_equal.h"
2324
#include "google/cloud/testing_util/status_matchers.h"
24-
#include <google/protobuf/util/time_util.h>
2525
#include <gmock/gmock.h>
2626
#include <string>
2727
#include <vector>
@@ -32,8 +32,9 @@ namespace bigtable {
3232
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3333
namespace {
3434

35+
using ::google::cloud::internal::ToProtoTimestamp;
3536
using ::google::cloud::testing_util::ContainsOnce;
36-
using ::google::protobuf::util::TimeUtil;
37+
using ::google::cloud::testing_util::IsProtoEqual;
3738
using ::testing::Contains;
3839
using ::testing::Not;
3940
namespace btadmin = ::google::bigtable::admin::v2;
@@ -77,12 +78,10 @@ TEST_F(AdminBackupIntegrationTest, CreateListGetUpdateRestoreDeleteBackup) {
7778
auto const backup_name = cluster_name + "/backups/" + backup_id;
7879

7980
// Create backup
80-
google::protobuf::Timestamp expire_time =
81-
TimeUtil::GetCurrentTime() + TimeUtil::HoursToDuration(12);
81+
auto expire_time = std::chrono::system_clock::now() + std::chrono::hours(12);
8282

8383
auto backup = table_admin_->CreateBackup(
84-
{cluster_id, backup_id, table_id,
85-
google::cloud::internal::ToChronoTimePoint(expire_time)});
84+
{cluster_id, backup_id, table_id, expire_time});
8685
ASSERT_STATUS_OK(backup);
8786
EXPECT_EQ(backup->name(), backup_name);
8887

@@ -97,17 +96,16 @@ TEST_F(AdminBackupIntegrationTest, CreateListGetUpdateRestoreDeleteBackup) {
9796
EXPECT_EQ(backup->name(), backup_name);
9897

9998
// Update backup
100-
expire_time = expire_time + TimeUtil::HoursToDuration(12);
101-
backup = table_admin_->UpdateBackup(
102-
{cluster_id, backup_id,
103-
google::cloud::internal::ToChronoTimePoint(expire_time)});
99+
expire_time += std::chrono::hours(12);
100+
backup = table_admin_->UpdateBackup({cluster_id, backup_id, expire_time});
104101
ASSERT_STATUS_OK(backup);
105102

106103
// Verify the update
107104
backup = table_admin_->GetBackup(cluster_id, backup_id);
108105
ASSERT_STATUS_OK(backup);
109106
EXPECT_EQ(backup->name(), backup_name);
110-
EXPECT_EQ(backup->expire_time(), expire_time);
107+
EXPECT_THAT(backup->expire_time(),
108+
IsProtoEqual(ToProtoTimestamp(expire_time)));
111109

112110
// Delete table
113111
EXPECT_STATUS_OK(table_admin_->DeleteTable(table_id));

google/cloud/servicecontrol/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main(int argc, char* argv[]) try {
4646
op.set_operation_id("TODO-use-UUID-4-or-UUID-5");
4747
op.set_operation_name("google.pubsub.v1.Publisher.Publish");
4848
op.set_consumer_id(project.FullName());
49-
*op.mutable_start_time() = TimeUtil::GetCurrentTime();
49+
*op.mutable_start_time() = (TimeUtil::GetCurrentTime)();
5050
return op;
5151
}();
5252

google/cloud/servicecontrol/quickstart/quickstart.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, char* argv[]) try {
3838
op.set_operation_id("TODO-use-UUID-4-or-UUID-5");
3939
op.set_operation_name("google.pubsub.v1.Publisher.Publish");
4040
op.set_consumer_id(project.FullName());
41-
*op.mutable_start_time() = TimeUtil::GetCurrentTime();
41+
*op.mutable_start_time() = (TimeUtil::GetCurrentTime)();
4242
return op;
4343
}();
4444

google/cloud/trace/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ int main(int argc, char* argv[]) try {
5959
span.set_name(std::string{"projects/"} + argv[1] + "/traces/" +
6060
RandomHexDigits(gen, 32) + "/spans/" + span_id);
6161
span.set_span_id(std::move(span_id));
62-
*span.mutable_start_time() = TimeUtil::GetCurrentTime();
62+
*span.mutable_start_time() = (TimeUtil::GetCurrentTime)();
6363
// Simulate a call using a small sleep
6464
std::this_thread::sleep_for(std::chrono::milliseconds(2));
65-
*span.mutable_end_time() = TimeUtil::GetCurrentTime();
65+
*span.mutable_end_time() = (TimeUtil::GetCurrentTime)();
6666

6767
auto response = client.CreateSpan(span);
6868
if (!response) throw std::move(response).status();

google/cloud/trace/quickstart/quickstart.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ int main(int argc, char* argv[]) try {
4949
span.set_name(std::string{"projects/"} + argv[1] + "/traces/" +
5050
RandomHexDigits(gen, 32) + "/spans/" + span_id);
5151
span.set_span_id(std::move(span_id));
52-
*span.mutable_start_time() = TimeUtil::GetCurrentTime();
52+
*span.mutable_start_time() = (TimeUtil::GetCurrentTime)();
5353
// Simulate a call using a small sleep
5454
std::this_thread::sleep_for(std::chrono::milliseconds(2));
55-
*span.mutable_end_time() = TimeUtil::GetCurrentTime();
55+
*span.mutable_end_time() = (TimeUtil::GetCurrentTime)();
5656

5757
auto response = client.CreateSpan(span);
5858
if (!response) throw std::move(response).status();

0 commit comments

Comments
 (0)