17 #include <gtest/gtest.h> 30 using namespace folly;
38 std::unique_ptr<IOBuf>& result,
41 return result !=
nullptr;
53 return folly::to<int>(req);
57 template <
typename Req,
typename Resp>
63 std::shared_ptr<AsyncTransportWrapper>
socket)
override {
77 template <
typename Req,
typename Resp>
82 std::shared_ptr<AsyncTransportWrapper>
socket)
override {
92 template <
typename Pipeline,
typename Req,
typename Resp>
98 dispatcher_.setPipeline(pipeline);
110 std::make_shared<ClientService>(client->getPipeline()));
114 TEST(Wangle, ClientServerTest) {
122 auto client = std::make_shared<ClientBootstrap<ServicePipeline>>();
124 client->pipelineFactory(
130 auto service = serviceFactory(client).value();
131 auto rep = (*service)(
"test");
148 return (*service_)(req +
"\n");
160 return (*service_)(folly::to<std::string>(req))
161 .thenValue([](
std::string resp) {
return folly::to<int>(resp); });
166 auto service = std::make_shared<EchoService>();
167 auto filter = std::make_shared<AppendFilter>(service);
168 auto result = (*filter)(
"test");
172 TEST(Wangle, ComplexFilterTest) {
173 auto service = std::make_shared<EchoService>();
174 auto filter = std::make_shared<IntToStringFilter>(service);
175 auto result = (*filter)(1);
187 return (*service_)(folly::to<std::string>(req)).thenValue([](
int resp) {
188 return folly::to<std::string>(resp);
193 TEST(Wangle, SuperComplexFilterTest) {
194 auto service = std::make_shared<EchoIntService>();
195 auto filter = std::make_shared<ChangeTypeFilter>(service);
196 auto result = (*filter)(1);
200 template <
typename Pipeline,
typename Req,
typename Resp>
210 return (*this->serviceFactory_)(client);
213 int connectionCount{0};
227 auto countingFactory =
232 auto client = std::make_shared<ClientBootstrap<ServicePipeline>>();
233 client->pipelineFactory(
239 auto service = (*countingFactory)(client).
value();
242 service = (*countingFactory)(client).
value();
243 EXPECT_EQ(2, countingFactory->connectionCount);
250 std::make_shared<ConstFactory<ServicePipeline, std::string, std::string>>(
251 std::make_shared<EchoService>());
266 template <
class Clock>
279 std::shared_ptr<Service<std::string, std::string>> service =
280 std::make_shared<EchoService>();
281 std::shared_ptr<Service<std::string, std::string>> closeOnReleaseService =
282 std::make_shared<CloseOnReleaseFilter<std::string, std::string>>(service);
283 std::shared_ptr<Service<std::string, std::string>> expiringService =
284 std::make_shared<ExpiringFilter<std::string, std::string>>(
285 closeOnReleaseService,
286 std::chrono::milliseconds(0),
287 std::chrono::milliseconds(400),
290 EXPECT_EQ(
"test", (*expiringService)(
"test").
get());
292 EXPECT_TRUE((*expiringService)(
"test").getTry().hasException());
298 std::shared_ptr<Service<std::string, std::string>> service =
299 std::make_shared<EchoService>();
300 std::shared_ptr<Service<std::string, std::string>> closeOnReleaseService =
301 std::make_shared<CloseOnReleaseFilter<std::string, std::string>>(service);
302 std::shared_ptr<Service<std::string, std::string>> expiringService =
303 std::make_shared<ExpiringFilter<std::string, std::string>>(
304 closeOnReleaseService,
305 std::chrono::milliseconds(100),
306 std::chrono::milliseconds(0),
315 std::shared_ptr<Service<std::string, std::string>> service =
316 std::make_shared<EchoService>();
317 std::shared_ptr<Service<std::string, std::string>> closeOnReleaseService =
318 std::make_shared<CloseOnReleaseFilter<std::string, std::string>>(service);
319 std::shared_ptr<Service<std::string, std::string>> expiringService =
320 std::make_shared<ExpiringFilter<std::string, std::string>>(
321 closeOnReleaseService,
322 std::chrono::milliseconds(1),
323 std::chrono::milliseconds(0),
326 auto f = (*expiringService)(
"2000");
329 EXPECT_EQ(
"2000", (*expiringService)(
"2000").
get());
ConnectionCountFilter(std::shared_ptr< ServiceFactory< Pipeline, Req, Resp >> factory)
Future< std::string > operator()(std::string req) override
Future< Unit > after(Duration) override
EventBase * getEventBase() const
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
AppendFilter(std::shared_ptr< Service< std::string, std::string >> service)
TEST(Wangle, ClientServerTest)
Future< Unit > at(std::chrono::time_point< Clock >)
bool decode(Context *, IOBufQueue &buf, std::unique_ptr< IOBuf > &result, size_t &) override
void bind(folly::AsyncServerSocket::UniquePtr s)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
EventBase * getEventBase()
ServicePipeline::Ptr newPipeline(std::shared_ptr< AsyncTransportWrapper > socket) override
Future< Resp > operator()(Req request) override
Future< int > operator()(std::string req) override
std::unique_ptr< folly::IOBuf > move()
—— Concurrent Priority Queue Implementation ——
Future< std::string > operator()(std::string req) override
SerialClientDispatcher< Pipeline, Req, Resp > dispatcher_
static EventBaseManager * get()
ServerBootstrap * childPipeline(std::shared_ptr< PipelineFactory< Pipeline >> factory)
InboundHandler< folly::IOBufQueue &, M >::Context Context
std::chrono::milliseconds Duration
std::vector< Promise< Unit > > promises_
Future< std::string > operator()(int req) override
NetworkSocket socket(int af, int type, int protocol)
Future< std::shared_ptr< Service< Req, Resp > > > operator()(std::shared_ptr< ClientBootstrap< Pipeline >> client) override
static const char *const value
const std::vector< std::shared_ptr< folly::AsyncSocketBase > > & getSockets() const
ServicePipeline::Ptr newPipeline(std::shared_ptr< AsyncTransportWrapper > socket) override
ChangeTypeFilter(std::shared_ptr< Service< std::string, int >> service)
#define EXPECT_TRUE(condition)
IntToStringFilter(std::shared_ptr< Service< std::string, std::string >> service)
Future< int > operator()(int req) override
std::shared_ptr< Pipeline > Ptr
Pipeline< IOBufQueue &, std::string > ServicePipeline
ClientService(Pipeline *pipeline)
ThreadPoolListHook * addr