proxygen
HTTPTransactionMocks.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-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  */
10 #pragma once
11 
15 
16 namespace proxygen {
17 
18 #if defined(__clang__) && __clang_major__ >= 3 && __clang_minor__ >= 6
19 #pragma clang diagnostic push
20 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
21 #endif
22 
24  public:
26  EXPECT_CALL(*this, getCodecNonConst())
27  .WillRepeatedly(testing::ReturnRef(mockCodec_));
28  }
33  const HTTPMessage&,
35  bool));
37  size_t(HTTPTransaction*, std::shared_ptr<folly::IOBuf>,
38  bool, bool));
39 
40  size_t sendBody(HTTPTransaction* txn, std::unique_ptr<folly::IOBuf> iob,
41  bool eom, bool trackLastByteFlushed) noexcept override {
42  return sendBody(txn,
43  std::shared_ptr<folly::IOBuf>(iob.release()), eom, trackLastByteFlushed);
44  }
45 
47  size_t));
50  , noexcept, , sendEOM, size_t(HTTPTransaction*, const HTTPHeaders*));
52  ErrorCode));
54  size_t(HTTPTransaction*, const http2::PriorityUpdate&));
58  uint32_t));
61  GMOCK_METHOD0_(, noexcept,, getLocalAddressNonConst,
62  const folly::SocketAddress&());
64  HTTPTransaction*(HTTPCodec::StreamID assocStreamId,
68  HTTPCodec::StreamID controlStream,
69  bool unidirectional));
70 
72  const noexcept override {
73  return const_cast<MockHTTPTransactionTransport*>(this)
74  ->getLocalAddressNonConst();
75  }
76  GMOCK_METHOD0_(, noexcept,, getPeerAddressNonConst,
77  const folly::SocketAddress&());
79  const noexcept override {
80  return const_cast<MockHTTPTransactionTransport*>(this)
81  ->getPeerAddressNonConst();
82  }
83  MOCK_CONST_METHOD1(describe, void(std::ostream&));
84  GMOCK_METHOD0_(, noexcept,, getSetupTransportInfoNonConst,
85  const wangle::TransportInfo&());
87  return const_cast<MockHTTPTransactionTransport*>(this)
88  ->getSetupTransportInfoNonConst();
89  }
90 
92  GMOCK_METHOD0_(, noexcept,, getCodecNonConst, const HTTPCodec&());
93  const HTTPCodec& getCodec() const noexcept override {
94  return const_cast<MockHTTPTransactionTransport*>(this)
95  ->getCodecNonConst();
96  }
97  MOCK_METHOD0(drain, void());
100 
101  MOCK_CONST_METHOD0(getTransport, const folly::AsyncTransportWrapper*());
102  MOCK_METHOD0(getTransport, folly::AsyncTransportWrapper*());
103 
109 
110  GMOCK_METHOD0_(, noexcept,, getUnderlyingTransportNonConst,
113  const noexcept override {
114  return const_cast<MockHTTPTransactionTransport*>(this)
116  }
120 
123 
125 };
126 
128  public:
131  uint32_t seqNo,
132  // Must be const for gmock
133  const HTTP2PriorityQueue& egressQueue,
134  folly::HHWheelTimer* timer = nullptr,
138  HTTPSessionStats* stats = nullptr,
139  bool useFlowControl = false,
140  uint32_t receiveInitialWindowSize = 0,
141  uint32_t sendInitialWindowSize = 0,
147  HTTPTransaction(direction, id, seqNo, mockTransport_,
148  const_cast<HTTP2PriorityQueue&>(egressQueue),
149  timer, transactionTimeout, stats, useFlowControl,
150  receiveInitialWindowSize,
151  sendInitialWindowSize,
152  priority, assocStreamId, exAttributes),
153  defaultAddress_("127.0.0.1", 80) {
154  EXPECT_CALL(mockTransport_, getLocalAddressNonConst())
155  .WillRepeatedly(testing::ReturnRef(defaultAddress_));
156  EXPECT_CALL(mockTransport_, getPeerAddressNonConst())
157  .WillRepeatedly(testing::ReturnRef(defaultAddress_));
158  EXPECT_CALL(mockTransport_, getCodecNonConst())
159  .WillRepeatedly(testing::ReturnRef(mockCodec_));
160  EXPECT_CALL(mockTransport_, getSetupTransportInfoNonConst())
161  .WillRepeatedly(testing::ReturnRef(setupTransportInfo_));
162 
163  // Some tests unfortunately require a half-mocked HTTPTransaction.
164  ON_CALL(*this, setHandler(testing::_))
165  .WillByDefault(testing::Invoke([this] (HTTPTransactionHandler* handler) {
166  this->setHandlerUnmocked(handler);
167  }));
168 
169  // By default we expect canSendHeaders in test to return true
170  // Tests that specifically require canSendHeaders to return false need
171  // to set the behavior locally. This is due to the fact that the mocked
172  // methods below imply internal state is not correctly tracked/managed
173  // in the context of tests
174  ON_CALL(*this, canSendHeaders()).WillByDefault(testing::Return(true));
175  }
176 
179  uint32_t seqNo,
180  // Must be const for gmock
181  const HTTP2PriorityQueue& egressQueue,
182  const WheelTimerInstance& timeout,
183  HTTPSessionStats* stats = nullptr,
184  bool useFlowControl = false,
185  uint32_t receiveInitialWindowSize = 0,
186  uint32_t sendInitialWindowSize = 0,
192  MockHTTPTransaction(direction,
193  id,
194  seqNo,
195  egressQueue,
196  timeout.getWheelTimer(),
197  timeout.getDefaultTimeout(),
198  stats,
199  useFlowControl,
200  receiveInitialWindowSize,
201  sendInitialWindowSize,
202  priority,
203  assocStreamId,
204  exAttributes) {}
205 
208  uint32_t seqNo,
209  // Must be const for gmock
210  const HTTP2PriorityQueue& egressQueue,
211  const WheelTimerInstance& timeout,
213  MockHTTPTransaction(direction,
214  id,
215  seqNo,
216  egressQueue,
217  timeout.getWheelTimer(),
218  timeout.getDefaultTimeout(),
219  nullptr,
220  false,
221  0,
222  0,
223  http2::DefaultPriority,
224  HTTPCodec::NoStream,
225  exAttributes) {}
226 
227  MOCK_CONST_METHOD0(extraResponseExpected, bool());
228 
229  MOCK_METHOD1(setHandler, void(HTTPTransactionHandler*));
230 
233  }
234 
235  MOCK_CONST_METHOD0(canSendHeaders, bool());
236  MOCK_METHOD1(sendHeaders, void(const HTTPMessage& headers));
237  MOCK_METHOD1(sendHeadersWithEOM, void(const HTTPMessage& headers));
238  MOCK_METHOD1(sendBody, void(std::shared_ptr<folly::IOBuf>));
239  void sendBody(std::unique_ptr<folly::IOBuf> iob) noexcept override {
240  sendBody(std::shared_ptr<folly::IOBuf>(iob.release()));
241  }
242  MOCK_METHOD1(sendChunkHeader, void(size_t));
244  MOCK_METHOD1(sendTrailers, void(const HTTPHeaders& trailers));
245  MOCK_METHOD0(sendEOM, void());
246  MOCK_METHOD0(sendAbort, void());
247  MOCK_METHOD0(drop, void());
248  MOCK_METHOD0(pauseIngress, void());
249  MOCK_METHOD0(resumeIngress, void());
250  MOCK_CONST_METHOD0(handlerEgressPaused, bool());
253  MOCK_METHOD1(setReceiveWindow, void(uint32_t));
254  MOCK_CONST_METHOD0(getReceiveWindow, const Window&());
255 
260 
261  void enablePush() {
262  EXPECT_CALL(mockCodec_, supportsPushTransactions())
263  .WillRepeatedly(testing::Return(true));
264  }
265 
270 };
271 
274  public:
276  GMOCK_METHOD0_(, noexcept,, firstHeaderByteFlushed, void());
277  GMOCK_METHOD0_(, noexcept,, firstByteFlushed, void());
278  GMOCK_METHOD0_(, noexcept,, trackedByteFlushed, void());
279  GMOCK_METHOD0_(, noexcept,, lastByteFlushed, void());
280  GMOCK_METHOD1_(, noexcept,, lastByteAcked, void(std::chrono::milliseconds));
281  GMOCK_METHOD1_(, noexcept,, headerBytesGenerated, void(HTTPHeaderSize&));
282  GMOCK_METHOD1_(, noexcept,, headerBytesReceived, void(const HTTPHeaderSize&));
283  GMOCK_METHOD1_(, noexcept,, bodyBytesGenerated, void(size_t));
284  GMOCK_METHOD1_(, noexcept,, bodyBytesReceived, void(size_t));
285 };
286 
287 #if defined(__clang__) && __clang_major__ >= 3 && __clang_minor__ >= 6
288 #pragma clang diagnostic pop
289 #endif
290 
291 }
virtual void setHandler(Handler *handler)
virtual void resumeIngress(HTTPTransaction *txn) noexcept=0
GMOCK_METHOD2_(, noexcept,, sendChunkHeader, size_t(HTTPTransaction *, size_t))
virtual bool getHTTP2PrioritiesEnabled() const =0
virtual void sendHeaders(HTTPTransaction *txn, const HTTPMessage &headers, HTTPHeaderSize *size, bool eom) noexcept=0
const folly::SocketAddress & getLocalAddress() const noexceptoverride
virtual size_t sendChunkTerminator(HTTPTransaction *txn) noexcept=0
virtual bool isDraining() const =0
const wangle::TransportInfo & getSetupTransportInfo() const noexceptoverride
const HTTPCodec & getCodec() const noexceptoverride
MockHTTPTransaction(TransportDirection direction, HTTPCodec::StreamID id, uint32_t seqNo, const HTTP2PriorityQueue &egressQueue, const WheelTimerInstance &timeout, HTTPSessionStats *stats=nullptr, bool useFlowControl=false, uint32_t receiveInitialWindowSize=0, uint32_t sendInitialWindowSize=0, http2::PriorityUpdate priority=http2::DefaultPriority, folly::Optional< HTTPCodec::StreamID > assocStreamId=HTTPCodec::NoStream, folly::Optional< HTTPCodec::ExAttributes > exAttributes=HTTPCodec::NoExAttributes)
requires E e noexcept(noexcept(s.error(std::move(e))))
const folly::SocketAddress & getPeerAddress() const noexceptoverride
#define nullptr
Definition: http_parser.c:41
internal::ReturnRefAction< R > ReturnRef(R &x)
virtual HTTPTransaction * newExTransaction(HTTPTransaction::Handler *handler, HTTPCodec::StreamID controlStream, bool unidirectional) noexcept=0
virtual void detach(HTTPTransaction *txn) noexcept=0
MOCK_METHOD1(getCurrentTransportInfo, bool(wangle::TransportInfo *))
virtual void addWaitingForReplaySafety(folly::AsyncTransport::ReplaySafetyCallback *callback) noexcept=0
void handler(int, siginfo_t *, void *)
MockHTTPTransaction(TransportDirection direction, HTTPCodec::StreamID id, uint32_t seqNo, const HTTP2PriorityQueue &egressQueue, const WheelTimerInstance &timeout, folly::Optional< HTTPCodec::ExAttributes > exAttributes)
GMOCK_METHOD4_(, noexcept,, sendHeaders, void(HTTPTransaction *, const HTTPMessage &, HTTPHeaderSize *, bool))
void setHandlerUnmocked(HTTPTransactionHandler *handler)
virtual void notifyEgressBodyBuffered(int64_t bytes) noexcept=0
const folly::SocketAddress defaultAddress_
virtual bool needToBlockForReplaySafety() const =0
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
virtual size_t sendAbort(HTTPTransaction *txn, ErrorCode statusCode) noexcept=0
virtual std::string getSecurityProtocol() const =0
virtual size_t sendEOM(HTTPTransaction *txn, const HTTPHeaders *trailers) noexcept=0
virtual size_t sendWindowUpdate(HTTPTransaction *txn, uint32_t bytes) noexcept=0
virtual void describe(std::ostream &) const =0
virtual void pauseIngress(HTTPTransaction *txn) noexcept=0
void sendBody(std::unique_ptr< folly::IOBuf > iob) noexceptoverride
virtual bool isReplaySafe() const =0
GMOCK_METHOD0_(, noexcept,, notifyPendingEgress, void())
virtual void notifyIngressBodyProcessed(uint32_t bytes) noexcept=0
size_t sendBody(HTTPTransaction *txn, std::unique_ptr< folly::IOBuf > iob, bool eom, bool trackLastByteFlushed) noexceptoverride
virtual size_t sendChunkHeader(HTTPTransaction *txn, size_t length) noexcept=0
const PriorityUpdate DefaultPriority
Definition: HTTP2Framer.cpp:21
virtual void transactionTimeout(HTTPTransaction *txn) noexcept=0
GMOCK_METHOD3_(, noexcept,, newExTransaction, HTTPTransaction *(HTTPTransaction::Handler *handler, HTTPCodec::StreamID controlStream, bool unidirectional))
testing::NiceMock< MockHTTPTransactionTransport > mockTransport_
#define ON_CALL(obj, call)
virtual size_t sendPriority(HTTPTransaction *txn, const http2::PriorityUpdate &pri) noexcept=0
const folly::AsyncTransportWrapper * getUnderlyingTransport() const noexceptoverride
const char * string
Definition: Conv.cpp:212
virtual void setHTTP2PrioritiesEnabled(bool enabled)=0
const
Definition: upload.py:398
MockHTTPTransaction(TransportDirection direction, HTTPCodec::StreamID id, uint32_t seqNo, const HTTP2PriorityQueue &egressQueue, folly::HHWheelTimer *timer=nullptr, const folly::Optional< std::chrono::milliseconds > &transactionTimeout=folly::Optional< std::chrono::milliseconds >(), HTTPSessionStats *stats=nullptr, bool useFlowControl=false, uint32_t receiveInitialWindowSize=0, uint32_t sendInitialWindowSize=0, http2::PriorityUpdate priority=http2::DefaultPriority, folly::Optional< HTTPCodec::StreamID > assocStreamId=HTTPCodec::NoStream, folly::Optional< HTTPCodec::ExAttributes > exAttributes=HTTPCodec::NoExAttributes)
#define EXPECT_CALL(obj, call)
virtual folly::Optional< const HTTPMessage::HTTPPriority > getHTTPPriority(uint8_t level)=0
static const folly::Optional< StreamID > NoStream
Definition: HTTPCodec.h:51
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
virtual HTTPTransaction * newPushedTransaction(HTTPCodec::StreamID assocStreamId, HTTPTransaction::PushHandler *handler) noexcept=0
wangle::TransportInfo setupTransportInfo_
MOCK_CONST_METHOD1(describe, void(std::ostream &))
virtual bool getCurrentTransportInfo(wangle::TransportInfo *tinfo)=0
virtual void notifyPendingEgress() noexcept=0
virtual void removeWaitingForReplaySafety(folly::AsyncTransport::ReplaySafetyCallback *callback) noexcept=0
GMOCK_METHOD1_(, noexcept,, pauseIngress, void(HTTPTransaction *))
internal::ReturnAction< R > Return(R value)
static const folly::Optional< ExAttributes > NoExAttributes
Definition: HTTPCodec.h:66