Skip to content

Commit 08e387d

Browse files
authored
fix(bigtable): missing functions to change policies (#5565)
1 parent 0578c7d commit 08e387d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

google/cloud/bigtable/instance_admin.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,28 @@ class InstanceAdmin {
13511351
std::vector<std::string> const& permissions);
13521352

13531353
private:
1354+
//@{
1355+
/// @name Helper functions to implement constructors with changed policies.
1356+
void ChangePolicy(RPCRetryPolicy const& policy) {
1357+
rpc_retry_policy_prototype_ = policy.clone();
1358+
}
1359+
1360+
void ChangePolicy(RPCBackoffPolicy const& policy) {
1361+
rpc_backoff_policy_prototype_ = policy.clone();
1362+
}
1363+
1364+
void ChangePolicy(PollingPolicy const& policy) {
1365+
polling_policy_prototype_ = policy.clone();
1366+
}
1367+
1368+
template <typename Policy, typename... Policies>
1369+
void ChangePolicies(Policy&& policy, Policies&&... policies) {
1370+
ChangePolicy(policy);
1371+
ChangePolicies(std::forward<Policies>(policies)...);
1372+
}
1373+
void ChangePolicies() {}
1374+
//@}
1375+
13541376
static StatusOr<google::cloud::IamPolicy> ProtoToWrapper(
13551377
google::iam::v1::Policy proto);
13561378

google/cloud/bigtable/instance_admin_test.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "google/cloud/testing_util/assert_ok.h"
2121
#include "google/cloud/testing_util/chrono_literals.h"
2222
#include "google/cloud/testing_util/fake_completion_queue_impl.h"
23+
#include "google/cloud/testing_util/status_matchers.h"
2324
#include "google/cloud/testing_util/validate_metadata.h"
2425
#include "absl/memory/memory.h"
2526
#include <google/protobuf/text_format.h>
@@ -37,9 +38,12 @@ namespace btadmin = ::google::bigtable::admin::v2;
3738
using MockAdminClient =
3839
::google::cloud::bigtable::testing::MockInstanceAdminClient;
3940
using ::google::cloud::testing_util::IsContextMDValid;
41+
using ::google::cloud::testing_util::StatusIs;
4042
using ::google::cloud::testing_util::chrono_literals::operator"" _ms;
4143
using ::google::cloud::testing_util::FakeCompletionQueueImpl;
4244
using ::testing::_;
45+
using ::testing::AtLeast;
46+
using ::testing::HasSubstr;
4347
using ::testing::Return;
4448
using ::testing::ReturnRef;
4549

@@ -312,6 +316,24 @@ TEST_F(InstanceAdminTest, ListInstancesUnrecoverableFailures) {
312316
EXPECT_FALSE(tested.ListInstances());
313317
}
314318

319+
/**
320+
* @test Verify that `bigtable::InstanceAdmin::ListInstances` handles
321+
* too many transient failures.
322+
*/
323+
TEST_F(InstanceAdminTest, ListInstancesTooManyTransients) {
324+
using ms = std::chrono::milliseconds;
325+
InstanceAdmin tested(client_, LimitedErrorCountRetryPolicy(3),
326+
ExponentialBackoffPolicy(ms(1), ms(2)));
327+
EXPECT_CALL(*client_, ListInstances)
328+
.Times(AtLeast(2))
329+
.WillRepeatedly(
330+
Return(grpc::Status(grpc::StatusCode::UNAVAILABLE, "try-again")));
331+
332+
// After all the setup, make the actual call we want to test.
333+
EXPECT_THAT(tested.ListInstances(),
334+
StatusIs(StatusCode::kUnavailable, HasSubstr("try-again")));
335+
}
336+
315337
/// @test Verify that `bigtable::DeleteInstance` works in the positive case.
316338
TEST_F(InstanceAdminTest, DeleteInstance) {
317339
using google::protobuf::Empty;

0 commit comments

Comments
 (0)