proxygen
RequestHandlerAdaptorTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
15 
16 using namespace folly;
17 using namespace proxygen;
18 using namespace testing;
19 
21  using RequestHandlerAdaptor::RequestHandlerAdaptor;
22 
23  void sendHeaders(HTTPMessage& /*msg*/) noexcept override {
24  headersSent_ = true;
25  }
26 
27  void sendEOM() noexcept override {
28  // prevent using tx_
29  }
30 
31  bool headersSent_{false};
32 };
33 
34 void testExpectHandling(bool handlerResponds) {
35  StrictMock<MockRequestHandler> requestHandler_;
36  EXPECT_CALL(requestHandler_, canHandleExpect()).WillOnce(
37  Return(handlerResponds));
38  EXPECT_CALL(requestHandler_, onRequest(_));
39  auto adaptor = std::make_shared<StubRequestHandlerAdaptor>(&requestHandler_);
40  auto msg = std::make_unique<HTTPMessage>();
41  msg->getHeaders().add("Expect", "100-continue");
42  auto txHandler = std::dynamic_pointer_cast<HTTPTransactionHandler>(adaptor);
43  txHandler->onHeadersComplete(std::move(msg));
44  EXPECT_EQ(adaptor->headersSent_, !handlerResponds);
45 }
46 
47 TEST(RequestHandlerAdaptorTest, Expect) {
48  testExpectHandling(true /* handlerResponds */);
49  testExpectHandling(false /* handlerResponds */);
50 }
51 
52 TEST(RequestHandlerAdaptorTest, onError) {
53  NiceMock<MockRequestHandler> requestHandler_;
54  auto adaptor = new RequestHandlerAdaptor(&requestHandler_);
56  HTTP2PriorityQueue egressQueue;
57  HTTPTransaction txn(TransportDirection::DOWNSTREAM,
58  1, 1, transport, egressQueue);
59  txn.setHandler(adaptor);
60  // egress timeout error
61  HTTPException ex(HTTPException::Direction::EGRESS, "egress timeout");
63  txn.onError(ex);
64 }
virtual void setHandler(Handler *handler)
void onError(const HTTPException &error)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void testExpectHandling(bool handlerResponds)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void setProxygenError(ProxygenError proxygenError)
Definition: Exception.h:46
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
void Expect(bool condition, const char *file, int line, const string &msg)
void sendHeaders(HTTPMessage &) noexceptoverride
virtual void onHeadersComplete(std::unique_ptr< HTTPMessage > msg) noexcept=0
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST(SequencedExecutor, CPUThreadPoolExecutor)
internal::ReturnAction< R > Return(R value)