MCPcopy Create free account
hub / github.com/apache/thrift / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

lib/cpp/test/OneWayHTTPTest.cpp:174–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172} ;
173
174BOOST_AUTO_TEST_CASE( JSON_BufferedHTTP )
175{
176 std::shared_ptr<TServerSocket> ss = std::make_shared<TServerSocket>(0) ;
177 TThreadedServer server(
178 std::make_shared<onewaytest::OneWayServiceProcessorFactory>(std::make_shared<OneWayServiceCloneFactory>()),
179 ss, //port
180 std::make_shared<THttpServerTransportFactory>(),
181 std::make_shared<TJSONProtocolFactory>());
182
183 std::shared_ptr<TServerReadyEventHandler> pEventHandler(new TServerReadyEventHandler) ;
184 server.setServerEventHandler(pEventHandler);
185
186#ifdef ENABLE_STDERR_LOGGING
187 cerr << "Starting the server...\n";
188#endif
189 RPC0ThreadClass t(server) ;
190 boost::thread thread(&RPC0ThreadClass::Run, &t);
191
192 {
193 Synchronized sync(*(pEventHandler.get()));
194 while (!pEventHandler->isListening()) {
195 pEventHandler->wait();
196 }
197 }
198
199 int port = ss->getPort() ;
200#ifdef ENABLE_STDERR_LOGGING
201 cerr << "port " << port << '\n';
202#endif
203
204 {
205 std::shared_ptr<TSocket> socket(new TSocket("localhost", port));
206 socket->setRecvTimeout(10000) ; // 1000msec should be enough
207 std::shared_ptr<TBlockableBufferedTransport> blockable_transport(new TBlockableBufferedTransport(socket));
208 std::shared_ptr<TTransport> transport(new THttpClient(blockable_transport, "localhost", "/service"));
209 std::shared_ptr<TProtocol> protocol(new TJSONProtocol(transport));
210 onewaytest::OneWayServiceClient client(protocol);
211
212
213 transport->open();
214 client.roundTripRPC();
215 blockable_transport->block() ;
216 uint32_t size0 = blockable_transport->write_buffer_length() ;
217 client.send_oneWayRPC() ;
218 uint32_t size1 = blockable_transport->write_buffer_length() ;
219 client.send_oneWayRPC() ;
220 uint32_t size2 = blockable_transport->write_buffer_length() ;
221 BOOST_CHECK((size1 - size0) == (size2 - size1)) ;
222 blockable_transport->unblock() ;
223 client.send_roundTripRPC() ;
224 blockable_transport->flush() ;
225 try {
226 client.recv_roundTripRPC() ;
227 } catch (const TTransportException &e) {
228 BOOST_ERROR( "we should not get a transport exception -- this means we failed: " + std::string(e.what()) ) ;
229 }
230 transport->close();
231 }

Callers

nothing calls this directly

Calls 15

stringFunction · 0.85
roundTripRPCMethod · 0.80
write_buffer_lengthMethod · 0.80
closeMethod · 0.65
setServerEventHandlerMethod · 0.45
getMethod · 0.45
isListeningMethod · 0.45
waitMethod · 0.45
getPortMethod · 0.45
setRecvTimeoutMethod · 0.45
openMethod · 0.45
blockMethod · 0.45

Tested by

no test coverage detected