| 492 | */ |
| 493 | template <typename ServerTraits, typename TemplateTraits> |
| 494 | void testEventSequencing() { |
| 495 | // We use TBufferedTransport for this test, instead of TFramedTransport. |
| 496 | // This way the server will start processing data as soon as it is received, |
| 497 | // instead of waiting for the full request. This is necessary so we can |
| 498 | // separate the preRead() and postRead() events. |
| 499 | typedef ServiceState<ServerTraits, |
| 500 | ChildServiceTraits<TemplateTraits>, |
| 501 | TBufferedTransportFactory, |
| 502 | TBufferedTransport> State; |
| 503 | |
| 504 | // Start the server |
| 505 | std::shared_ptr<State> state(new State); |
| 506 | ServerThread serverThread(state, true); |
| 507 | |
| 508 | const std::shared_ptr<EventLog>& log = state->getLog(); |
| 509 | |
| 510 | // Make sure we're at the end of the log |
| 511 | checkNoEvents(log); |
| 512 | |
| 513 | state->getHandler()->prepareTriggeredCall(); |
| 514 | |
| 515 | // Make sure createContext() is called after a connection has been |
| 516 | // established. We open a plain socket instead of creating a client. |
| 517 | std::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", state->getPort())); |
| 518 | socket->open(); |
| 519 | |
| 520 | // Make sure the proper events occurred after a new connection |
| 521 | uint32_t connId = checkNewConnEvents(log); |
| 522 | |
| 523 | // Send a message header. We manually construct the request so that we |
| 524 | // can test the timing for the preRead() call. |
| 525 | string requestName = "getDataWait"; |
| 526 | string eventName = "ParentService.getDataWait"; |
| 527 | auto seqid = int32_t(time(nullptr)); |
| 528 | TBinaryProtocol protocol(socket); |
| 529 | protocol.writeMessageBegin(requestName, T_CALL, seqid); |
| 530 | socket->flush(); |
| 531 | |
| 532 | // Make sure we saw the call started and pre-read events |
| 533 | Event event = log->waitForEvent(); |
| 534 | BOOST_CHECK_EQUAL(EventLog::ET_CALL_STARTED, event.type); |
| 535 | BOOST_CHECK_EQUAL(eventName, event.message); |
| 536 | BOOST_CHECK_EQUAL(connId, event.connectionId); |
| 537 | uint32_t callId = event.callId; |
| 538 | |
| 539 | event = log->waitForEvent(); |
| 540 | BOOST_CHECK_EQUAL(EventLog::ET_PRE_READ, event.type); |
| 541 | BOOST_CHECK_EQUAL(eventName, event.message); |
| 542 | BOOST_CHECK_EQUAL(connId, event.connectionId); |
| 543 | BOOST_CHECK_EQUAL(callId, event.callId); |
| 544 | |
| 545 | // Make sure there are no new events |
| 546 | checkNoEvents(log); |
| 547 | |
| 548 | // Send the rest of the request |
| 549 | protocol.writeStructBegin("ParentService_getDataNotified_pargs"); |
| 550 | protocol.writeFieldBegin("length", apache::thrift::protocol::T_I32, 1); |
| 551 | protocol.writeI32(8 * 1024 * 1024); |
nothing calls this directly
no test coverage detected