apache::thrift::RocketClientChannel::Ptr ThriftTransportBase::createChannel() { auto socket = getConnectingSocket(); if (!socket) { return nullptr; } auto channel = apache::thrift::RocketClientChannel::newChannel(std::move(socket)); channel->setProtocolId(apache::thrift::protocol::T_COMPACT_PROTOCOL); channel->setCloseCallback(this); return channel; }
HTTPClientChannel::Ptr HTTPClientChannel::newHTTP1xChannel( apache::thrift::async::TAsyncTransport::UniquePtr transport, const std::string& host, const std::string& url) { auto channel = newChannel(std::move(transport), host, url, folly::make_unique<proxygen::HTTP1xCodec>( proxygen::TransportDirection::UPSTREAM)); channel->setProtocolId(apache::thrift::protocol::T_BINARY_PROTOCOL); return channel; }
void testClientWithHandler() { auto handler = std::make_shared<Handler>(); auto pFac = std::make_shared<ThriftServerAsyncProcessorFactory<Handler>>(handler); apache::thrift::server::ServerConfigsMock serverConfigs; auto connection = std::make_shared<InMemoryConnection>(pFac, serverConfigs); auto thriftClient = ThriftClient::Ptr(new ThriftClient(connection)); thriftClient->setProtocolId(apache::thrift::protocol::T_COMPACT_PROTOCOL); auto divisionClient = std::make_unique<DivisionAsyncClient>(std::move(thriftClient)); // Synchronous client EXPECT_EQ(3, divisionClient->sync_divide(15, 5)); EXPECT_THROW({ divisionClient->sync_divide(1, 0); }, DivideByZero);