proxygen
Mocks.h
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 
17 #pragma once
18 
25 
26 #include <boost/thread.hpp>
27 #include <gmock/gmock.h>
28 #include <gtest/gtest.h>
29 
30 namespace wangle {
31 
37  public:
39  : pipeline_(pipeline) {}
40 
42  return pipeline_;
43  }
44 
45  void cleanup() {
46  pipeline_.reset();
47  }
48 
49  protected:
51 };
52 
57  : public AcceptRoutingHandler<DefaultPipeline, char> {
58  public:
61  std::shared_ptr<RoutingDataHandlerFactory<char>> routingHandlerFactory,
63  childPipelineFactory,
64  DefaultPipeline::Ptr routingPipeline)
66  server,
67  routingHandlerFactory,
68  childPipelineFactory),
69  routingPipeline_(routingPipeline) {}
70 
71  protected:
73  return routingPipeline_;
74  }
76 };
77 
79  public:
80  MockRoutingDataHandler(uint64_t connId, Callback* cob)
81  : RoutingDataHandler<char>(connId, cob) {}
82  MOCK_METHOD1(transportActive, void(Context*));
84  parseRoutingData,
85  bool(folly::IOBufQueue& bufQueue, RoutingData& routingData));
86  MOCK_METHOD2(readException, void(Context*, folly::exception_wrapper ex));
87 };
88 
90  public:
92 
93  std::shared_ptr<RoutingDataHandler<char>> newHandler(
94  uint64_t /*connId*/,
95  RoutingDataHandler<char>::Callback* /*cob*/) override {
96  VLOG(4) << "New pipeline with a test routing handler";
97  return std::shared_ptr<RoutingDataHandler<char>>(routingDataHandler_);
98  }
99  void setRoutingDataHandler(MockRoutingDataHandler* routingDataHandler) {
100  routingDataHandler_ = routingDataHandler;
101  }
102 
103  protected:
105 };
106 
108  : public RoutingDataPipelineFactory<DefaultPipeline, char> {
109  public:
111  MockBytesToBytesHandler* downstreamHandler)
112  : downstreamHandler_(downstreamHandler) {}
114  std::shared_ptr<folly::AsyncTransportWrapper> socket,
115  const char& /*routingData*/,
116  RoutingDataHandler<char>* /*handler*/,
117  std::shared_ptr<TransportInfo> /*transportInfo*/) override {
118  auto pipeline = DefaultPipeline::create();
119  pipeline->addBack(AsyncSocketHandler(socket));
120  pipeline->addBack(
121  std::shared_ptr<MockBytesToBytesHandler>(downstreamHandler_));
122  pipeline->finalize();
123  return pipeline;
124  }
125 
126  protected:
128 };
129 } // namespace wangle
DefaultPipeline::Ptr newRoutingPipeline() override
Definition: Mocks.h:72
void setRoutingDataHandler(MockRoutingDataHandler *routingDataHandler)
Definition: Mocks.h:99
MockBytesToBytesHandler * downstreamHandler_
Definition: Mocks.h:127
DefaultPipeline::Ptr routingPipeline_
Definition: Mocks.h:75
MockRoutingDataHandler(uint64_t connId, Callback *cob)
Definition: Mocks.h:80
AcceptPipeline::Ptr pipeline_
Definition: Mocks.h:50
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
MockRoutingDataHandler * routingDataHandler_
Definition: Mocks.h:104
#define MOCK_METHOD1(m,...)
static Ptr create()
Definition: Pipeline.h:174
AcceptPipeline::Ptr newPipeline(Acceptor *) override
Definition: Mocks.h:41
std::shared_ptr< Pipeline > Ptr
Definition: Pipeline.h:172
Handler< R, R, W, W >::Context Context
Definition: Handler.h:161
MockAcceptPipelineFactory(AcceptPipeline::Ptr pipeline)
Definition: Mocks.h:38
MockDownstreamPipelineFactory(MockBytesToBytesHandler *downstreamHandler)
Definition: Mocks.h:110
MockAcceptRoutingHandler(ServerBootstrap< DefaultPipeline > *server, std::shared_ptr< RoutingDataHandlerFactory< char >> routingHandlerFactory, std::shared_ptr< RoutingDataPipelineFactory< DefaultPipeline, char >> childPipelineFactory, DefaultPipeline::Ptr routingPipeline)
Definition: Mocks.h:59
#define MOCK_METHOD2(m,...)
std::shared_ptr< RoutingDataHandler< char > > newHandler(uint64_t, RoutingDataHandler< char >::Callback *) override
Definition: Mocks.h:93
DefaultPipeline::Ptr newPipeline(std::shared_ptr< folly::AsyncTransportWrapper > socket, const char &, RoutingDataHandler< char > *, std::shared_ptr< TransportInfo >) override
Definition: Mocks.h:113