proxygen
OutputBufferingHandlerTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
23 
24 using namespace folly;
25 using namespace wangle;
26 using namespace testing;
27 
29  IOBufQueue&,
30  std::unique_ptr<IOBuf>>>
32 
33 MATCHER_P(IOBufContains, str, "") { return arg->moveToFbString() == str; }
34 
35 TEST(OutputBufferingHandlerTest, Basic) {
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
MATCHER_P(IOBufContains, str,"")
StrictMock< MockHandlerAdapter< IOBufQueue &, std::unique_ptr< IOBuf > > > MockBytesHandler
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
bool loopOnce(int flags=0)
Definition: EventBase.cpp:271
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static std::shared_ptr< AsyncSocket > newSocket(EventBase *evb)
Definition: AsyncSocket.h:281
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
TEST(SequencedExecutor, CPUThreadPoolExecutor)