Upgrading dependencies to gorealis v2 and thrift 0.12.0
This commit is contained in:
parent
7cbbea498b
commit
54b8d7942a
1327 changed files with 137391 additions and 61476 deletions
85
vendor/git.apache.org/thrift.git/lib/cpp/test/TNonblockingServerTest.cpp
generated
vendored
85
vendor/git.apache.org/thrift.git/lib/cpp/test/TNonblockingServerTest.cpp
generated
vendored
|
@ -19,15 +19,28 @@
|
|||
|
||||
#define BOOST_TEST_MODULE TNonblockingServerTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
#include "thrift/concurrency/Monitor.h"
|
||||
#include "thrift/concurrency/Thread.h"
|
||||
#include "thrift/server/TNonblockingServer.h"
|
||||
#include "thrift/transport/TNonblockingServerSocket.h"
|
||||
#include "thrift/stdcxx.h"
|
||||
|
||||
#include "gen-cpp/ParentService.h"
|
||||
|
||||
#include <event.h>
|
||||
|
||||
using apache::thrift::concurrency::Guard;
|
||||
using apache::thrift::concurrency::Monitor;
|
||||
using apache::thrift::concurrency::Mutex;
|
||||
using apache::thrift::concurrency::PlatformThreadFactory;
|
||||
using apache::thrift::concurrency::Runnable;
|
||||
using apache::thrift::concurrency::Thread;
|
||||
using apache::thrift::concurrency::ThreadFactory;
|
||||
using apache::thrift::server::TServerEventHandler;
|
||||
using apache::thrift::stdcxx::make_shared;
|
||||
using apache::thrift::stdcxx::shared_ptr;
|
||||
|
||||
using namespace apache::thrift;
|
||||
|
||||
struct Handler : public test::ParentServiceIf {
|
||||
|
@ -46,11 +59,32 @@ struct Handler : public test::ParentServiceIf {
|
|||
|
||||
class Fixture {
|
||||
private:
|
||||
struct Runner : public apache::thrift::concurrency::Runnable {
|
||||
struct ListenEventHandler : public TServerEventHandler {
|
||||
public:
|
||||
ListenEventHandler(Mutex* mutex) : listenMonitor_(mutex), ready_(false) {}
|
||||
|
||||
void preServe() /* override */ {
|
||||
Guard g(listenMonitor_.mutex());
|
||||
ready_ = true;
|
||||
listenMonitor_.notify();
|
||||
}
|
||||
|
||||
Monitor listenMonitor_;
|
||||
bool ready_;
|
||||
};
|
||||
|
||||
struct Runner : public Runnable {
|
||||
int port;
|
||||
boost::shared_ptr<event_base> userEventBase;
|
||||
boost::shared_ptr<TProcessor> processor;
|
||||
boost::shared_ptr<server::TNonblockingServer> server;
|
||||
shared_ptr<event_base> userEventBase;
|
||||
shared_ptr<TProcessor> processor;
|
||||
shared_ptr<server::TNonblockingServer> server;
|
||||
shared_ptr<ListenEventHandler> listenHandler;
|
||||
shared_ptr<transport::TNonblockingServerSocket> socket;
|
||||
Mutex mutex_;
|
||||
|
||||
Runner() {
|
||||
listenHandler.reset(new ListenEventHandler(&mutex_));
|
||||
}
|
||||
|
||||
virtual void run() {
|
||||
// When binding to explicit port, allow retrying to workaround bind failures on ports in use
|
||||
|
@ -58,10 +92,19 @@ private:
|
|||
startServer(retryCount);
|
||||
}
|
||||
|
||||
void readyBarrier() {
|
||||
// block until server is listening and ready to accept connections
|
||||
Guard g(mutex_);
|
||||
while (!listenHandler->ready_) {
|
||||
listenHandler->listenMonitor_.wait();
|
||||
}
|
||||
}
|
||||
private:
|
||||
void startServer(int retry_count) {
|
||||
try {
|
||||
server.reset(new server::TNonblockingServer(processor, port));
|
||||
socket.reset(new transport::TNonblockingServerSocket(port));
|
||||
server.reset(new server::TNonblockingServer(processor, socket));
|
||||
server->setServerEventHandler(listenHandler);
|
||||
if (userEventBase) {
|
||||
server->registerEvents(userEventBase.get());
|
||||
}
|
||||
|
@ -82,7 +125,7 @@ private:
|
|||
};
|
||||
|
||||
protected:
|
||||
Fixture() : processor(new test::ParentServiceProcessor(boost::make_shared<Handler>())) {}
|
||||
Fixture() : processor(new test::ParentServiceProcessor(make_shared<Handler>())) {}
|
||||
|
||||
~Fixture() {
|
||||
if (server) {
|
||||
|
@ -98,31 +141,31 @@ protected:
|
|||
}
|
||||
|
||||
int startServer(int port) {
|
||||
boost::shared_ptr<Runner> runner(new Runner);
|
||||
shared_ptr<Runner> runner(new Runner);
|
||||
runner->port = port;
|
||||
runner->processor = processor;
|
||||
runner->userEventBase = userEventBase_;
|
||||
|
||||
boost::scoped_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory(
|
||||
new apache::thrift::concurrency::PlatformThreadFactory(
|
||||
shared_ptr<ThreadFactory> threadFactory(
|
||||
new PlatformThreadFactory(
|
||||
#if !USE_BOOST_THREAD && !USE_STD_THREAD
|
||||
concurrency::PlatformThreadFactory::OTHER, concurrency::PlatformThreadFactory::NORMAL,
|
||||
PlatformThreadFactory::OTHER, PlatformThreadFactory::NORMAL,
|
||||
1,
|
||||
#endif
|
||||
false));
|
||||
thread = threadFactory->newThread(runner);
|
||||
thread->start();
|
||||
// wait 100 ms for the server to begin listening
|
||||
THRIFT_SLEEP_USEC(100000);
|
||||
runner->readyBarrier();
|
||||
|
||||
server = runner->server;
|
||||
return runner->port;
|
||||
}
|
||||
|
||||
bool canCommunicate(int serverPort) {
|
||||
boost::shared_ptr<transport::TSocket> socket(new transport::TSocket("localhost", serverPort));
|
||||
shared_ptr<transport::TSocket> socket(new transport::TSocket("localhost", serverPort));
|
||||
socket->open();
|
||||
test::ParentServiceClient client(boost::make_shared<protocol::TBinaryProtocol>(
|
||||
boost::make_shared<transport::TFramedTransport>(socket)));
|
||||
test::ParentServiceClient client(make_shared<protocol::TBinaryProtocol>(
|
||||
make_shared<transport::TFramedTransport>(socket)));
|
||||
client.addString("foo");
|
||||
std::vector<std::string> strings;
|
||||
client.getStrings(strings);
|
||||
|
@ -130,12 +173,12 @@ protected:
|
|||
}
|
||||
|
||||
private:
|
||||
boost::shared_ptr<event_base> userEventBase_;
|
||||
boost::shared_ptr<test::ParentServiceProcessor> processor;
|
||||
shared_ptr<event_base> userEventBase_;
|
||||
shared_ptr<test::ParentServiceProcessor> processor;
|
||||
protected:
|
||||
boost::shared_ptr<server::TNonblockingServer> server;
|
||||
shared_ptr<server::TNonblockingServer> server;
|
||||
private:
|
||||
boost::shared_ptr<apache::thrift::concurrency::Thread> thread;
|
||||
shared_ptr<apache::thrift::concurrency::Thread> thread;
|
||||
|
||||
};
|
||||
|
||||
|
@ -148,7 +191,6 @@ BOOST_FIXTURE_TEST_CASE(get_specified_port, Fixture) {
|
|||
BOOST_CHECK(canCommunicate(specified_port));
|
||||
|
||||
server->stop();
|
||||
BOOST_CHECK_EQUAL(server->getListenPort(), specified_port);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(get_assigned_port, Fixture) {
|
||||
|
@ -159,7 +201,6 @@ BOOST_FIXTURE_TEST_CASE(get_assigned_port, Fixture) {
|
|||
BOOST_CHECK(canCommunicate(assigned_port));
|
||||
|
||||
server->stop();
|
||||
BOOST_CHECK_EQUAL(server->getListenPort(), 0);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(provide_event_base, Fixture) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue