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

Function TEST_F

test/brpc_ssl_unittest.cpp:109–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109TEST_F(SSLTest, sanity) {
110 // Test RPC based on SSL + brpc protocol
111 const int port = 8613;
112 brpc::Server server;
113 brpc::ServerOptions options;
114
115 brpc::CertInfo cert;
116 cert.certificate = "cert1.crt";
117 cert.private_key = "cert1.key";
118 options.mutable_ssl_options()->default_cert = cert;
119
120 EchoServiceImpl echo_svc;
121 ASSERT_EQ(0, server.AddService(
122 &echo_svc, brpc::SERVER_DOESNT_OWN_SERVICE));
123 ASSERT_EQ(0, server.Start(port, &options));
124
125 test::EchoRequest req;
126 test::EchoResponse res;
127 req.set_message(EXP_REQUEST);
128 {
129 brpc::Channel channel;
130 brpc::ChannelOptions coptions;
131 coptions.mutable_ssl_options();
132 coptions.mutable_ssl_options()->sni_name = "localhost";
133 ASSERT_EQ(0, channel.Init("localhost", port, &coptions));
134
135 brpc::Controller cntl;
136 test::EchoService_Stub stub(&channel);
137 stub.Echo(&cntl, &req, &res, NULL);
138 EXPECT_EQ(EXP_RESPONSE, res.message()) << cntl.ErrorText();
139 }
140
141 // stress test
142 const int NUM = 5;
143 const int COUNT = 3000;
144 pthread_t tids[NUM];
145 {
146 brpc::Channel channel;
147 brpc::ChannelOptions coptions;
148 coptions.mutable_ssl_options();
149 coptions.mutable_ssl_options()->sni_name = "localhost";
150 ASSERT_EQ(0, channel.Init("127.0.0.1", port, &coptions));
151 for (int i = 0; i < NUM; ++i) {
152 google::protobuf::Closure* thrd_func =
153 brpc::NewCallback(SendMultipleRPC, &channel, COUNT);
154 EXPECT_EQ(0, pthread_create(&tids[i], NULL, RunClosure, thrd_func));
155 }
156 for (int i = 0; i < NUM; ++i) {
157 pthread_join(tids[i], NULL);
158 }
159 }
160 {
161 // Use HTTP
162 brpc::Channel channel;
163 brpc::ChannelOptions coptions;
164 coptions.protocol = "http";
165 coptions.mutable_ssl_options();
166 coptions.mutable_ssl_options()->sni_name = "localhost";

Callers

nothing calls this directly

Calls 15

NewCallbackFunction · 0.85
RegisterProtocolFunction · 0.85
SerializeRequestDefaultFunction · 0.85
PackRpcRequestFunction · 0.85
JoinFunction · 0.85
GetRawPemStringFunction · 0.85
CheckCertFunction · 0.85
tcp_listenFunction · 0.85
tcp_connectFunction · 0.85
AddServiceMethod · 0.80
ErrorTextMethod · 0.80
AddHandlerMethod · 0.80

Tested by

no test coverage detected