forked from googleapis/google-cloud-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretry_traits_test.cc
More file actions
95 lines (87 loc) · 3.69 KB
/
retry_traits_test.cc
File metadata and controls
95 lines (87 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "google/cloud/bigtable/internal/retry_traits.h"
#include "google/cloud/internal/make_status.h"
#include "google/cloud/internal/status_payload_keys.h"
#include <google/rpc/error_details.pb.h>
#include <google/rpc/status.pb.h>
#include <gmock/gmock.h>
namespace google {
namespace cloud {
namespace bigtable_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {
/// @test Verify that certain known internal errors are retryable.
TEST(SafeGrpcRetry, RstStreamRetried) {
EXPECT_FALSE(SafeGrpcRetry::IsTransientFailure(
Status(StatusCode::kInternal, "non-retryable")));
EXPECT_TRUE(SafeGrpcRetry::IsTransientFailure(
Status(StatusCode::kInternal, "RST_STREAM")));
}
TEST(QueryPlanRefreshRetry, IsQueryPlanExpiredNoStatusPayload) {
auto non_query_plan_failed_precondition =
internal::FailedPreconditionError("not the query plan");
EXPECT_FALSE(QueryPlanRefreshRetry::IsQueryPlanExpired(
non_query_plan_failed_precondition));
auto query_plan_expired =
internal::FailedPreconditionError("PREPARED_QUERY_EXPIRED");
EXPECT_TRUE(QueryPlanRefreshRetry::IsQueryPlanExpired(query_plan_expired));
}
TEST(QueryPlanRefreshRetry, QueryPlanExpiredStatusPayload) {
auto query_plan_expired_violation =
internal::FailedPreconditionError("failed precondition");
google::rpc::PreconditionFailure_Violation violation;
violation.set_type("PREPARED_QUERY_EXPIRED");
violation.set_description(
"The prepared query has expired. Please re-issue the ExecuteQuery with a "
"valid prepared query.");
google::rpc::PreconditionFailure precondition;
*precondition.add_violations() = violation;
google::rpc::Status status;
status.set_code(9);
status.set_message("failed precondition");
google::protobuf::Any any;
ASSERT_TRUE(any.PackFrom(precondition));
*status.add_details() = any;
internal::SetPayload(query_plan_expired_violation,
google::cloud::internal::StatusPayloadGrpcProto(),
status.SerializeAsString());
EXPECT_TRUE(
QueryPlanRefreshRetry::IsQueryPlanExpired(query_plan_expired_violation));
}
TEST(QueryPlanRefreshRetry, QueryPlanNotExpiredStatusPayload) {
auto query_plan_not_expired_violation =
internal::FailedPreconditionError("failed precondition");
google::rpc::PreconditionFailure_Violation violation;
violation.set_type("something else");
violation.set_description("This is not the violation you are looking for");
google::rpc::PreconditionFailure precondition;
*precondition.add_violations() = violation;
google::rpc::Status status;
status.set_code(9);
status.set_message("failed precondition");
google::protobuf::Any any;
ASSERT_TRUE(any.PackFrom(precondition));
*status.add_details() = any;
internal::SetPayload(query_plan_not_expired_violation,
google::cloud::internal::StatusPayloadGrpcProto(),
status.SerializeAsString());
EXPECT_FALSE(QueryPlanRefreshRetry::IsQueryPlanExpired(
query_plan_not_expired_violation));
}
} // namespace
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable_internal
} // namespace cloud
} // namespace google