proxygen
AcceptRoutingHandlerTest Class Reference
Inheritance diagram for AcceptRoutingHandlerTest:
testing::Test

Public Member Functions

void SetUp () override
 
EventBasegetEventBase ()
 
Future< DefaultPipeline * > clientConnect ()
 
Future< DefaultPipeline * > clientConnectAndWrite ()
 
Future< DefaultPipeline * > clientConnectAndCleanClose ()
 
Future< DefaultPipeline * > justClientConnect ()
 
void sendClientException (DefaultPipeline *clientPipeline)
 
void TearDown () override
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 

Protected Attributes

std::unique_ptr< TestServerserver_
 
std::shared_ptr< MockAcceptPipelineFactoryacceptPipelineFactory_
 
AcceptPipeline::Ptr acceptPipeline_
 
DefaultPipeline::Ptr routingPipeline_
 
std::shared_ptr< MockRoutingDataHandlerFactoryroutingDataHandlerFactory_
 
MockRoutingDataHandlerroutingDataHandler_
 
MockAcceptRoutingHandleracceptRoutingHandler_
 
MockBytesToBytesHandlerdownstreamHandler_
 
std::shared_ptr< MockDownstreamPipelineFactorydownstreamPipelineFactory_
 
SocketAddress address_
 
RoutingDataHandler< char >::RoutingData routingData_
 
std::shared_ptr< TestClientclient_
 
int kConnId0 {0}
 
int kNumIOThreads {1}
 

Additional Inherited Members

- Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
 Test ()
 
 Test ()
 

Detailed Description

Definition at line 39 of file AcceptRoutingHandlerTest.cpp.

Member Function Documentation

Future<DefaultPipeline*> AcceptRoutingHandlerTest::clientConnect ( )
inline

Definition at line 85 of file AcceptRoutingHandlerTest.cpp.

85  {
86  client_ = std::make_shared<TestClient>();
87  client_->pipelineFactory(std::make_shared<TestClientPipelineFactory>());
88  client_->group(server_->getIOGroup());
89  return client_->connect(address_);
90  }
std::unique_ptr< TestServer > server_
std::shared_ptr< TestClient > client_
Future<DefaultPipeline*> AcceptRoutingHandlerTest::clientConnectAndCleanClose ( )
inline

Definition at line 111 of file AcceptRoutingHandlerTest.cpp.

References wangle::Pipeline< R, W >::close(), folly::getEventBase(), and folly::EventBase::runInEventBaseThread().

111  {
112  auto clientPipelinePromise =
113  std::make_shared<folly::Promise<DefaultPipeline*>>();
114 
116  clientConnectAndWrite().thenValue([=](DefaultPipeline* clientPipeline) {
117  VLOG(4) << "Client close";
118  clientPipeline->close().thenValue(
119  [=](auto&&) { clientPipelinePromise->setValue(clientPipeline); });
120  });
121  });
122 
123  return clientPipelinePromise->getFuture();
124  }
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type close()
Definition: Pipeline-inl.h:258
Future< DefaultPipeline * > clientConnectAndWrite()
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
Future<DefaultPipeline*> AcceptRoutingHandlerTest::clientConnectAndWrite ( )
inline

Definition at line 92 of file AcceptRoutingHandlerTest.cpp.

References folly::IOBuf::create(), folly::data(), folly::getEventBase(), folly::gen::move, folly::EventBase::runInEventBaseThread(), and wangle::Pipeline< R, W >::write().

92  {
93  auto clientPipelinePromise =
94  std::make_shared<folly::Promise<DefaultPipeline*>>();
95 
97  clientConnect().thenValue([=](DefaultPipeline* clientPipeline) {
98  VLOG(4) << "Client connected. Send data.";
99  auto data = IOBuf::create(1);
100  data->append(1);
101  *(data->writableData()) = 'a';
102  clientPipeline->write(std::move(data)).thenValue([=](auto&&) {
103  clientPipelinePromise->setValue(clientPipeline);
104  });
105  });
106  });
107 
108  return clientPipelinePromise->getFuture();
109  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type write(W msg)
Definition: Pipeline-inl.h:235
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
Future< DefaultPipeline * > clientConnect()
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
EventBase* AcceptRoutingHandlerTest::getEventBase ( )
inline

Definition at line 81 of file AcceptRoutingHandlerTest.cpp.

References folly::EventBase::getEventBase().

81  {
82  return server_->getIOGroup()->getEventBase();
83  }
std::unique_ptr< TestServer > server_
Future<DefaultPipeline*> AcceptRoutingHandlerTest::justClientConnect ( )
inline

Definition at line 126 of file AcceptRoutingHandlerTest.cpp.

References folly::getEventBase(), and folly::EventBase::runInEventBaseThread().

126  {
127  auto clientPipelinePromise =
128  std::make_shared<folly::Promise<DefaultPipeline*>>();
130  clientConnect().thenValue([=](DefaultPipeline* clientPipeline) {
131  clientPipelinePromise->setValue(clientPipeline);
132  });
133  });
134 
135  return clientPipelinePromise->getFuture();
136  }
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
Future< DefaultPipeline * > clientConnect()
void AcceptRoutingHandlerTest::sendClientException ( DefaultPipeline clientPipeline)
inline

Definition at line 138 of file AcceptRoutingHandlerTest.cpp.

References folly::getEventBase(), folly::EventBase::runInEventBaseThread(), and wangle::Pipeline< R, W >::writeException().

138  {
140  clientPipeline->writeException(
141  std::runtime_error("Client socket exception, right after connect."));
142  });
143  }
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type writeException(folly::exception_wrapper e)
Definition: Pipeline-inl.h:246
void AcceptRoutingHandlerTest::SetUp ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 41 of file AcceptRoutingHandlerTest.cpp.

41  {
42  routingData_.routingData = 'A';
43 
46  std::make_shared<MockDownstreamPipelineFactory>(downstreamHandler_);
47 
48  server_ = std::make_unique<TestServer>();
49 
50  // A routing pipeline with a mock routing handler that we can set
51  // expectations on.
52  routingPipeline_ = DefaultPipeline::create();
53 
55  std::make_shared<MockRoutingDataHandlerFactory>();
57  server_.get(),
62  new MockRoutingDataHandler(kConnId0, acceptRoutingHandler_);
63  routingDataHandlerFactory_->setRoutingDataHandler(routingDataHandler_);
64 
65  acceptPipeline_ = AcceptPipeline::create();
66  acceptPipeline_->addBack(
67  std::shared_ptr<MockAcceptRoutingHandler>(acceptRoutingHandler_));
68  acceptPipeline_->finalize();
69 
70  // A single threaded IOGroup shared between client and server for a
71  // deterministic event list.
72  auto ioGroup = std::make_shared<IOThreadPoolExecutor>(kNumIOThreads);
73 
75  std::make_shared<MockAcceptPipelineFactory>(acceptPipeline_);
76  server_->pipeline(acceptPipelineFactory_)->group(ioGroup, ioGroup)->bind(0);
77  server_->getSockets()[0]->getAddress(&address_);
78  VLOG(4) << "Start server at " << address_;
79  }
std::unique_ptr< TestServer > server_
MockRoutingDataHandler * routingDataHandler_
std::shared_ptr< MockRoutingDataHandlerFactory > routingDataHandlerFactory_
RoutingDataHandler< char >::RoutingData routingData_
MockBytesToBytesHandler * downstreamHandler_
MockAcceptRoutingHandler * acceptRoutingHandler_
std::shared_ptr< MockDownstreamPipelineFactory > downstreamPipelineFactory_
std::shared_ptr< MockAcceptPipelineFactory > acceptPipelineFactory_
void AcceptRoutingHandlerTest::TearDown ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 145 of file AcceptRoutingHandlerTest.cpp.

145  {
146  acceptPipeline_.reset();
147  acceptPipelineFactory_->cleanup();
148  }
std::shared_ptr< MockAcceptPipelineFactory > acceptPipelineFactory_

Member Data Documentation

AcceptPipeline::Ptr AcceptRoutingHandlerTest::acceptPipeline_
protected

Definition at line 153 of file AcceptRoutingHandlerTest.cpp.

std::shared_ptr<MockAcceptPipelineFactory> AcceptRoutingHandlerTest::acceptPipelineFactory_
protected

Definition at line 152 of file AcceptRoutingHandlerTest.cpp.

MockAcceptRoutingHandler* AcceptRoutingHandlerTest::acceptRoutingHandler_
protected

Definition at line 158 of file AcceptRoutingHandlerTest.cpp.

SocketAddress AcceptRoutingHandlerTest::address_
protected

Definition at line 161 of file AcceptRoutingHandlerTest.cpp.

std::shared_ptr<TestClient> AcceptRoutingHandlerTest::client_
protected

Definition at line 164 of file AcceptRoutingHandlerTest.cpp.

MockBytesToBytesHandler* AcceptRoutingHandlerTest::downstreamHandler_
protected

Definition at line 159 of file AcceptRoutingHandlerTest.cpp.

std::shared_ptr<MockDownstreamPipelineFactory> AcceptRoutingHandlerTest::downstreamPipelineFactory_
protected

Definition at line 160 of file AcceptRoutingHandlerTest.cpp.

int AcceptRoutingHandlerTest::kConnId0 {0}
protected

Definition at line 166 of file AcceptRoutingHandlerTest.cpp.

int AcceptRoutingHandlerTest::kNumIOThreads {1}
protected

Definition at line 167 of file AcceptRoutingHandlerTest.cpp.

RoutingDataHandler<char>::RoutingData AcceptRoutingHandlerTest::routingData_
protected

Definition at line 162 of file AcceptRoutingHandlerTest.cpp.

MockRoutingDataHandler* AcceptRoutingHandlerTest::routingDataHandler_
protected

Definition at line 156 of file AcceptRoutingHandlerTest.cpp.

std::shared_ptr<MockRoutingDataHandlerFactory> AcceptRoutingHandlerTest::routingDataHandlerFactory_
protected

Definition at line 155 of file AcceptRoutingHandlerTest.cpp.

DefaultPipeline::Ptr AcceptRoutingHandlerTest::routingPipeline_
protected

Definition at line 154 of file AcceptRoutingHandlerTest.cpp.

std::unique_ptr<TestServer> AcceptRoutingHandlerTest::server_
protected

Definition at line 151 of file AcceptRoutingHandlerTest.cpp.


The documentation for this class was generated from the following file: