1313// limitations under the License.
1414
1515#include " google/cloud/bigtable/internal/retry_traits.h"
16+ #include " google/cloud/internal/make_status.h"
17+ #include " google/cloud/internal/status_payload_keys.h"
18+ #include < google/rpc/error_details.pb.h>
19+ #include < google/rpc/status.pb.h>
1620#include < gmock/gmock.h>
1721
1822namespace google {
@@ -29,6 +33,61 @@ TEST(SafeGrpcRetry, RstStreamRetried) {
2933 Status (StatusCode::kInternal , " RST_STREAM" )));
3034}
3135
36+ TEST (QueryPlanRefreshRetry, IsQueryPlanExpiredNoStatusPayload) {
37+ auto non_query_plan_failed_precondition =
38+ internal::FailedPreconditionError (" not the query plan" );
39+ EXPECT_FALSE (QueryPlanRefreshRetry::IsQueryPlanExpired (
40+ non_query_plan_failed_precondition));
41+
42+ auto query_plan_expired =
43+ internal::FailedPreconditionError (" PREPARED_QUERY_EXPIRED" );
44+ EXPECT_TRUE (QueryPlanRefreshRetry::IsQueryPlanExpired (query_plan_expired));
45+ }
46+
47+ TEST (QueryPlanRefreshRetry, QueryPlanExpiredStatusPayload) {
48+ auto query_plan_expired_violation =
49+ internal::FailedPreconditionError (" failed precondition" );
50+ google::rpc::PreconditionFailure_Violation violation;
51+ violation.set_type (" PREPARED_QUERY_EXPIRED" );
52+ violation.set_description (
53+ " The prepared query has expired. Please re-issue the ExecuteQuery with a "
54+ " valid prepared query." );
55+ google::rpc::PreconditionFailure precondition;
56+ *precondition.add_violations () = violation;
57+ google::rpc::Status status;
58+ status.set_code (9 );
59+ status.set_message (" failed precondition" );
60+ google::protobuf::Any any;
61+ ASSERT_TRUE (any.PackFrom (precondition));
62+ *status.add_details () = any;
63+ internal::SetPayload (query_plan_expired_violation,
64+ google::cloud::internal::StatusPayloadGrpcProto (),
65+ status.SerializeAsString ());
66+ EXPECT_TRUE (
67+ QueryPlanRefreshRetry::IsQueryPlanExpired (query_plan_expired_violation));
68+ }
69+
70+ TEST (QueryPlanRefreshRetry, QueryPlanNotExpiredStatusPayload) {
71+ auto query_plan_not_expired_violation =
72+ internal::FailedPreconditionError (" failed precondition" );
73+ google::rpc::PreconditionFailure_Violation violation;
74+ violation.set_type (" something else" );
75+ violation.set_description (" This is not the violation you are looking for" );
76+ google::rpc::PreconditionFailure precondition;
77+ *precondition.add_violations () = violation;
78+ google::rpc::Status status;
79+ status.set_code (9 );
80+ status.set_message (" failed precondition" );
81+ google::protobuf::Any any;
82+ ASSERT_TRUE (any.PackFrom (precondition));
83+ *status.add_details () = any;
84+ internal::SetPayload (query_plan_not_expired_violation,
85+ google::cloud::internal::StatusPayloadGrpcProto (),
86+ status.SerializeAsString ());
87+ EXPECT_FALSE (QueryPlanRefreshRetry::IsQueryPlanExpired (
88+ query_plan_not_expired_violation));
89+ }
90+
3291} // namespace
3392GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
3493} // namespace bigtable_internal
0 commit comments