17 #ifndef PAGESPEED_CONTROLLER_CONTROLLER_GRPC_MOCKS_H_
18 #define PAGESPEED_CONTROLLER_CONTROLLER_GRPC_MOCKS_H_
20 #include "pagespeed/controller/controller.grpc.pb.h"
21 #include "pagespeed/controller/controller.pb.h"
35 using testing::Invoke;
36 using testing::WithArgs;
37 using testing::Return;
38 using testing::SetArgPointee;
40 namespace net_instaweb {
48 : func_(func), sync_(sync) {}
69 template <
typename RequestT,
typename ResponseT>
71 :
public ::grpc::ClientAsyncReaderWriterInterface<RequestT, ResponseT> {
74 EXPECT_CALL(*
this, WritesDone(_)).Times(0);
75 EXPECT_CALL(*
this, ReadInitialMetadata(_)).Times(0);
76 EXPECT_CALL(*
this, Finish(_, _)).Times(0);
77 EXPECT_CALL(*
this, Write(_, _)).Times(0);
78 EXPECT_CALL(*
this, Write(_, _, _)).Times(0);
79 EXPECT_CALL(*
this, Read(_, _)).Times(0);
84 ASSERT_THAT(ParseTextFormatProtoFromString(asciiProto, &resp), Eq(
true));
86 EXPECT_CALL(*
this, Read(_, _))
88 SetArgPointee<0>(resp),
89 WithArgs<1>(Invoke(
this, &MockReaderWriterT::QueueVoidFunction))));
92 void ExpectReadFailure() {
93 EXPECT_CALL(*
this, Read(_, _))
94 .WillOnce(WithArgs<1>(
95 Invoke(
this, &MockReaderWriterT::QueueVoidFunctionForCancel)));
100 template <
typename Matcher>
102 EXPECT_CALL(*
this, Write(matcher, _))
104 WithArgs<1>(Invoke(
this, &MockReaderWriterT::QueueVoidFunction)));
107 template <
typename Matcher>
108 void ExpectWriteFailure(
const Matcher& matcher) {
109 EXPECT_CALL(*
this, Write(matcher, _))
110 .WillOnce(WithArgs<1>(
111 Invoke(
this, &MockReaderWriterT::QueueVoidFunctionForCancel)));
114 void ExpectFinish(const ::grpc::Status& status) {
115 EXPECT_CALL(*
this, Finish(_, _))
117 SetArgPointee<0>(status),
118 WithArgs<1>(Invoke(
this, &MockReaderWriterT::QueueVoidFunction))));
121 void ExpectFinishAndNotify(const ::grpc::Status& status,
122 WorkerTestBase::SyncPoint* sync) {
123 EXPECT_CALL(*
this, Finish(_, _))
124 .WillOnce(DoAll(SetArgPointee<0>(status),
125 WithArgs<1>(Invoke([
this, sync](
void* f) {
126 this->QueueVoidFunctionWithNotify(f, sync);
130 void ExpectFinishFailure() {
131 EXPECT_CALL(*
this, Finish(_, _))
132 .WillOnce(WithArgs<1>(
133 Invoke(
this, &MockReaderWriterT::QueueVoidFunctionForCancel)));
136 MOCK_METHOD1(WritesDone,
void(
void* tag));
137 MOCK_METHOD1(ReadInitialMetadata,
void(
void* tag));
138 MOCK_METHOD2(Finish,
void(::grpc::Status* status,
void* tag));
139 MOCK_METHOD2_T(Write,
void(
const RequestT& resp,
void* tag));
140 MOCK_METHOD3_T(Write,
void(
const RequestT& resp, ::grpc::WriteOptions options,
void* tag));
141 MOCK_METHOD2_T(Read,
void(ResponseT* resp,
void* tag));
144 void QueueVoidFunction(
void* fv) {
145 Function* f =
static_cast<Function*
>(fv);
149 void QueueVoidFunctionForCancel(
void* fv) {
150 Function* f =
static_cast<Function*
>(fv);
154 void QueueVoidFunctionWithNotify(
void* fv, WorkerTestBase::SyncPoint* sync) {
155 Function* f =
static_cast<Function*
>(fv);
156 sequence_->
Add(
new NotifyFunction(f, sync));
166 :
public grpc::CentralControllerRpcService::StubInterface {
169 : sequence_(sequence) {
170 EXPECT_CALL(*
this, ScheduleExpensiveOperationRaw(_)).Times(0);
171 EXPECT_CALL(*
this, ScheduleRewriteRaw(_)).Times(0);
172 EXPECT_CALL(*
this, AsyncScheduleExpensiveOperationRaw(_, _, _)).Times(0);
173 EXPECT_CALL(*
this, AsyncScheduleRewriteRaw(_, _, _)).Times(0);
177 ScheduleExpensiveOperationRaw,
178 ::grpc::ClientReaderWriterInterface<
179 ::net_instaweb::ScheduleExpensiveOperationRequest,
181 ScheduleExpensiveOperationResponse>*(::grpc::ClientContext*));
185 ::grpc::ClientReaderWriterInterface<
186 ::net_instaweb::ScheduleRewriteRequest,
187 ::net_instaweb::ScheduleRewriteResponse>*(::grpc::ClientContext*));
190 AsyncScheduleExpensiveOperationRaw,
191 ::grpc::ClientAsyncReaderWriterInterface<
192 ::net_instaweb::ScheduleExpensiveOperationRequest,
194 ScheduleExpensiveOperationResponse>*(::grpc::ClientContext*,
195 ::grpc::CompletionQueue*,
199 AsyncScheduleRewriteRaw,
200 ::grpc::ClientAsyncReaderWriterInterface<
201 ::net_instaweb::ScheduleRewriteRequest,
202 ::net_instaweb::ScheduleRewriteResponse>*(::grpc::ClientContext*,
203 ::grpc::CompletionQueue*,
207 ::grpc::ClientAsyncReaderWriterInterface<
208 ::net_instaweb::ScheduleExpensiveOperationRequest,
209 ::net_instaweb::ScheduleExpensiveOperationResponse>* rw) {
213 AsyncScheduleExpensiveOperationRaw(_,
nullptr , _))
214 .WillOnce(DoAll(WithArgs<2>(Invoke([
this](
void* fv) {
215 sequence_->
Add(static_cast<Function*>(fv));
221 ::grpc::ClientAsyncReaderWriterInterface<
222 ::net_instaweb::ScheduleExpensiveOperationRequest,
223 ::net_instaweb::ScheduleExpensiveOperationResponse>* rw) {
227 AsyncScheduleExpensiveOperationRaw(_,
nullptr , _))
228 .WillOnce(DoAll(WithArgs<2>(Invoke([
this](
void* fv) {
231 &Function::CallCancel));
237 ::grpc::ClientAsyncReaderWriterInterface<
238 ::net_instaweb::ScheduleRewriteRequest,
239 ::net_instaweb::ScheduleRewriteResponse>* rw) {
243 AsyncScheduleRewriteRaw(_,
nullptr , _))
244 .WillOnce(DoAll(WithArgs<2>(Invoke([
this](
void* fv) {
245 sequence_->
Add(static_cast<Function*>(fv));
251 ::grpc::ClientAsyncReaderWriterInterface<
252 ::net_instaweb::ScheduleRewriteRequest,
253 ::net_instaweb::ScheduleRewriteResponse>* rw) {
257 AsyncScheduleRewriteRaw(_,
nullptr , _))
258 .WillOnce(DoAll(WithArgs<2>(Invoke([
this](
void* fv) {
261 &Function::CallCancel));
Function * MakeFunction(C *object, void(C::*run)())
Makes a Function* that calls a 0-arg class method.
Definition: function.h:291
void ExpectAsyncScheduleRewriteFailure(::grpc::ClientAsyncReaderWriterInterface< ::net_instaweb::ScheduleRewriteRequest,::net_instaweb::ScheduleRewriteResponse > *rw)
Definition: controller_grpc_mocks.h:250
void ExpectWrite(const Matcher &matcher)
Definition: controller_grpc_mocks.h:101
Definition: sequence.h:33
void ExpectAsyncScheduleRewrite(::grpc::ClientAsyncReaderWriterInterface< ::net_instaweb::ScheduleRewriteRequest,::net_instaweb::ScheduleRewriteResponse > *rw)
Definition: controller_grpc_mocks.h:236
A way for one thread to wait for another.
Definition: worker_test_base.h:71
Definition: function.h:47
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
void Run() override
Definition: controller_grpc_mocks.h:50
virtual void Add(Function *function)=0
void Cancel() override
Definition: controller_grpc_mocks.h:55
void ExpectAsyncScheduleExpensiveOperation(::grpc::ClientAsyncReaderWriterInterface< ::net_instaweb::ScheduleExpensiveOperationRequest,::net_instaweb::ScheduleExpensiveOperationResponse > *rw)
Definition: controller_grpc_mocks.h:206
Definition: controller_grpc_mocks.h:70
Definition: controller_grpc_mocks.h:45
Definition: controller_grpc_mocks.h:165
void ExpectAsyncScheduleExpensiveOperationFailure(::grpc::ClientAsyncReaderWriterInterface< ::net_instaweb::ScheduleExpensiveOperationRequest,::net_instaweb::ScheduleExpensiveOperationResponse > *rw)
Definition: controller_grpc_mocks.h:220