Skip to content
Merged
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
49 changes: 14 additions & 35 deletions google/cloud/bigtable/internal/async_bulk_apply_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,40 +168,25 @@ class MockMetric : public Metric {
(const, override));
};

// This class is a vehicle to get a MockMetric into the OperationContext object.
class CloningMetric : public Metric {
public:
explicit CloningMetric(std::unique_ptr<MockMetric> metric)
: metric_(std::move(metric)) {}
std::unique_ptr<Metric> clone(TableResourceLabels const&,
TableDataLabels const&) const override {
return std::move(metric_);
}

private:
mutable std::unique_ptr<MockMetric> metric_;
};

#endif // GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS

TEST_F(AsyncBulkApplyTest, Success) {
bigtable::BulkMutation mut(IdempotentMutation("r0"),
IdempotentMutation("r1"));

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -263,19 +248,18 @@ TEST_F(AsyncBulkApplyTest, PartialStreamIsRetried) {
IdempotentMutation("r1"));

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(2);
EXPECT_CALL(*mock_metric, PostCall).Times(2);
EXPECT_CALL(*mock_metric, OnDone).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -365,19 +349,18 @@ TEST_F(AsyncBulkApplyTest, IdempotentMutationPolicy) {
NonIdempotentMutation("fail-with-transient-error"));

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(2);
EXPECT_CALL(*mock_metric, PostCall).Times(2);
EXPECT_CALL(*mock_metric, OnDone).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -513,19 +496,18 @@ TEST_F(AsyncBulkApplyTest, RetryInfoHeeded) {
bigtable::BulkMutation mut(IdempotentMutation("r0"));

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(2);
EXPECT_CALL(*mock_metric, PostCall).Times(2);
EXPECT_CALL(*mock_metric, OnDone).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -586,19 +568,18 @@ TEST_F(AsyncBulkApplyTest, RetryInfoIgnored) {
bigtable::BulkMutation mut(IdempotentMutation("r0"));

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -688,19 +669,18 @@ TEST_F(AsyncBulkApplyTest, CancelAfterSuccess) {
promise<std::optional<v2::MutateRowsResponse>> p;

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -764,19 +744,18 @@ TEST_F(AsyncBulkApplyTest, CancelMidStream) {
promise<std::optional<v2::MutateRowsResponse>> p;

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down
54 changes: 16 additions & 38 deletions google/cloud/bigtable/internal/async_row_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,41 +120,26 @@ class MockMetric : public Metric {
(const, override));
};

// This class is a vehicle to get a MockMetric into the OperationContext object.
class CloningMetric : public Metric {
public:
explicit CloningMetric(std::unique_ptr<MockMetric> metric)
: metric_(std::move(metric)) {}
std::unique_ptr<Metric> clone(TableResourceLabels const&,
TableDataLabels const&) const override {
return std::move(metric_);
}

private:
mutable std::unique_ptr<MockMetric> metric_;
};

#endif // GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
/// @test Verify that successfully reading rows works.
TEST_F(AsyncRowReaderTest, Success) {
CompletionQueue cq;

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(3);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(3);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -239,21 +224,20 @@ TEST_F(AsyncRowReaderTest, SuccessDelayedFuture) {
CompletionQueue cq;

#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(3);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(3);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -332,21 +316,20 @@ TEST_F(AsyncRowReaderTest, SuccessDelayedFuture) {
TEST_F(AsyncRowReaderTest, ResponseInMultipleChunks) {
CompletionQueue cq;
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(1);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -405,21 +388,20 @@ TEST_F(AsyncRowReaderTest, ResponseInMultipleChunks) {
TEST_F(AsyncRowReaderTest, ParserEofFailsOnUnfinishedRow) {
CompletionQueue cq;
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(0);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(0);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -477,21 +459,20 @@ TEST_F(AsyncRowReaderTest, ParserEofFailsOnUnfinishedRow) {
TEST_F(AsyncRowReaderTest, ParserEofDoesntFailOnUnfinishedRowIfRowLimit) {
CompletionQueue cq;
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(1);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(1);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -555,21 +536,20 @@ TEST_F(AsyncRowReaderTest, ParserEofDoesntFailOnUnfinishedRowIfRowLimit) {
TEST_F(AsyncRowReaderTest, PermanentFailure) {
CompletionQueue cq;
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(1);
EXPECT_CALL(*mock_metric, PostCall).Times(1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(0);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(0);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -627,21 +607,20 @@ TEST_F(AsyncRowReaderTest, RetryPolicyExhausted) {
});
CompletionQueue cq(mock_cq);
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(kNumRetries + 1);
EXPECT_CALL(*mock_metric, PostCall).Times(kNumRetries + 1);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(0);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(0);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down Expand Up @@ -793,21 +772,20 @@ TEST_F(AsyncRowReaderTest, RetrySkipsReadRows) {
});
CompletionQueue cq(mock_cq);
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
auto mock_metric = std::make_unique<MockMetric>();
auto mock_metric = std::make_shared<MockMetric>();
EXPECT_CALL(*mock_metric, PreCall).Times(2);
EXPECT_CALL(*mock_metric, PostCall).Times(2);
EXPECT_CALL(*mock_metric, OnDone).Times(1);
EXPECT_CALL(*mock_metric, ElementRequest).Times(2);
EXPECT_CALL(*mock_metric, ElementDelivery).Times(2);

auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
auto clock = std::make_shared<testing_util::FakeSteadyClock>();

// Normally std::make_shared would be used here, but some weird type deduction
// is preventing it.
// NOLINTNEXTLINE(modernize-make-shared)
auto operation_context = std::shared_ptr<OperationContext>(
new OperationContext({}, {}, {fake_metric}, clock));
new OperationContext({mock_metric}, clock));
#else
auto operation_context = std::make_shared<OperationContext>();
#endif
Expand Down
Loading
Loading