12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- #include " googletest/include/gtest/gtest.h"
16
- #include " retry_policy.h"
17
15
#include < chrono>
18
16
#include < memory>
19
17
18
+ #include " googletest/include/gtest/gtest.h"
19
+ #include " retry_policy.h"
20
+ #include " status.h"
21
+
20
22
namespace {
21
23
using namespace ::google;
22
24
23
- class TestStatus {
24
- public:
25
- bool const isPermanent;
26
- };
27
-
28
- class TestRetryablePolicy {
29
- public:
30
- static bool IsPermanentFailure (TestStatus const & s) {
31
- return s.isPermanent ;
32
- }
33
- };
34
-
35
- using RP = gax::RetryPolicy<TestStatus, TestRetryablePolicy>;
36
-
37
- using LECRP = gax::LimitedErrorCountRetryPolicy<TestStatus, TestRetryablePolicy>;
38
-
39
25
TEST (LimitedErrorCountRetryPolicy, Basic) {
40
- LECRP tested (3 );
41
- TestStatus s{ false } ;
26
+ gax::LimitedErrorCountRetryPolicy tested (3 );
27
+ gax::Status s ;
42
28
EXPECT_TRUE (tested.OnFailure (s));
43
29
EXPECT_TRUE (tested.OnFailure (s));
44
30
EXPECT_TRUE (tested.OnFailure (s));
@@ -47,57 +33,57 @@ TEST(LimitedErrorCountRetryPolicy, Basic) {
47
33
}
48
34
49
35
TEST (LimitedErrorCountRetryPolicy, PermanentFailureCheck) {
50
- LECRP tested (3 );
51
- TestStatus s{true };
36
+ gax::LimitedErrorCountRetryPolicy tested (3 );
37
+ gax::Status s{gax::StatusCode:: kCancelled , " " };
52
38
EXPECT_FALSE (tested.OnFailure (s));
53
39
}
54
40
55
41
TEST (LimitedErrorCountRetryPolicy, CopyConstruct) {
56
- LECRP tested (3 );
57
- TestStatus s{ false } ;
42
+ gax::LimitedErrorCountRetryPolicy tested (3 );
43
+ gax::Status s ;
58
44
EXPECT_TRUE (tested.OnFailure (s));
59
45
EXPECT_TRUE (tested.OnFailure (s));
60
46
EXPECT_TRUE (tested.OnFailure (s));
61
47
EXPECT_FALSE (tested.OnFailure (s));
62
48
63
- LECRP copy (tested);
49
+ gax::LimitedErrorCountRetryPolicy copy (tested);
64
50
EXPECT_TRUE (copy.OnFailure (s));
65
51
EXPECT_TRUE (copy.OnFailure (s));
66
52
EXPECT_TRUE (copy.OnFailure (s));
67
53
EXPECT_FALSE (copy.OnFailure (s));
68
54
}
69
55
70
56
TEST (LimitedErrorCountRetryPolicy, MoveConstruct) {
71
- LECRP tested (3 );
72
- TestStatus s{ false } ;
57
+ gax::LimitedErrorCountRetryPolicy tested (3 );
58
+ gax::Status s ;
73
59
EXPECT_TRUE (tested.OnFailure (s));
74
60
EXPECT_TRUE (tested.OnFailure (s));
75
61
EXPECT_TRUE (tested.OnFailure (s));
76
62
EXPECT_FALSE (tested.OnFailure (s));
77
63
78
- LECRP copy (std::move (tested));
64
+ gax::LimitedErrorCountRetryPolicy copy (std::move (tested));
79
65
EXPECT_TRUE (copy.OnFailure (s));
80
66
EXPECT_TRUE (copy.OnFailure (s));
81
67
EXPECT_TRUE (copy.OnFailure (s));
82
68
EXPECT_FALSE (copy.OnFailure (s));
83
69
}
84
70
85
71
TEST (LimitedErrorCountRetryPolicy, Clone) {
86
- LECRP tested (3 );
87
- TestStatus s{ false } ;
72
+ gax::LimitedErrorCountRetryPolicy tested (3 );
73
+ gax::Status s ;
88
74
EXPECT_TRUE (tested.OnFailure (s));
89
75
EXPECT_TRUE (tested.OnFailure (s));
90
76
EXPECT_TRUE (tested.OnFailure (s));
91
77
EXPECT_FALSE (tested.OnFailure (s));
92
78
93
- std::unique_ptr<RP > clone = tested.clone ();
79
+ std::unique_ptr<gax::RetryPolicy > clone = tested.clone ();
94
80
EXPECT_TRUE (clone->OnFailure (s));
95
81
EXPECT_TRUE (clone->OnFailure (s));
96
82
EXPECT_TRUE (clone->OnFailure (s));
97
83
EXPECT_FALSE (clone->OnFailure (s));
98
84
}
99
85
100
- static std::chrono::time_point<std::chrono::system_clock> now_point = std::chrono::system_clock::now() ;
86
+ static std::chrono::time_point<std::chrono::system_clock> now_point;
101
87
102
88
class TestClock {
103
89
public:
@@ -106,11 +92,9 @@ class TestClock {
106
92
}
107
93
};
108
94
109
- using LDRP = gax::LimitedDurationRetryPolicy<TestStatus, TestRetryablePolicy, TestClock>;
110
-
111
95
TEST (LimitedDurationRetryPolicy, Basic) {
112
- LDRP tested (std::chrono::milliseconds (5 ));
113
- TestStatus s{ false } ;
96
+ gax::LimitedDurationRetryPolicy<TestClock> tested (std::chrono::milliseconds (5 ));
97
+ gax::Status s ;
114
98
EXPECT_TRUE (tested.OnFailure (s));
115
99
116
100
now_point += std::chrono::milliseconds (2 );
@@ -121,42 +105,42 @@ TEST(LimitedDurationRetryPolicy, Basic) {
121
105
}
122
106
123
107
TEST (LimitedDurationRetryPolicy, PermanentFailureCheck) {
124
- LDRP tested (std::chrono::milliseconds (5 ));
125
- TestStatus s{true };
108
+ gax::LimitedDurationRetryPolicy<TestClock> tested (std::chrono::milliseconds (5 ));
109
+ gax::Status s{gax::StatusCode:: kCancelled , " " };
126
110
127
111
EXPECT_FALSE (tested.OnFailure (s));
128
112
}
129
113
130
114
TEST (LimitedDurationRetryPolicy, CopyConstruct) {
131
- LDRP tested (std::chrono::milliseconds (5 ));
132
- TestStatus s{ false } ;
115
+ gax::LimitedDurationRetryPolicy<TestClock> tested (std::chrono::milliseconds (5 ));
116
+ gax::Status s ;
133
117
134
118
now_point += std::chrono::milliseconds (10 );
135
119
EXPECT_FALSE (tested.OnFailure (s));
136
120
137
- LDRP copy (tested);
121
+ gax::LimitedDurationRetryPolicy<TestClock> copy (tested);
138
122
EXPECT_TRUE (copy.OnFailure (s));
139
123
}
140
124
141
125
TEST (LimitedDurationRetryPolicy, MoveConstruct) {
142
- LDRP tested (std::chrono::milliseconds (5 ));
143
- TestStatus s{ false } ;
126
+ gax::LimitedDurationRetryPolicy<TestClock> tested (std::chrono::milliseconds (5 ));
127
+ gax::Status s ;
144
128
145
129
now_point += std::chrono::milliseconds (10 );
146
130
EXPECT_FALSE (tested.OnFailure (s));
147
131
148
- LDRP copy (std::move (tested));
132
+ gax::LimitedDurationRetryPolicy<TestClock> copy (std::move (tested));
149
133
EXPECT_TRUE (copy.OnFailure (s));
150
134
}
151
135
152
136
TEST (LimitedDurationRetryPolicy, Clone) {
153
- LDRP tested (std::chrono::milliseconds (5 ));
154
- TestStatus s{ false } ;
137
+ gax::LimitedDurationRetryPolicy<TestClock> tested (std::chrono::milliseconds (5 ));
138
+ gax::Status s ;
155
139
156
140
now_point += std::chrono::milliseconds (10 );
157
141
EXPECT_FALSE (tested.OnFailure (s));
158
142
159
- std::unique_ptr<RP > clone = tested.clone ();
143
+ std::unique_ptr<gax::RetryPolicy > clone = tested.clone ();
160
144
EXPECT_TRUE (clone->OnFailure (s));
161
145
}
162
146
0 commit comments