MCPcopy Create free account
hub / github.com/apache/brpc / RunCase

Function RunCase

example/auto_concurrency_limiter/client.cpp:171–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void RunCase(test::ControlService_Stub &cntl_stub,
172 const test::TestCase& test_case) {
173 LOG(INFO) << "Running case:`" << test_case.case_name() << '\'';
174 brpc::Channel channel;
175 brpc::ChannelOptions options;
176 options.protocol = FLAGS_protocol;
177 options.connection_type = FLAGS_connection_type;
178 options.timeout_ms = FLAGS_timeout_ms;
179 options.max_retry = FLAGS_max_retry;
180 if (channel.Init(FLAGS_echo_server.c_str(), &options) != 0) {
181 LOG(FATAL) << "Fail to initialize channel";
182 }
183 test::EchoService_Stub echo_stub(&channel);
184
185 test::NotifyRequest cntl_req;
186 test::NotifyResponse cntl_rsp;
187 brpc::Controller cntl;
188 cntl_req.set_message("StartCase");
189 cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, NULL);
190 CHECK(!cntl.Failed()) << "control failed";
191
192 TestCaseContext context(test_case);
193 bthread::get_global_timer_thread()->schedule(RunUpdateTask, &context,
194 butil::microseconds_from_now(FLAGS_client_qps_change_interval_us));
195
196 while (context.running.load(butil::memory_order_acquire)) {
197 test::NotifyRequest echo_req;
198 echo_req.set_message("hello");
199 brpc::Controller* echo_cntl = new brpc::Controller;
200 test::NotifyResponse* echo_rsp = new test::NotifyResponse;
201 google::protobuf::Closure* done = brpc::NewCallback(
202 &HandleEchoResponse, echo_cntl, echo_rsp);
203 echo_stub.Echo(echo_cntl, &echo_req, echo_rsp, done);
204 ::usleep(context.interval_us.load(butil::memory_order_relaxed));
205 }
206
207 LOG(INFO) << "Waiting to stop case: `" << test_case.case_name() << '\'';
208 ::sleep(FLAGS_case_interval);
209 cntl.Reset();
210 cntl_req.set_message("StopCase");
211 cntl_stub.Notify(&cntl, &cntl_req, &cntl_rsp, NULL);
212 CHECK(!cntl.Failed()) << "control failed";
213 LOG(INFO) << "Case `" << test_case.case_name() << "' finshed:";
214}
215
216int main(int argc, char* argv[]) {
217 // Parse gflags. We recommend you to use gflags as well.

Callers 1

mainFunction · 0.85

Calls 11

get_global_timer_threadFunction · 0.85
microseconds_from_nowFunction · 0.85
NewCallbackFunction · 0.85
InitMethod · 0.45
c_strMethod · 0.45
NotifyMethod · 0.45
FailedMethod · 0.45
scheduleMethod · 0.45
loadMethod · 0.45
EchoMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected