http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/server/TThreadPoolServer.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/server/TThreadPoolServer.h b/lib/cpp/src/thrift/server/TThreadPoolServer.h index 267dbad..189d7e9 100644 --- a/lib/cpp/src/thrift/server/TThreadPoolServer.h +++ b/lib/cpp/src/thrift/server/TThreadPoolServer.h @@ -33,40 +33,40 @@ namespace server { class TThreadPoolServer : public TServerFramework { public: TThreadPoolServer( - const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager = - apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); + const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager + = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); TThreadPoolServer( - const boost::shared_ptr<apache::thrift::TProcessor>& processor, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager = - apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); + const boost::shared_ptr<apache::thrift::TProcessor>& processor, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager + = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); TThreadPoolServer( - const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager = - apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); + const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager + = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); TThreadPoolServer( - const boost::shared_ptr<apache::thrift::TProcessor>& processor, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager = - apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); + const boost::shared_ptr<apache::thrift::TProcessor>& processor, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager + = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); virtual ~TThreadPoolServer(); @@ -86,7 +86,7 @@ public: protected: virtual void onClientConnected(const boost::shared_ptr<TConnectedClient>& pClient) /* override */; - virtual void onClientDisconnected(TConnectedClient *pClient) /* override */; + virtual void onClientDisconnected(TConnectedClient* pClient) /* override */; boost::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager_; @@ -96,7 +96,6 @@ protected: volatile int64_t taskExpiration_; }; - } } } // apache::thrift::server
http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/server/TThreadedServer.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/server/TThreadedServer.cpp b/lib/cpp/src/thrift/server/TThreadedServer.cpp index 98b02c5..92f5cf8 100644 --- a/lib/cpp/src/thrift/server/TThreadedServer.cpp +++ b/lib/cpp/src/thrift/server/TThreadedServer.cpp @@ -36,52 +36,58 @@ using apache::thrift::transport::TTransportFactory; using boost::shared_ptr; using std::string; -TThreadedServer::TThreadedServer( - const shared_ptr<TProcessorFactory>& processorFactory, - const shared_ptr<TServerTransport>& serverTransport, - const shared_ptr<TTransportFactory>& transportFactory, - const shared_ptr<TProtocolFactory>& protocolFactory, - const shared_ptr<ThreadFactory>& threadFactory) +TThreadedServer::TThreadedServer(const shared_ptr<TProcessorFactory>& processorFactory, + const shared_ptr<TServerTransport>& serverTransport, + const shared_ptr<TTransportFactory>& transportFactory, + const shared_ptr<TProtocolFactory>& protocolFactory, + const shared_ptr<ThreadFactory>& threadFactory) : TServerFramework(processorFactory, serverTransport, transportFactory, protocolFactory), - threadFactory_(threadFactory) {} - + threadFactory_(threadFactory) { +} -TThreadedServer::TThreadedServer( - const shared_ptr<TProcessor>& processor, - const shared_ptr<TServerTransport>& serverTransport, - const shared_ptr<TTransportFactory>& transportFactory, - const shared_ptr<TProtocolFactory>& protocolFactory, - const shared_ptr<ThreadFactory>& threadFactory) +TThreadedServer::TThreadedServer(const shared_ptr<TProcessor>& processor, + const shared_ptr<TServerTransport>& serverTransport, + const shared_ptr<TTransportFactory>& transportFactory, + const shared_ptr<TProtocolFactory>& protocolFactory, + const shared_ptr<ThreadFactory>& threadFactory) : TServerFramework(processor, serverTransport, transportFactory, protocolFactory), - threadFactory_(threadFactory) {} + threadFactory_(threadFactory) { +} -TThreadedServer::TThreadedServer( - const shared_ptr<TProcessorFactory>& processorFactory, - const shared_ptr<TServerTransport>& serverTransport, - const shared_ptr<TTransportFactory>& inputTransportFactory, - const shared_ptr<TTransportFactory>& outputTransportFactory, - const shared_ptr<TProtocolFactory>& inputProtocolFactory, - const shared_ptr<TProtocolFactory>& outputProtocolFactory, - const shared_ptr<ThreadFactory>& threadFactory) - : TServerFramework(processorFactory, serverTransport, - inputTransportFactory, outputTransportFactory, - inputProtocolFactory, outputProtocolFactory), - threadFactory_(threadFactory) {} +TThreadedServer::TThreadedServer(const shared_ptr<TProcessorFactory>& processorFactory, + const shared_ptr<TServerTransport>& serverTransport, + const shared_ptr<TTransportFactory>& inputTransportFactory, + const shared_ptr<TTransportFactory>& outputTransportFactory, + const shared_ptr<TProtocolFactory>& inputProtocolFactory, + const shared_ptr<TProtocolFactory>& outputProtocolFactory, + const shared_ptr<ThreadFactory>& threadFactory) + : TServerFramework(processorFactory, + serverTransport, + inputTransportFactory, + outputTransportFactory, + inputProtocolFactory, + outputProtocolFactory), + threadFactory_(threadFactory) { +} -TThreadedServer::TThreadedServer( - const shared_ptr<TProcessor>& processor, - const shared_ptr<TServerTransport>& serverTransport, - const shared_ptr<TTransportFactory>& inputTransportFactory, - const shared_ptr<TTransportFactory>& outputTransportFactory, - const shared_ptr<TProtocolFactory>& inputProtocolFactory, - const shared_ptr<TProtocolFactory>& outputProtocolFactory, - const shared_ptr<ThreadFactory>& threadFactory) - : TServerFramework(processor, serverTransport, - inputTransportFactory, outputTransportFactory, - inputProtocolFactory, outputProtocolFactory), - threadFactory_(threadFactory) {} +TThreadedServer::TThreadedServer(const shared_ptr<TProcessor>& processor, + const shared_ptr<TServerTransport>& serverTransport, + const shared_ptr<TTransportFactory>& inputTransportFactory, + const shared_ptr<TTransportFactory>& outputTransportFactory, + const shared_ptr<TProtocolFactory>& inputProtocolFactory, + const shared_ptr<TProtocolFactory>& outputProtocolFactory, + const shared_ptr<ThreadFactory>& threadFactory) + : TServerFramework(processor, + serverTransport, + inputTransportFactory, + outputTransportFactory, + inputProtocolFactory, + outputProtocolFactory), + threadFactory_(threadFactory) { +} -TThreadedServer::~TThreadedServer() {} +TThreadedServer::~TThreadedServer() { +} void TThreadedServer::serve() { TServerFramework::serve(); @@ -90,7 +96,7 @@ void TThreadedServer::serve() { try { Synchronized s(clientsMonitor_); while (getConcurrentClientCount() > 0) { - clientsMonitor_.wait(); + clientsMonitor_.wait(); } } catch (TException& tx) { string errStr = string("TThreadedServer: Exception joining workers: ") + tx.what(); @@ -109,7 +115,6 @@ void TThreadedServer::onClientDisconnected(TConnectedClient* pClient) { clientsMonitor_.notify(); } } - } } } // apache::thrift::server http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/server/TThreadedServer.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/server/TThreadedServer.h b/lib/cpp/src/thrift/server/TThreadedServer.h index 21b6a28..cdacfd7 100644 --- a/lib/cpp/src/thrift/server/TThreadedServer.h +++ b/lib/cpp/src/thrift/server/TThreadedServer.h @@ -34,41 +34,45 @@ namespace server { */ class TThreadedServer : public TServerFramework { public: - TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory = - boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( - new apache::thrift::concurrency::PlatformThreadFactory)); + TThreadedServer( + const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory + = boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( + new apache::thrift::concurrency::PlatformThreadFactory)); - TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessor>& processor, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory = - boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( - new apache::thrift::concurrency::PlatformThreadFactory)); + TThreadedServer( + const boost::shared_ptr<apache::thrift::TProcessor>& processor, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory + = boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( + new apache::thrift::concurrency::PlatformThreadFactory)); - TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory = - boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( - new apache::thrift::concurrency::PlatformThreadFactory)); + TThreadedServer( + const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory + = boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( + new apache::thrift::concurrency::PlatformThreadFactory)); - TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessor>& processor, - const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, - const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, - const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, - const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory = - boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( - new apache::thrift::concurrency::PlatformThreadFactory)); + TThreadedServer( + const boost::shared_ptr<apache::thrift::TProcessor>& processor, + const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, + const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, + const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, + const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory + = boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( + new apache::thrift::concurrency::PlatformThreadFactory)); virtual ~TThreadedServer(); @@ -80,12 +84,11 @@ public: protected: virtual void onClientConnected(const boost::shared_ptr<TConnectedClient>& pClient) /* override */; - virtual void onClientDisconnected(TConnectedClient *pClient) /* override */; + virtual void onClientDisconnected(TConnectedClient* pClient) /* override */; boost::shared_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory_; apache::thrift::concurrency::Monitor clientsMonitor_; }; - } } } // apache::thrift::server http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/transport/TBufferTransports.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TBufferTransports.cpp b/lib/cpp/src/thrift/transport/TBufferTransports.cpp index af551c3..700bdd5 100644 --- a/lib/cpp/src/thrift/transport/TBufferTransports.cpp +++ b/lib/cpp/src/thrift/transport/TBufferTransports.cpp @@ -203,8 +203,7 @@ bool TFramedTransport::readFrame() { // Check for oversized frame if (sz > static_cast<int32_t>(maxFrameSize_)) - throw TTransportException(TTransportException::CORRUPTED_DATA, - "Received an oversized frame"); + throw TTransportException(TTransportException::CORRUPTED_DATA, "Received an oversized frame"); // Read the frame payload, and reset markers. if (sz > static_cast<int32_t>(rBufSize_)) { @@ -369,14 +368,14 @@ void TMemoryBuffer::ensureCanWrite(uint32_t len) { } // Allocate into a new pointer so we don't bork ours if it fails. - uint8_t* new_buffer = static_cast<uint8_t *>(std::realloc(buffer_, new_size)); + uint8_t* new_buffer = static_cast<uint8_t*>(std::realloc(buffer_, new_size)); if (new_buffer == NULL) { throw std::bad_alloc(); } - rBase_ = new_buffer + (rBase_ - buffer_) ; - rBound_ = new_buffer + (rBound_ - buffer_) ; - wBase_ = new_buffer + (wBase_ - buffer_) ; + rBase_ = new_buffer + (rBase_ - buffer_); + rBound_ = new_buffer + (rBound_ - buffer_); + wBase_ = new_buffer + (wBase_ - buffer_); wBound_ = new_buffer + new_size; buffer_ = new_buffer; bufferSize_ = new_size; http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/transport/TFileTransport.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TFileTransport.cpp b/lib/cpp/src/thrift/transport/TFileTransport.cpp index 8f6fe8e..85e88b9 100644 --- a/lib/cpp/src/thrift/transport/TFileTransport.cpp +++ b/lib/cpp/src/thrift/transport/TFileTransport.cpp @@ -239,7 +239,7 @@ void TFileTransport::enqueueEvent(const uint8_t* buf, uint32_t eventLen) { assert(!forceFlush_); // add to the buffer - eventInfo *pEvent = toEnqueue.release(); + eventInfo* pEvent = toEnqueue.release(); if (!enqueueBuffer_->addEvent(pEvent)) { delete pEvent; return; http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp b/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp index 421af6a..7e1484d 100644 --- a/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp +++ b/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp @@ -32,7 +32,8 @@ TSSLServerSocket::TSSLServerSocket(int port, boost::shared_ptr<TSSLSocketFactory factory_->server(true); } -TSSLServerSocket::TSSLServerSocket(const std::string& address, int port, +TSSLServerSocket::TSSLServerSocket(const std::string& address, + int port, boost::shared_ptr<TSSLSocketFactory> factory) : TServerSocket(address, port), factory_(factory) { factory_->server(true); http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/transport/TSSLServerSocket.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TSSLServerSocket.h b/lib/cpp/src/thrift/transport/TSSLServerSocket.h index 7d2dfcc..dfdbde8 100644 --- a/lib/cpp/src/thrift/transport/TSSLServerSocket.h +++ b/lib/cpp/src/thrift/transport/TSSLServerSocket.h @@ -49,7 +49,8 @@ public: * @param port Listening port * @param factory SSL socket factory implementation */ - TSSLServerSocket(const std::string& address, int port, + TSSLServerSocket(const std::string& address, + int port, boost::shared_ptr<TSSLSocketFactory> factory); /** http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/transport/TServerSocket.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp index f5c3ea5..daa1524 100644 --- a/lib/cpp/src/thrift/transport/TServerSocket.cpp +++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp @@ -70,10 +70,9 @@ inline SOCKOPT_CAST_T* cast_sockopt(T* v) { return reinterpret_cast<SOCKOPT_CAST_T*>(v); } -void destroyer_of_fine_sockets(THRIFT_SOCKET *ssock) -{ - ::THRIFT_CLOSESOCKET(*ssock); - delete ssock; +void destroyer_of_fine_sockets(THRIFT_SOCKET* ssock) { + ::THRIFT_CLOSESOCKET(*ssock); + delete ssock; } namespace apache { @@ -99,8 +98,8 @@ TServerSocket::TServerSocket(int port) listening_(false), interruptSockWriter_(THRIFT_INVALID_SOCKET), interruptSockReader_(THRIFT_INVALID_SOCKET), - childInterruptSockWriter_(THRIFT_INVALID_SOCKET) -{} + childInterruptSockWriter_(THRIFT_INVALID_SOCKET) { +} TServerSocket::TServerSocket(int port, int sendTimeout, int recvTimeout) : port_(port), @@ -118,8 +117,8 @@ TServerSocket::TServerSocket(int port, int sendTimeout, int recvTimeout) listening_(false), interruptSockWriter_(THRIFT_INVALID_SOCKET), interruptSockReader_(THRIFT_INVALID_SOCKET), - childInterruptSockWriter_(THRIFT_INVALID_SOCKET) -{} + childInterruptSockWriter_(THRIFT_INVALID_SOCKET) { +} TServerSocket::TServerSocket(const string& address, int port) : port_(port), @@ -138,8 +137,8 @@ TServerSocket::TServerSocket(const string& address, int port) listening_(false), interruptSockWriter_(THRIFT_INVALID_SOCKET), interruptSockReader_(THRIFT_INVALID_SOCKET), - childInterruptSockWriter_(THRIFT_INVALID_SOCKET) -{} + childInterruptSockWriter_(THRIFT_INVALID_SOCKET) { +} TServerSocket::TServerSocket(const string& path) : port_(0), @@ -158,8 +157,8 @@ TServerSocket::TServerSocket(const string& path) listening_(false), interruptSockWriter_(THRIFT_INVALID_SOCKET), interruptSockReader_(THRIFT_INVALID_SOCKET), - childInterruptSockWriter_(THRIFT_INVALID_SOCKET) -{} + childInterruptSockWriter_(THRIFT_INVALID_SOCKET) { +} TServerSocket::~TServerSocket() { close(); @@ -212,8 +211,7 @@ void TServerSocket::listen() { THRIFT_SOCKET sv[2]; // Create the socket pair used to interrupt if (-1 == THRIFT_SOCKETPAIR(AF_LOCAL, SOCK_STREAM, 0, sv)) { - GlobalOutput.perror("TServerSocket::listen() socketpair() interrupt", - THRIFT_GET_SOCKET_ERROR); + GlobalOutput.perror("TServerSocket::listen() socketpair() interrupt", THRIFT_GET_SOCKET_ERROR); interruptSockWriter_ = THRIFT_INVALID_SOCKET; interruptSockReader_ = THRIFT_INVALID_SOCKET; } else { @@ -224,14 +222,13 @@ void TServerSocket::listen() { // Create the socket pair used to interrupt all clients if (-1 == THRIFT_SOCKETPAIR(AF_LOCAL, SOCK_STREAM, 0, sv)) { GlobalOutput.perror("TServerSocket::listen() socketpair() childInterrupt", - THRIFT_GET_SOCKET_ERROR); + THRIFT_GET_SOCKET_ERROR); childInterruptSockWriter_ = THRIFT_INVALID_SOCKET; pChildInterruptSockReader_.reset(); } else { childInterruptSockWriter_ = sv[1]; - pChildInterruptSockReader_ = - boost::shared_ptr<THRIFT_SOCKET>(new THRIFT_SOCKET(sv[0]), - destroyer_of_fine_sockets); + pChildInterruptSockReader_ + = boost::shared_ptr<THRIFT_SOCKET>(new THRIFT_SOCKET(sv[0]), destroyer_of_fine_sockets); } // Validate port number @@ -388,7 +385,8 @@ void TServerSocket::listen() { GlobalOutput.perror("TServerSocket::listen() THRIFT_FCNTL() THRIFT_F_GETFL ", errno_copy); close(); throw TTransportException(TTransportException::NOT_OPEN, - "THRIFT_FCNTL() THRIFT_F_GETFL failed", errno_copy); + "THRIFT_FCNTL() THRIFT_F_GETFL failed", + errno_copy); } if (-1 == THRIFT_FCNTL(serverSocket_, THRIFT_F_SETFL, flags | THRIFT_O_NONBLOCK)) { @@ -396,7 +394,8 @@ void TServerSocket::listen() { GlobalOutput.perror("TServerSocket::listen() THRIFT_FCNTL() THRIFT_O_NONBLOCK ", errno_copy); close(); throw TTransportException(TTransportException::NOT_OPEN, - "THRIFT_FCNTL() THRIFT_F_SETFL THRIFT_O_NONBLOCK failed", errno_copy); + "THRIFT_FCNTL() THRIFT_F_SETFL THRIFT_O_NONBLOCK failed", + errno_copy); } // prepare the port information @@ -413,7 +412,8 @@ void TServerSocket::listen() { if (len > sizeof(((sockaddr_un*)NULL)->sun_path)) { int errno_copy = THRIFT_GET_SOCKET_ERROR; GlobalOutput.perror("TSocket::listen() Unix Domain socket path too long", errno_copy); - throw TTransportException(TTransportException::NOT_OPEN, "Unix Domain socket path too long", + throw TTransportException(TTransportException::NOT_OPEN, + "Unix Domain socket path too long", errno_copy); } @@ -649,7 +649,6 @@ void TServerSocket::close() { pChildInterruptSockReader_.reset(); listening_ = false; } - } } } // apache::thrift::transport http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/transport/TSocket.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TSocket.cpp b/lib/cpp/src/thrift/transport/TSocket.cpp index 4156d7e..2450d50 100644 --- a/lib/cpp/src/thrift/transport/TSocket.cpp +++ b/lib/cpp/src/thrift/transport/TSocket.cpp @@ -143,21 +143,20 @@ TSocket::TSocket(THRIFT_SOCKET socket) #endif } -TSocket::TSocket(THRIFT_SOCKET socket, - boost::shared_ptr<THRIFT_SOCKET> interruptListener) : - host_(""), - port_(0), - path_(""), - socket_(socket), - interruptListener_(interruptListener), - connTimeout_(0), - sendTimeout_(0), - recvTimeout_(0), - keepAlive_(false), - lingerOn_(1), - lingerVal_(0), - noDelay_(1), - maxRecvRetries_(5) { +TSocket::TSocket(THRIFT_SOCKET socket, boost::shared_ptr<THRIFT_SOCKET> interruptListener) + : host_(""), + port_(0), + path_(""), + socket_(socket), + interruptListener_(interruptListener), + connTimeout_(0), + sendTimeout_(0), + recvTimeout_(0), + keepAlive_(false), + lingerOn_(1), + lingerVal_(0), + noDelay_(1), + maxRecvRetries_(5) { cachedPeerAddr_.ipv4.sin_family = AF_UNSPEC; #ifdef SO_NOSIGPIPE { @@ -177,11 +176,10 @@ bool TSocket::isOpen() { bool TSocket::peek() { if (!isOpen()) { - return false; + return false; } - if (interruptListener_) - { - for (int retries = 0; ; ) { + if (interruptListener_) { + for (int retries = 0;;) { struct THRIFT_POLLFD fds[2]; std::memset(fds, 0, sizeof(fds)); fds[0].fd = socket_; @@ -515,8 +513,7 @@ try_again: int got = 0; - if (interruptListener_) - { + if (interruptListener_) { struct THRIFT_POLLFD fds[2]; std::memset(fds, 0, sizeof(fds)); fds[0].fd = socket_; @@ -536,12 +533,10 @@ try_again: } else if (ret > 0) { // Check the interruptListener if (fds[1].revents & THRIFT_POLLIN) { - throw TTransportException(TTransportException::INTERRUPTED, - "Interrupted"); + throw TTransportException(TTransportException::INTERRUPTED, "Interrupted"); } } else /* ret == 0 */ { - throw TTransportException(TTransportException::TIMED_OUT, - "THRIFT_EAGAIN (timed out)"); + throw TTransportException(TTransportException::TIMED_OUT, "THRIFT_EAGAIN (timed out)"); } // falling through means there is something to recv and it cannot block @@ -562,9 +557,8 @@ try_again: // check if this is the lack of resources or timeout case struct timeval end; THRIFT_GETTIMEOFDAY(&end, NULL); - uint32_t readElapsedMicros - = static_cast<uint32_t>(((end.tv_sec - begin.tv_sec) * 1000 * 1000) - + (end.tv_usec - begin.tv_usec)); + uint32_t readElapsedMicros = static_cast<uint32_t>(((end.tv_sec - begin.tv_sec) * 1000 * 1000) + + (end.tv_usec - begin.tv_usec)); if (!eagainThresholdMicros || (readElapsedMicros < eagainThresholdMicros)) { if (retries++ < maxRecvRetries_) { http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/src/thrift/transport/TSocket.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TSocket.h b/lib/cpp/src/thrift/transport/TSocket.h index 09a64e3..9f0074d 100644 --- a/lib/cpp/src/thrift/transport/TSocket.h +++ b/lib/cpp/src/thrift/transport/TSocket.h @@ -257,8 +257,7 @@ public: * Constructor to create socket from file descriptor that * can be interrupted safely. */ - TSocket(THRIFT_SOCKET socket, - boost::shared_ptr<THRIFT_SOCKET> interruptListener); + TSocket(THRIFT_SOCKET socket, boost::shared_ptr<THRIFT_SOCKET> interruptListener); /** * Set a cache of the peer address (used when trivially available: e.g. http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TFDTransportTest.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TFDTransportTest.cpp b/lib/cpp/test/TFDTransportTest.cpp index 47780ff..edbc55a 100644 --- a/lib/cpp/test/TFDTransportTest.cpp +++ b/lib/cpp/test/TFDTransportTest.cpp @@ -30,8 +30,8 @@ class DummyException : std::exception {}; int main() { { TFDTransport t(256, TFDTransport::NO_CLOSE_ON_DESTROY); } - // Disabled on MSVC because the RTL asserts on an invalid file descriptor - // in both debug and release mode; at least in MSVCR100 (Visual Studio 2010) +// Disabled on MSVC because the RTL asserts on an invalid file descriptor +// in both debug and release mode; at least in MSVCR100 (Visual Studio 2010) #if !defined(WIN32) try { { http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TMemoryBufferTest.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TMemoryBufferTest.cpp b/lib/cpp/test/TMemoryBufferTest.cpp index ec0f392..b562b34 100644 --- a/lib/cpp/test/TMemoryBufferTest.cpp +++ b/lib/cpp/test/TMemoryBufferTest.cpp @@ -36,8 +36,7 @@ using std::cout; using std::endl; using std::string; -BOOST_AUTO_TEST_CASE(test_read_write_grow) -{ +BOOST_AUTO_TEST_CASE(test_read_write_grow) { // Added to test the fix for THRIFT-1248 TMemoryBuffer uut; const int maxSize = 65536; @@ -45,25 +44,21 @@ BOOST_AUTO_TEST_CASE(test_read_write_grow) std::vector<uint8_t> buf; buf.resize(maxSize); - for (uint32_t i = 0; i < maxSize; ++i) - { + for (uint32_t i = 0; i < maxSize; ++i) { buf[i] = static_cast<uint8_t>(i); } - for (uint32_t i = 1; i < maxSize; i *= 2) - { + for (uint32_t i = 1; i < maxSize; i *= 2) { uut.write(&buf[0], i); } - for (uint32_t i = 1; i < maxSize; i *= 2) - { + for (uint32_t i = 1; i < maxSize; i *= 2) { uut.read(verify, i); BOOST_CHECK_EQUAL(0, ::memcmp(verify, &buf[0], i)); } } -BOOST_AUTO_TEST_CASE(test_roundtrip) -{ +BOOST_AUTO_TEST_CASE(test_roundtrip) { shared_ptr<TMemoryBuffer> strBuffer(new TMemoryBuffer()); shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(strBuffer)); @@ -85,8 +80,7 @@ BOOST_AUTO_TEST_CASE(test_roundtrip) assert(a == a2); } -BOOST_AUTO_TEST_CASE(test_copy) -{ +BOOST_AUTO_TEST_CASE(test_copy) { string* str1 = new string("abcd1234"); const char* data1 = str1->data(); TMemoryBuffer buf((uint8_t*)str1->data(), @@ -108,8 +102,7 @@ BOOST_AUTO_TEST_CASE(test_copy) assert(str4 == "67891234"); } -BOOST_AUTO_TEST_CASE(test_exceptions) -{ +BOOST_AUTO_TEST_CASE(test_exceptions) { char data[] = "foo\0bar"; TMemoryBuffer buf1((uint8_t*)data, 7, TMemoryBuffer::OBSERVE); http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TServerIntegrationTest.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TServerIntegrationTest.cpp b/lib/cpp/test/TServerIntegrationTest.cpp index fec1b9c..42ec5d6 100644 --- a/lib/cpp/test/TServerIntegrationTest.cpp +++ b/lib/cpp/test/TServerIntegrationTest.cpp @@ -68,8 +68,7 @@ using boost::posix_time::milliseconds; /** * preServe runs after listen() is successful, when we can connect */ -class TServerReadyEventHandler : public TServerEventHandler, public Monitor -{ +class TServerReadyEventHandler : public TServerEventHandler, public Monitor { public: TServerReadyEventHandler() : isListening_(false), accepted_(0) {} virtual ~TServerReadyEventHandler() {} @@ -90,6 +89,7 @@ public: } bool isListening() const { return isListening_; } uint64_t acceptedCount() const { return accepted_; } + private: bool isListening_; uint64_t accepted_; @@ -127,16 +127,11 @@ public: THRIFT_UNUSED_VARIABLE(length); } - void onewayWait() { - } + void onewayWait() {} - void exceptionWait(const std::string& message) { - THRIFT_UNUSED_VARIABLE(message); - } + void exceptionWait(const std::string& message) { THRIFT_UNUSED_VARIABLE(message); } - void unexpectedExceptionWait(const std::string& message) { - THRIFT_UNUSED_VARIABLE(message); - } + void unexpectedExceptionWait(const std::string& message) { THRIFT_UNUSED_VARIABLE(message); } protected: Mutex mutex_; @@ -144,34 +139,31 @@ protected: std::vector<std::string> strings_; }; -void autoSocketCloser(TSocket *pSock) { +void autoSocketCloser(TSocket* pSock) { pSock->close(); delete pSock; } -template<class TServerType> -class TServerIntegrationTestFixture : public TestPortFixture -{ +template <class TServerType> +class TServerIntegrationTestFixture : public TestPortFixture { public: - TServerIntegrationTestFixture(const boost::shared_ptr<TProcessorFactory>& _processorFactory) : - pServer(new TServerType( - _processorFactory, - boost::shared_ptr<TServerTransport>(new TServerSocket("localhost", m_serverPort)), - boost::shared_ptr<TTransportFactory>(new TTransportFactory), - boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))), - pEventHandler(boost::shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)) - { + TServerIntegrationTestFixture(const boost::shared_ptr<TProcessorFactory>& _processorFactory) + : pServer(new TServerType(_processorFactory, + boost::shared_ptr<TServerTransport>( + new TServerSocket("localhost", m_serverPort)), + boost::shared_ptr<TTransportFactory>(new TTransportFactory), + boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))), + pEventHandler(boost::shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)) { pServer->setServerEventHandler(pEventHandler); } - TServerIntegrationTestFixture(const boost::shared_ptr<TProcessor>& _processor) : - pServer(new TServerType( - _processor, - boost::shared_ptr<TServerTransport>(new TServerSocket("localhost", 0)), - boost::shared_ptr<TTransportFactory>(new TTransportFactory), - boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))), - pEventHandler(boost::shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)) - { + TServerIntegrationTestFixture(const boost::shared_ptr<TProcessor>& _processor) + : pServer( + new TServerType(_processor, + boost::shared_ptr<TServerTransport>(new TServerSocket("localhost", 0)), + boost::shared_ptr<TTransportFactory>(new TTransportFactory), + boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))), + pEventHandler(boost::shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)) { pServer->setServerEventHandler(pEventHandler); } @@ -181,7 +173,7 @@ public: // block until listen() completes so clients will be able to connect Synchronized sync(*(pEventHandler.get())); while (!pEventHandler->isListening()) { - pEventHandler->wait(); + pEventHandler->wait(); } BOOST_MESSAGE("server is listening"); @@ -190,7 +182,7 @@ public: void blockUntilAccepted(uint64_t numAccepted) { Synchronized sync(*(pEventHandler.get())); while (pEventHandler->acceptedCount() < numAccepted) { - pEventHandler->wait(); + pEventHandler->wait(); } BOOST_MESSAGE(boost::format("server has accepted %1%") % numAccepted); @@ -207,12 +199,10 @@ public: } } - ~TServerIntegrationTestFixture() { - stopServer(); - } + ~TServerIntegrationTestFixture() { stopServer(); } int getServerPort() { - TServerSocket *pSock = dynamic_cast<TServerSocket *>(pServer->getServerTransport().get()); + TServerSocket* pSock = dynamic_cast<TServerSocket*>(pServer->getServerTransport().get()); return pSock->getPort(); } @@ -227,24 +217,23 @@ public: std::vector<boost::shared_ptr<boost::thread> > holdThreads; for (int64_t i = 0; i < numToMake; ++i) { - boost::shared_ptr<TSocket> pClientSock(new TSocket("localhost", getServerPort()), autoSocketCloser); - holdSockets.push_back(pClientSock); - boost::shared_ptr<TProtocol> pClientProtocol(new TBinaryProtocol(pClientSock)); - ParentServiceClient client(pClientProtocol); - pClientSock->open(); - client.incrementGeneration(); - holdThreads.push_back( - boost::shared_ptr<boost::thread>( - new boost::thread( - boost::bind(&TServerIntegrationTestFixture::delayClose, this, - pClientSock, milliseconds(100 * numToMake))))); + boost::shared_ptr<TSocket> pClientSock(new TSocket("localhost", getServerPort()), + autoSocketCloser); + holdSockets.push_back(pClientSock); + boost::shared_ptr<TProtocol> pClientProtocol(new TBinaryProtocol(pClientSock)); + ParentServiceClient client(pClientProtocol); + pClientSock->open(); + client.incrementGeneration(); + holdThreads.push_back(boost::shared_ptr<boost::thread>( + new boost::thread(boost::bind(&TServerIntegrationTestFixture::delayClose, + this, + pClientSock, + milliseconds(100 * numToMake))))); } BOOST_CHECK_EQUAL(expectedHWM, pServer->getConcurrentClientCountHWM()); stopServer(); - BOOST_FOREACH(boost::shared_ptr<boost::thread> pThread, holdThreads) { - pThread->join(); - } + BOOST_FOREACH (boost::shared_ptr<boost::thread> pThread, holdThreads) { pThread->join(); } holdThreads.clear(); holdSockets.clear(); } @@ -254,183 +243,191 @@ public: boost::shared_ptr<boost::thread> pServerThread; }; -template<class TServerType> -class TServerIntegrationProcessorFactoryTestFixture : public TServerIntegrationTestFixture<TServerType> -{ +template <class TServerType> +class TServerIntegrationProcessorFactoryTestFixture + : public TServerIntegrationTestFixture<TServerType> { public: - TServerIntegrationProcessorFactoryTestFixture() : - TServerIntegrationTestFixture<TServerType>( - boost::make_shared<ParentServiceProcessorFactory>( - boost::make_shared<ParentServiceIfSingletonFactory>( - boost::make_shared<ParentHandler>()))) { } + TServerIntegrationProcessorFactoryTestFixture() + : TServerIntegrationTestFixture<TServerType>(boost::make_shared<ParentServiceProcessorFactory>( + boost::make_shared<ParentServiceIfSingletonFactory>( + boost::make_shared<ParentHandler>()))) {} }; -template<class TServerType> -class TServerIntegrationProcessorTestFixture : public TServerIntegrationTestFixture<TServerType> -{ +template <class TServerType> +class TServerIntegrationProcessorTestFixture : public TServerIntegrationTestFixture<TServerType> { public: - TServerIntegrationProcessorTestFixture() : - TServerIntegrationTestFixture<TServerType>( - boost::make_shared<ParentServiceProcessor>( - boost::make_shared<ParentHandler>())) { } + TServerIntegrationProcessorTestFixture() + : TServerIntegrationTestFixture<TServerType>( + boost::make_shared<ParentServiceProcessor>(boost::make_shared<ParentHandler>())) {} }; BOOST_AUTO_TEST_SUITE(constructors) -BOOST_FIXTURE_TEST_CASE(test_simple_factory, TServerIntegrationProcessorFactoryTestFixture<TSimpleServer>) -{ - baseline(3, 1); +BOOST_FIXTURE_TEST_CASE(test_simple_factory, + TServerIntegrationProcessorFactoryTestFixture<TSimpleServer>) { + baseline(3, 1); } -BOOST_FIXTURE_TEST_CASE(test_simple, TServerIntegrationProcessorTestFixture<TSimpleServer>) -{ - baseline(3, 1); +BOOST_FIXTURE_TEST_CASE(test_simple, TServerIntegrationProcessorTestFixture<TSimpleServer>) { + baseline(3, 1); } -BOOST_FIXTURE_TEST_CASE(test_threaded_factory, TServerIntegrationProcessorFactoryTestFixture<TThreadedServer>) -{ - baseline(10, 10); +BOOST_FIXTURE_TEST_CASE(test_threaded_factory, + TServerIntegrationProcessorFactoryTestFixture<TThreadedServer>) { + baseline(10, 10); } -BOOST_FIXTURE_TEST_CASE(test_threaded, TServerIntegrationProcessorTestFixture<TThreadedServer>) -{ - baseline(10, 10); +BOOST_FIXTURE_TEST_CASE(test_threaded, TServerIntegrationProcessorTestFixture<TThreadedServer>) { + baseline(10, 10); } -BOOST_FIXTURE_TEST_CASE(test_threaded_bound, TServerIntegrationProcessorTestFixture<TThreadedServer>) -{ - pServer->setConcurrentClientLimit(4); - baseline(10, 4); +BOOST_FIXTURE_TEST_CASE(test_threaded_bound, + TServerIntegrationProcessorTestFixture<TThreadedServer>) { + pServer->setConcurrentClientLimit(4); + baseline(10, 4); } -BOOST_FIXTURE_TEST_CASE(test_threadpool_factory, TServerIntegrationProcessorFactoryTestFixture<TThreadPoolServer>) -{ - pServer->getThreadManager()->threadFactory( - boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( - new apache::thrift::concurrency::PlatformThreadFactory)); - pServer->getThreadManager()->start(); - - // thread factory has 4 threads as a default - // thread factory however is a bad way to limit concurrent clients - // as accept() will be called to grab a 5th client socket, in this case - // and then the thread factory will block adding the thread to manage - // that client. - baseline(10, 5); +BOOST_FIXTURE_TEST_CASE(test_threadpool_factory, + TServerIntegrationProcessorFactoryTestFixture<TThreadPoolServer>) { + pServer->getThreadManager()->threadFactory( + boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( + new apache::thrift::concurrency::PlatformThreadFactory)); + pServer->getThreadManager()->start(); + + // thread factory has 4 threads as a default + // thread factory however is a bad way to limit concurrent clients + // as accept() will be called to grab a 5th client socket, in this case + // and then the thread factory will block adding the thread to manage + // that client. + baseline(10, 5); } -BOOST_FIXTURE_TEST_CASE(test_threadpool, TServerIntegrationProcessorTestFixture<TThreadPoolServer>) -{ - pServer->getThreadManager()->threadFactory( - boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( - new apache::thrift::concurrency::PlatformThreadFactory)); - pServer->getThreadManager()->start(); - - // thread factory has 4 threads as a default - // thread factory however is a bad way to limit concurrent clients - // as accept() will be called to grab a 5th client socket, in this case - // and then the thread factory will block adding the thread to manage - // that client. - baseline(10, 5); +BOOST_FIXTURE_TEST_CASE(test_threadpool, + TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { + pServer->getThreadManager()->threadFactory( + boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( + new apache::thrift::concurrency::PlatformThreadFactory)); + pServer->getThreadManager()->start(); + + // thread factory has 4 threads as a default + // thread factory however is a bad way to limit concurrent clients + // as accept() will be called to grab a 5th client socket, in this case + // and then the thread factory will block adding the thread to manage + // that client. + baseline(10, 5); } -BOOST_FIXTURE_TEST_CASE(test_threadpool_bound, TServerIntegrationProcessorTestFixture<TThreadPoolServer>) -{ - pServer->getThreadManager()->threadFactory( - boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( - new apache::thrift::concurrency::PlatformThreadFactory)); - pServer->getThreadManager()->start(); - pServer->setConcurrentClientLimit(4); +BOOST_FIXTURE_TEST_CASE(test_threadpool_bound, + TServerIntegrationProcessorTestFixture<TThreadPoolServer>) { + pServer->getThreadManager()->threadFactory( + boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>( + new apache::thrift::concurrency::PlatformThreadFactory)); + pServer->getThreadManager()->start(); + pServer->setConcurrentClientLimit(4); - baseline(10, 4); + baseline(10, 4); } BOOST_AUTO_TEST_SUITE_END() +BOOST_FIXTURE_TEST_SUITE(TServerIntegrationTest, + TServerIntegrationProcessorTestFixture<TThreadedServer>) -BOOST_FIXTURE_TEST_SUITE ( TServerIntegrationTest, TServerIntegrationProcessorTestFixture<TThreadedServer> ) - -BOOST_AUTO_TEST_CASE(test_stop_with_interruptable_clients_connected) -{ - // This tests THRIFT-2441 new behavior: stopping the server disconnects clients +BOOST_AUTO_TEST_CASE(test_stop_with_interruptable_clients_connected) { + // This tests THRIFT-2441 new behavior: stopping the server disconnects clients - startServer(); + startServer(); - boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), autoSocketCloser); - pClientSock1->open(); + boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), + autoSocketCloser); + pClientSock1->open(); - boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), autoSocketCloser); - pClientSock2->open(); + boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), + autoSocketCloser); + pClientSock2->open(); - // Ensure they have been accepted - blockUntilAccepted(2); + // Ensure they have been accepted + blockUntilAccepted(2); - // The test fixture destructor will force the sockets to disconnect - // Prior to THRIFT-2441, pServer->stop() would hang until clients disconnected - stopServer(); + // The test fixture destructor will force the sockets to disconnect + // Prior to THRIFT-2441, pServer->stop() would hang until clients disconnected + stopServer(); - // extra proof the server end disconnected the clients - uint8_t buf[1]; - BOOST_CHECK_EQUAL(0, pClientSock1->read(&buf[0], 1)); // 0 = disconnected - BOOST_CHECK_EQUAL(0, pClientSock2->read(&buf[0], 1)); // 0 = disconnected + // extra proof the server end disconnected the clients + uint8_t buf[1]; + BOOST_CHECK_EQUAL(0, pClientSock1->read(&buf[0], 1)); // 0 = disconnected + BOOST_CHECK_EQUAL(0, pClientSock2->read(&buf[0], 1)); // 0 = disconnected } -BOOST_AUTO_TEST_CASE(test_stop_with_uninterruptable_clients_connected) -{ - // This tests pre-THRIFT-2441 behavior: stopping the server blocks until clients - // disconnect. +BOOST_AUTO_TEST_CASE(test_stop_with_uninterruptable_clients_connected) { + // This tests pre-THRIFT-2441 behavior: stopping the server blocks until clients + // disconnect. - boost::dynamic_pointer_cast<TServerSocket>(pServer->getServerTransport())-> - setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior + boost::dynamic_pointer_cast<TServerSocket>(pServer->getServerTransport()) + ->setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior - startServer(); + startServer(); - boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), autoSocketCloser); - pClientSock1->open(); + boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), + autoSocketCloser); + pClientSock1->open(); - boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), autoSocketCloser); - pClientSock2->open(); + boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), + autoSocketCloser); + pClientSock2->open(); - // Ensure they have been accepted - blockUntilAccepted(2); + // Ensure they have been accepted + blockUntilAccepted(2); - boost::thread t1(boost::bind(&TServerIntegrationTestFixture::delayClose, this, pClientSock1, milliseconds(250))); - boost::thread t2(boost::bind(&TServerIntegrationTestFixture::delayClose, this, pClientSock2, milliseconds(250))); + boost::thread t1(boost::bind(&TServerIntegrationTestFixture::delayClose, + this, + pClientSock1, + milliseconds(250))); + boost::thread t2(boost::bind(&TServerIntegrationTestFixture::delayClose, + this, + pClientSock2, + milliseconds(250))); - // Once the clients disconnect the server will stop - stopServer(); - t1.join(); - t2.join(); + // Once the clients disconnect the server will stop + stopServer(); + t1.join(); + t2.join(); } -BOOST_AUTO_TEST_CASE(test_concurrent_client_limit) -{ - startServer(); - - BOOST_CHECK_EQUAL(INT64_MAX, pServer->getConcurrentClientLimit()); - pServer->setConcurrentClientLimit(2); - BOOST_CHECK_EQUAL(0, pServer->getConcurrentClientCount()); - BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientLimit()); - - boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), autoSocketCloser); - pClientSock1->open(); - blockUntilAccepted(1); - BOOST_CHECK_EQUAL(1, pServer->getConcurrentClientCount()); - - boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), autoSocketCloser); - pClientSock2->open(); - blockUntilAccepted(2); - BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); - - // a third client cannot connect until one of the other two closes - boost::thread t2(boost::bind(&TServerIntegrationTestFixture::delayClose, this, pClientSock2, milliseconds(250))); - boost::shared_ptr<TSocket> pClientSock3(new TSocket("localhost", getServerPort()), autoSocketCloser); - pClientSock2->open(); - blockUntilAccepted(2); - BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); - BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCountHWM()); - - stopServer(); - t2.join(); +BOOST_AUTO_TEST_CASE(test_concurrent_client_limit) { + startServer(); + + BOOST_CHECK_EQUAL(INT64_MAX, pServer->getConcurrentClientLimit()); + pServer->setConcurrentClientLimit(2); + BOOST_CHECK_EQUAL(0, pServer->getConcurrentClientCount()); + BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientLimit()); + + boost::shared_ptr<TSocket> pClientSock1(new TSocket("localhost", getServerPort()), + autoSocketCloser); + pClientSock1->open(); + blockUntilAccepted(1); + BOOST_CHECK_EQUAL(1, pServer->getConcurrentClientCount()); + + boost::shared_ptr<TSocket> pClientSock2(new TSocket("localhost", getServerPort()), + autoSocketCloser); + pClientSock2->open(); + blockUntilAccepted(2); + BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); + + // a third client cannot connect until one of the other two closes + boost::thread t2(boost::bind(&TServerIntegrationTestFixture::delayClose, + this, + pClientSock2, + milliseconds(250))); + boost::shared_ptr<TSocket> pClientSock3(new TSocket("localhost", getServerPort()), + autoSocketCloser); + pClientSock2->open(); + blockUntilAccepted(2); + BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCount()); + BOOST_CHECK_EQUAL(2, pServer->getConcurrentClientCountHWM()); + + stopServer(); + t2.join(); } BOOST_AUTO_TEST_SUITE_END() http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TServerSocketTest.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TServerSocketTest.cpp b/lib/cpp/test/TServerSocketTest.cpp index 65f99f9..ae87ba8 100644 --- a/lib/cpp/test/TServerSocketTest.cpp +++ b/lib/cpp/test/TServerSocketTest.cpp @@ -29,44 +29,39 @@ using apache::thrift::transport::TSocket; using apache::thrift::transport::TTransport; using apache::thrift::transport::TTransportException; -BOOST_FIXTURE_TEST_SUITE ( TServerSocketTest, TestPortFixture ) +BOOST_FIXTURE_TEST_SUITE(TServerSocketTest, TestPortFixture) -BOOST_AUTO_TEST_CASE( test_bind_to_address ) -{ - TServerSocket sock1("localhost", m_serverPort); - sock1.listen(); - TSocket clientSock("localhost", m_serverPort); - clientSock.open(); - boost::shared_ptr<TTransport> accepted = sock1.accept(); - accepted->close(); - sock1.close(); +BOOST_AUTO_TEST_CASE(test_bind_to_address) { + TServerSocket sock1("localhost", m_serverPort); + sock1.listen(); + TSocket clientSock("localhost", m_serverPort); + clientSock.open(); + boost::shared_ptr<TTransport> accepted = sock1.accept(); + accepted->close(); + sock1.close(); - std::cout << "An error message from getaddrinfo on the console is expected:" << std::endl; - TServerSocket sock2("257.258.259.260", m_serverPort); - BOOST_CHECK_THROW(sock2.listen(), TTransportException); - sock2.close(); + std::cout << "An error message from getaddrinfo on the console is expected:" << std::endl; + TServerSocket sock2("257.258.259.260", m_serverPort); + BOOST_CHECK_THROW(sock2.listen(), TTransportException); + sock2.close(); } -BOOST_AUTO_TEST_CASE( test_listen_valid_port ) -{ - TServerSocket sock1(-1); - TTRANSPORT_CHECK_THROW(sock1.listen(), TTransportException::BAD_ARGS); +BOOST_AUTO_TEST_CASE(test_listen_valid_port) { + TServerSocket sock1(-1); + TTRANSPORT_CHECK_THROW(sock1.listen(), TTransportException::BAD_ARGS); - TServerSocket sock2(65536); - TTRANSPORT_CHECK_THROW(sock2.listen(), TTransportException::BAD_ARGS); + TServerSocket sock2(65536); + TTRANSPORT_CHECK_THROW(sock2.listen(), TTransportException::BAD_ARGS); } -BOOST_AUTO_TEST_CASE( test_close_before_listen ) -{ - TServerSocket sock1("localhost", m_serverPort); - sock1.close(); +BOOST_AUTO_TEST_CASE(test_close_before_listen) { + TServerSocket sock1("localhost", m_serverPort); + sock1.close(); } -BOOST_AUTO_TEST_CASE( test_get_port ) -{ - TServerSocket sock1("localHost", 888); - BOOST_CHECK_EQUAL(888, sock1.getPort()); +BOOST_AUTO_TEST_CASE(test_get_port) { + TServerSocket sock1("localHost", 888); + BOOST_CHECK_EQUAL(888, sock1.getPort()); } BOOST_AUTO_TEST_SUITE_END() - http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TServerTransportTest.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TServerTransportTest.cpp b/lib/cpp/test/TServerTransportTest.cpp index 09b2c59..2047337 100644 --- a/lib/cpp/test/TServerTransportTest.cpp +++ b/lib/cpp/test/TServerTransportTest.cpp @@ -26,37 +26,32 @@ using apache::thrift::transport::TServerTransport; using apache::thrift::transport::TTransport; using apache::thrift::transport::TTransportException; -BOOST_AUTO_TEST_SUITE ( TServerTransportTest ) +BOOST_AUTO_TEST_SUITE(TServerTransportTest) -class TestTTransport : public TTransport -{ -}; +class TestTTransport : public TTransport {}; -class TestTServerTransport : public TServerTransport -{ +class TestTServerTransport : public TServerTransport { public: - TestTServerTransport() : valid_(true) {} - void close() {} - bool valid_; + TestTServerTransport() : valid_(true) {} + void close() {} + bool valid_; + protected: - boost::shared_ptr<TTransport> acceptImpl() - { - return valid_ ? boost::shared_ptr<TestTTransport>(new TestTTransport) : boost::shared_ptr<TestTTransport>(); - } + boost::shared_ptr<TTransport> acceptImpl() { + return valid_ ? boost::shared_ptr<TestTTransport>(new TestTTransport) + : boost::shared_ptr<TestTTransport>(); + } }; -BOOST_AUTO_TEST_CASE( test_positive_accept ) -{ - TestTServerTransport uut; - BOOST_CHECK(uut.accept()); +BOOST_AUTO_TEST_CASE(test_positive_accept) { + TestTServerTransport uut; + BOOST_CHECK(uut.accept()); } -BOOST_AUTO_TEST_CASE( test_negative_accept ) -{ - TestTServerTransport uut; - uut.valid_ = false; - BOOST_CHECK_THROW(uut.accept(), TTransportException); +BOOST_AUTO_TEST_CASE(test_negative_accept) { + TestTServerTransport uut; + uut.valid_ = false; + BOOST_CHECK_THROW(uut.accept(), TTransportException); } BOOST_AUTO_TEST_SUITE_END() - http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TSocketInterruptTest.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TSocketInterruptTest.cpp b/lib/cpp/test/TSocketInterruptTest.cpp index 4f6b2bc..02da3ee 100644 --- a/lib/cpp/test/TSocketInterruptTest.cpp +++ b/lib/cpp/test/TSocketInterruptTest.cpp @@ -33,122 +33,110 @@ using apache::thrift::transport::TSocket; using apache::thrift::transport::TTransport; using apache::thrift::transport::TTransportException; -BOOST_FIXTURE_TEST_SUITE ( TSocketInterruptTest, TestPortFixture ) +BOOST_FIXTURE_TEST_SUITE(TSocketInterruptTest, TestPortFixture) -void readerWorker(boost::shared_ptr<TTransport> tt, uint32_t expectedResult) -{ - uint8_t buf[4]; - BOOST_CHECK_EQUAL(expectedResult, tt->read(buf, 4)); +void readerWorker(boost::shared_ptr<TTransport> tt, uint32_t expectedResult) { + uint8_t buf[4]; + BOOST_CHECK_EQUAL(expectedResult, tt->read(buf, 4)); } -void readerWorkerMustThrow(boost::shared_ptr<TTransport> tt) -{ - try - { - uint8_t buf[4]; - tt->read(buf, 4); - BOOST_ERROR("should not have gotten here"); - } - catch (const TTransportException& tx) - { - BOOST_CHECK_EQUAL(TTransportException::INTERRUPTED, tx.getType()); - } +void readerWorkerMustThrow(boost::shared_ptr<TTransport> tt) { + try { + uint8_t buf[4]; + tt->read(buf, 4); + BOOST_ERROR("should not have gotten here"); + } catch (const TTransportException& tx) { + BOOST_CHECK_EQUAL(TTransportException::INTERRUPTED, tx.getType()); + } } -BOOST_AUTO_TEST_CASE( test_interruptable_child_read ) -{ - TServerSocket sock1("localhost", m_serverPort); - sock1.listen(); - TSocket clientSock("localhost", m_serverPort); - clientSock.open(); - boost::shared_ptr<TTransport> accepted = sock1.accept(); - boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted)); - boost::this_thread::sleep(boost::posix_time::milliseconds(50)); - // readThread is practically guaranteed to be blocking now - sock1.interruptChildren(); - BOOST_CHECK_MESSAGE(readThread.try_join_for(boost::chrono::milliseconds(200)), - "server socket interruptChildren did not interrupt child read"); - clientSock.close(); - accepted->close(); - sock1.close(); +BOOST_AUTO_TEST_CASE(test_interruptable_child_read) { + TServerSocket sock1("localhost", m_serverPort); + sock1.listen(); + TSocket clientSock("localhost", m_serverPort); + clientSock.open(); + boost::shared_ptr<TTransport> accepted = sock1.accept(); + boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted)); + boost::this_thread::sleep(boost::posix_time::milliseconds(50)); + // readThread is practically guaranteed to be blocking now + sock1.interruptChildren(); + BOOST_CHECK_MESSAGE(readThread.try_join_for(boost::chrono::milliseconds(200)), + "server socket interruptChildren did not interrupt child read"); + clientSock.close(); + accepted->close(); + sock1.close(); } -BOOST_AUTO_TEST_CASE( test_non_interruptable_child_read ) -{ - TServerSocket sock1("localhost", m_serverPort); - sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior - sock1.listen(); - TSocket clientSock("localhost", m_serverPort); - clientSock.open(); - boost::shared_ptr<TTransport> accepted = sock1.accept(); - boost::thread readThread(boost::bind(readerWorker, accepted, 0)); - boost::this_thread::sleep(boost::posix_time::milliseconds(50)); - // readThread is practically guaranteed to be blocking here - sock1.interruptChildren(); - BOOST_CHECK_MESSAGE(!readThread.try_join_for(boost::chrono::milliseconds(200)), - "server socket interruptChildren interrupted child read"); - - // only way to proceed is to have the client disconnect - clientSock.close(); - readThread.join(); - accepted->close(); - sock1.close(); +BOOST_AUTO_TEST_CASE(test_non_interruptable_child_read) { + TServerSocket sock1("localhost", m_serverPort); + sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior + sock1.listen(); + TSocket clientSock("localhost", m_serverPort); + clientSock.open(); + boost::shared_ptr<TTransport> accepted = sock1.accept(); + boost::thread readThread(boost::bind(readerWorker, accepted, 0)); + boost::this_thread::sleep(boost::posix_time::milliseconds(50)); + // readThread is practically guaranteed to be blocking here + sock1.interruptChildren(); + BOOST_CHECK_MESSAGE(!readThread.try_join_for(boost::chrono::milliseconds(200)), + "server socket interruptChildren interrupted child read"); + + // only way to proceed is to have the client disconnect + clientSock.close(); + readThread.join(); + accepted->close(); + sock1.close(); } -BOOST_AUTO_TEST_CASE( test_cannot_change_after_listen ) -{ - TServerSocket sock1("localhost", m_serverPort); - sock1.listen(); - BOOST_CHECK_THROW(sock1.setInterruptableChildren(false), std::logic_error); - sock1.close(); +BOOST_AUTO_TEST_CASE(test_cannot_change_after_listen) { + TServerSocket sock1("localhost", m_serverPort); + sock1.listen(); + BOOST_CHECK_THROW(sock1.setInterruptableChildren(false), std::logic_error); + sock1.close(); } -void peekerWorker(boost::shared_ptr<TTransport> tt, bool expectedResult) -{ - BOOST_CHECK_EQUAL(expectedResult, tt->peek()); +void peekerWorker(boost::shared_ptr<TTransport> tt, bool expectedResult) { + BOOST_CHECK_EQUAL(expectedResult, tt->peek()); } -BOOST_AUTO_TEST_CASE( test_interruptable_child_peek ) -{ - TServerSocket sock1("localhost", m_serverPort); - sock1.listen(); - TSocket clientSock("localhost", m_serverPort); - clientSock.open(); - boost::shared_ptr<TTransport> accepted = sock1.accept(); - // peek() will return false if child is interrupted - boost::thread peekThread(boost::bind(peekerWorker, accepted, false)); - boost::this_thread::sleep(boost::posix_time::milliseconds(50)); - // peekThread is practically guaranteed to be blocking now - sock1.interruptChildren(); - BOOST_CHECK_MESSAGE(peekThread.try_join_for(boost::chrono::milliseconds(200)), - "server socket interruptChildren did not interrupt child peek"); - clientSock.close(); - accepted->close(); - sock1.close(); +BOOST_AUTO_TEST_CASE(test_interruptable_child_peek) { + TServerSocket sock1("localhost", m_serverPort); + sock1.listen(); + TSocket clientSock("localhost", m_serverPort); + clientSock.open(); + boost::shared_ptr<TTransport> accepted = sock1.accept(); + // peek() will return false if child is interrupted + boost::thread peekThread(boost::bind(peekerWorker, accepted, false)); + boost::this_thread::sleep(boost::posix_time::milliseconds(50)); + // peekThread is practically guaranteed to be blocking now + sock1.interruptChildren(); + BOOST_CHECK_MESSAGE(peekThread.try_join_for(boost::chrono::milliseconds(200)), + "server socket interruptChildren did not interrupt child peek"); + clientSock.close(); + accepted->close(); + sock1.close(); } -BOOST_AUTO_TEST_CASE( test_non_interruptable_child_peek ) -{ - TServerSocket sock1("localhost", m_serverPort); - sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior - sock1.listen(); - TSocket clientSock("localhost", m_serverPort); - clientSock.open(); - boost::shared_ptr<TTransport> accepted = sock1.accept(); - // peek() will return false when remote side is closed - boost::thread peekThread(boost::bind(peekerWorker, accepted, false)); - boost::this_thread::sleep(boost::posix_time::milliseconds(50)); - // peekThread is practically guaranteed to be blocking now - sock1.interruptChildren(); - BOOST_CHECK_MESSAGE(!peekThread.try_join_for(boost::chrono::milliseconds(200)), - "server socket interruptChildren interrupted child peek"); - - // only way to proceed is to have the client disconnect - clientSock.close(); - peekThread.join(); - accepted->close(); - sock1.close(); +BOOST_AUTO_TEST_CASE(test_non_interruptable_child_peek) { + TServerSocket sock1("localhost", m_serverPort); + sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior + sock1.listen(); + TSocket clientSock("localhost", m_serverPort); + clientSock.open(); + boost::shared_ptr<TTransport> accepted = sock1.accept(); + // peek() will return false when remote side is closed + boost::thread peekThread(boost::bind(peekerWorker, accepted, false)); + boost::this_thread::sleep(boost::posix_time::milliseconds(50)); + // peekThread is practically guaranteed to be blocking now + sock1.interruptChildren(); + BOOST_CHECK_MESSAGE(!peekThread.try_join_for(boost::chrono::milliseconds(200)), + "server socket interruptChildren interrupted child peek"); + + // only way to proceed is to have the client disconnect + clientSock.close(); + peekThread.join(); + accepted->close(); + sock1.close(); } BOOST_AUTO_TEST_SUITE_END() - http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TTransportCheckThrow.h ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TTransportCheckThrow.h b/lib/cpp/test/TTransportCheckThrow.h index 3b212e1..92277b4 100644 --- a/lib/cpp/test/TTransportCheckThrow.h +++ b/lib/cpp/test/TTransportCheckThrow.h @@ -19,15 +19,26 @@ #pragma once -#define TTRANSPORT_CHECK_THROW(_CALL, _TYPE) \ - { bool caught = false; \ - try { (_CALL); } \ - catch (TTransportException& ex) { BOOST_CHECK_EQUAL(ex.getType(), _TYPE); caught = true; } \ - BOOST_CHECK_MESSAGE(caught, "expected TTransportException but nothing was thrown"); } - -#define TTRANSPORT_REQUIRE_THROW(_CALL, _TYPE) \ - { bool caught = false; \ - try { (_CALL); } \ - catch (TTransportException& ex) { BOOST_REQUIRE_EQUAL(ex.getType(), _TYPE); caught = true; } \ - BOOST_REQUIRE_MESSAGE(caught, "expected TTransportException but nothing was thrown"); } +#define TTRANSPORT_CHECK_THROW(_CALL, _TYPE) \ + { \ + bool caught = false; \ + try { \ + (_CALL); \ + } catch (TTransportException & ex) { \ + BOOST_CHECK_EQUAL(ex.getType(), _TYPE); \ + caught = true; \ + } \ + BOOST_CHECK_MESSAGE(caught, "expected TTransportException but nothing was thrown"); \ + } +#define TTRANSPORT_REQUIRE_THROW(_CALL, _TYPE) \ + { \ + bool caught = false; \ + try { \ + (_CALL); \ + } catch (TTransportException & ex) { \ + BOOST_REQUIRE_EQUAL(ex.getType(), _TYPE); \ + caught = true; \ + } \ + BOOST_REQUIRE_MESSAGE(caught, "expected TTransportException but nothing was thrown"); \ + } http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TestPortFixture.h ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TestPortFixture.h b/lib/cpp/test/TestPortFixture.h index 5b27e5e..5af47d6 100644 --- a/lib/cpp/test/TestPortFixture.h +++ b/lib/cpp/test/TestPortFixture.h @@ -21,16 +21,13 @@ #include <cstdlib> -class TestPortFixture -{ - public: - TestPortFixture() - { - const char *spEnv = std::getenv("THRIFT_TEST_PORT"); - m_serverPort = (spEnv) ? atoi(spEnv) : 9090; - } +class TestPortFixture { +public: + TestPortFixture() { + const char* spEnv = std::getenv("THRIFT_TEST_PORT"); + m_serverPort = (spEnv) ? atoi(spEnv) : 9090; + } - protected: - int m_serverPort; +protected: + int m_serverPort; }; - http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/lib/cpp/test/TypedefTest.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/test/TypedefTest.cpp b/lib/cpp/test/TypedefTest.cpp index eb2f743..24e9265 100644 --- a/lib/cpp/test/TypedefTest.cpp +++ b/lib/cpp/test/TypedefTest.cpp @@ -24,4 +24,5 @@ BOOST_STATIC_ASSERT((boost::is_same<int32_t, thrift::test::MyInt32>::value)); BOOST_STATIC_ASSERT((boost::is_same<std::string, thrift::test::MyString>::value)); -BOOST_STATIC_ASSERT((boost::is_same<thrift::test::TypedefTestStruct, thrift::test::MyStruct>::value)); +BOOST_STATIC_ASSERT( + (boost::is_same<thrift::test::TypedefTestStruct, thrift::test::MyStruct>::value)); http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/test/cpp/src/TestClient.cpp ---------------------------------------------------------------------- diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp index 2a89a28..fa5b635 100644 --- a/test/cpp/src/TestClient.cpp +++ b/test/cpp/src/TestClient.cpp @@ -51,7 +51,6 @@ using namespace apache::thrift::async; // Length of argv[0] - Length of script dir #define EXECUTABLE_FILE_NAME_LENGTH 19 - // Current time, microseconds since the epoch uint64_t now() { int64_t ret; http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/test/cpp/src/TestServer.cpp ---------------------------------------------------------------------- diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp index 2705064..526cb0b 100644 --- a/test/cpp/src/TestServer.cpp +++ b/test/cpp/src/TestServer.cpp @@ -418,7 +418,8 @@ public: cob(res); } - virtual void testBinary(tcxx::function<void(std::string const& _return)> cob, const std::string& thing) { + virtual void testBinary(tcxx::function<void(std::string const& _return)> cob, + const std::string& thing) { std::string res; _delegate->testBinary(res, thing); cob(res); http://git-wip-us.apache.org/repos/asf/thrift/blob/1f6e380c/test/crossrunner/collect.py ---------------------------------------------------------------------- diff --git a/test/crossrunner/collect.py b/test/crossrunner/collect.py index 6c771b3..145afef 100644 --- a/test/crossrunner/collect.py +++ b/test/crossrunner/collect.py @@ -36,7 +36,7 @@ from crossrunner.util import merge_dict # (e.g. binary:accel) where test is run for any matching "spec" while actual # argument passed to test executable is "impl". # Otherwise "spec" is equivalent to "spec:spec" pair. -# (e.g. "binary" is equivalent to "binary:bianry" in tests.json) +# (e.g. "binary" is equivalent to "binary:binary" in tests.json) # VALID_JSON_KEYS = [ 'name', # name of the library, typically a language name
