proxygen
OutputBufferingHandlerTest.cpp File Reference
#include <wangle/channel/StaticPipeline.h>
#include <wangle/channel/OutputBufferingHandler.h>
#include <wangle/channel/test/MockHandler.h>
#include <folly/io/async/AsyncSocket.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>

Go to the source code of this file.

Typedefs

typedef StrictMock< MockHandlerAdapter< IOBufQueue &, std::unique_ptr< IOBuf > > > MockBytesHandler
 

Functions

 MATCHER_P (IOBufContains, str,"")
 
 TEST (OutputBufferingHandlerTest, Basic)
 

Typedef Documentation

Definition at line 31 of file OutputBufferingHandlerTest.cpp.

Function Documentation

MATCHER_P ( IOBufContains  ,
str  ,
""   
)

Definition at line 33 of file OutputBufferingHandlerTest.cpp.

33 { return arg->moveToFbString() == str; }
TEST ( OutputBufferingHandlerTest  ,
Basic   
)

Definition at line 35 of file OutputBufferingHandlerTest.cpp.

References testing::_, folly::IOBuf::copyBuffer(), EXPECT_CALL, EXPECT_FALSE, EXPECT_TRUE, f, folly::EventBase::loopOnce(), folly::AsyncSocket::newSocket(), and folly::netops::socket().

35  {
36  MockBytesHandler mockHandler;
37  EXPECT_CALL(mockHandler, attachPipeline(_));
40  OutputBufferingHandler>::create(
41  &mockHandler,
43 
44  EventBase eb;
45  auto socket = AsyncSocket::newSocket(&eb);
46  pipeline->setTransport(socket);
47 
48  // Buffering should prevent writes until the EB loops, and the writes should
49  // be batched into one write call.
50  auto f1 = pipeline->write(IOBuf::copyBuffer("hello"));
51  auto f2 = pipeline->write(IOBuf::copyBuffer("world"));
52  EXPECT_FALSE(f1.isReady());
53  EXPECT_FALSE(f2.isReady());
54  EXPECT_CALL(mockHandler, write_(_, IOBufContains("helloworld")));
55  eb.loopOnce();
56  EXPECT_TRUE(f1.isReady());
57  EXPECT_TRUE(f2.isReady());
58  EXPECT_CALL(mockHandler, detachPipeline(_));
59 
60  // Make sure the SharedPromise resets correctly
61  auto f = pipeline->write(IOBuf::copyBuffer("foo"));
62  EXPECT_FALSE(f.isReady());
63  EXPECT_CALL(mockHandler, write_(_, IOBufContains("foo")));
64  eb.loopOnce();
65  EXPECT_TRUE(f.isReady());
66  pipeline.reset();
67 }
auto f
StrictMock< MockHandlerAdapter< IOBufQueue &, std::unique_ptr< IOBuf > > > MockBytesHandler
bool loopOnce(int flags=0)
Definition: EventBase.cpp:271
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862