@@ -87,12 +87,23 @@ TEST_F(MixerClientImplTest, TestSuccessCheck) {
87
87
EXPECT_TRUE (done_status.ok ());
88
88
89
89
for (int i = 0 ; i < 10 ; i++) {
90
- // Other calls should ba cached.
90
+ // Other calls should be cached.
91
91
Status done_status1 = Status::UNKNOWN;
92
92
client_->Check (request_, empty_quotas, empty_transport_,
93
93
[&done_status1](Status status) { done_status1 = status; });
94
94
EXPECT_TRUE (done_status1.ok ());
95
95
}
96
+
97
+ Statistics stat;
98
+ client_->GetStatistics (&stat);
99
+ EXPECT_EQ (stat.total_check_calls , 11 );
100
+ // The first check call is a remote blocking check call.
101
+ EXPECT_EQ (stat.total_remote_check_calls , 1 );
102
+ EXPECT_EQ (stat.total_blocking_remote_check_calls , 1 );
103
+ // Empty quota does not trigger any quota call.
104
+ EXPECT_EQ (stat.total_quota_calls , 0 );
105
+ EXPECT_EQ (stat.total_remote_quota_calls , 0 );
106
+ EXPECT_EQ (stat.total_blocking_remote_quota_calls , 0 );
96
107
}
97
108
98
109
TEST_F (MixerClientImplTest, TestPerRequestTransport) {
@@ -116,12 +127,23 @@ TEST_F(MixerClientImplTest, TestPerRequestTransport) {
116
127
EXPECT_TRUE (done_status.ok ());
117
128
118
129
for (int i = 0 ; i < 10 ; i++) {
119
- // Other calls should ba cached.
130
+ // Other calls should be cached.
120
131
Status done_status1 = Status::UNKNOWN;
121
132
client_->Check (request_, empty_quotas, local_check_transport.GetFunc (),
122
133
[&done_status1](Status status) { done_status1 = status; });
123
134
EXPECT_TRUE (done_status1.ok ());
124
135
}
136
+
137
+ Statistics stat;
138
+ client_->GetStatistics (&stat);
139
+ EXPECT_EQ (stat.total_check_calls , 11 );
140
+ // The first check call is a remote blocking check call.
141
+ EXPECT_EQ (stat.total_remote_check_calls , 1 );
142
+ EXPECT_EQ (stat.total_blocking_remote_check_calls , 1 );
143
+ // Empty quota does not trigger any quota call.
144
+ EXPECT_EQ (stat.total_quota_calls , 0 );
145
+ EXPECT_EQ (stat.total_remote_quota_calls , 0 );
146
+ EXPECT_EQ (stat.total_blocking_remote_quota_calls , 0 );
125
147
}
126
148
127
149
TEST_F (MixerClientImplTest, TestNoCheckCache) {
@@ -146,14 +168,23 @@ TEST_F(MixerClientImplTest, TestNoCheckCache) {
146
168
EXPECT_TRUE (done_status.ok ());
147
169
148
170
for (int i = 0 ; i < 10 ; i++) {
149
- // Other calls should ba cached.
171
+ // Other calls are not cached.
150
172
Status done_status1 = Status::UNKNOWN;
151
173
client_->Check (request_, quotas_, empty_transport_,
152
174
[&done_status1](Status status) { done_status1 = status; });
153
175
EXPECT_TRUE (done_status1.ok ());
154
176
}
155
177
// Call count 11 since check is not cached.
156
- EXPECT_LE (call_counts, 11 );
178
+ EXPECT_EQ (call_counts, 11 );
179
+ Statistics stat;
180
+ client_->GetStatistics (&stat);
181
+ // Because there is no check cache, we make remote blocking call every time.
182
+ EXPECT_EQ (stat.total_check_calls , 11 );
183
+ EXPECT_EQ (stat.total_remote_check_calls , 11 );
184
+ EXPECT_EQ (stat.total_blocking_remote_check_calls , 11 );
185
+ EXPECT_EQ (stat.total_quota_calls , 11 );
186
+ EXPECT_EQ (stat.total_remote_quota_calls , 11 );
187
+ EXPECT_EQ (stat.total_blocking_remote_quota_calls , 11 );
157
188
}
158
189
159
190
TEST_F (MixerClientImplTest, TestNoQuotaCache) {
@@ -178,14 +209,23 @@ TEST_F(MixerClientImplTest, TestNoQuotaCache) {
178
209
EXPECT_TRUE (done_status.ok ());
179
210
180
211
for (int i = 0 ; i < 10 ; i++) {
181
- // Other calls should ba cached.
212
+ // Other calls should be cached.
182
213
Status done_status1 = Status::UNKNOWN;
183
214
client_->Check (request_, quotas_, empty_transport_,
184
215
[&done_status1](Status status) { done_status1 = status; });
185
216
EXPECT_TRUE (done_status1.ok ());
186
217
}
187
218
// Call count 11 since quota is not cached.
188
- EXPECT_LE (call_counts, 11 );
219
+ EXPECT_EQ (call_counts, 11 );
220
+ Statistics stat;
221
+ client_->GetStatistics (&stat);
222
+ // Because there is no quota cache, we make remote blocking call every time.
223
+ EXPECT_EQ (stat.total_check_calls , 11 );
224
+ EXPECT_EQ (stat.total_remote_check_calls , 11 );
225
+ EXPECT_EQ (stat.total_blocking_remote_check_calls , 11 );
226
+ EXPECT_EQ (stat.total_quota_calls , 11 );
227
+ EXPECT_EQ (stat.total_remote_quota_calls , 11 );
228
+ EXPECT_EQ (stat.total_blocking_remote_quota_calls , 11 );
189
229
}
190
230
191
231
TEST_F (MixerClientImplTest, TestSuccessCheckAndQuota) {
@@ -208,14 +248,24 @@ TEST_F(MixerClientImplTest, TestSuccessCheckAndQuota) {
208
248
EXPECT_TRUE (done_status.ok ());
209
249
210
250
for (int i = 0 ; i < 10 ; i++) {
211
- // Other calls should ba cached.
251
+ // Other calls should be cached.
212
252
Status done_status1 = Status::UNKNOWN;
213
253
client_->Check (request_, quotas_, empty_transport_,
214
254
[&done_status1](Status status) { done_status1 = status; });
215
255
EXPECT_TRUE (done_status1.ok ());
216
256
}
217
257
// Call count should be less than 4
218
258
EXPECT_LE (call_counts, 3 );
259
+ Statistics stat;
260
+ client_->GetStatistics (&stat);
261
+ // Less than 4 remote calls are made for prefetching, and they are
262
+ // non-blocking remote calls.
263
+ EXPECT_EQ (stat.total_check_calls , 11 );
264
+ EXPECT_LE (stat.total_remote_check_calls , 3 );
265
+ EXPECT_EQ (stat.total_blocking_remote_check_calls , 1 );
266
+ EXPECT_EQ (stat.total_quota_calls , 11 );
267
+ EXPECT_LE (stat.total_remote_quota_calls , 3 );
268
+ EXPECT_EQ (stat.total_blocking_remote_quota_calls , 1 );
219
269
}
220
270
221
271
TEST_F (MixerClientImplTest, TestFailedCheckAndQuota) {
@@ -238,12 +288,22 @@ TEST_F(MixerClientImplTest, TestFailedCheckAndQuota) {
238
288
EXPECT_ERROR_CODE (Code::FAILED_PRECONDITION, done_status);
239
289
240
290
for (int i = 0 ; i < 10 ; i++) {
241
- // Other calls should ba cached.
291
+ // Other calls should be cached.
242
292
Status done_status1 = Status::UNKNOWN;
243
293
client_->Check (request_, quotas_, empty_transport_,
244
294
[&done_status1](Status status) { done_status1 = status; });
245
295
EXPECT_ERROR_CODE (Code::FAILED_PRECONDITION, done_status1);
246
296
}
297
+ Statistics stat;
298
+ client_->GetStatistics (&stat);
299
+ // The first call is a remote blocking call, which returns failed precondition
300
+ // in check response. Following calls only make check cache calls and return.
301
+ EXPECT_EQ (stat.total_check_calls , 11 );
302
+ EXPECT_EQ (stat.total_remote_check_calls , 1 );
303
+ EXPECT_EQ (stat.total_blocking_remote_check_calls , 1 );
304
+ EXPECT_EQ (stat.total_quota_calls , 1 );
305
+ EXPECT_EQ (stat.total_remote_quota_calls , 1 );
306
+ EXPECT_EQ (stat.total_blocking_remote_quota_calls , 1 );
247
307
}
248
308
249
309
} // namespace
0 commit comments