Revert "THRIFT-2729: C++ - .clang-format created and applied"
This reverts commit 74260aa9099c3bb209bc8e524b0e8ba603f62c41.
diff --git a/test/cpp/src/StressTest.cpp b/test/cpp/src/StressTest.cpp
index fa468a4..dfe8350 100644
--- a/test/cpp/src/StressTest.cpp
+++ b/test/cpp/src/StressTest.cpp
@@ -40,7 +40,7 @@
#include <sstream>
#include <map>
#if _WIN32
-#include <thrift/windows/TWinsockSingleton.h>
+ #include <thrift/windows/TWinsockSingleton.h>
#endif
using namespace std;
@@ -54,18 +54,23 @@
using namespace test::stress;
struct eqstr {
- bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; }
+ bool operator()(const char* s1, const char* s2) const {
+ return strcmp(s1, s2) == 0;
+ }
};
struct ltstr {
- bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; }
+ bool operator()(const char* s1, const char* s2) const {
+ return strcmp(s1, s2) < 0;
+ }
};
+
// typedef hash_map<const char*, int, hash<const char*>, eqstr> count_map;
typedef map<const char*, int, ltstr> count_map;
class Server : public ServiceIf {
-public:
+ public:
Server() {}
void count(const char* method) {
@@ -84,46 +89,43 @@
return counts_;
}
- int8_t echoByte(const int8_t arg) { return arg; }
- int32_t echoI32(const int32_t arg) { return arg; }
- int64_t echoI64(const int64_t arg) { return arg; }
- void echoString(string& out, const string& arg) {
+ int8_t echoByte(const int8_t arg) {return arg;}
+ int32_t echoI32(const int32_t arg) {return arg;}
+ int64_t echoI64(const int64_t arg) {return arg;}
+ void echoString(string& out, const string &arg) {
if (arg != "hello") {
T_ERROR_ABORT("WRONG STRING (%s)!!!!", arg.c_str());
}
out = arg;
}
- void echoList(vector<int8_t>& out, const vector<int8_t>& arg) { out = arg; }
- void echoSet(set<int8_t>& out, const set<int8_t>& arg) { out = arg; }
- void echoMap(map<int8_t, int8_t>& out, const map<int8_t, int8_t>& arg) { out = arg; }
+ void echoList(vector<int8_t> &out, const vector<int8_t> &arg) { out = arg; }
+ void echoSet(set<int8_t> &out, const set<int8_t> &arg) { out = arg; }
+ void echoMap(map<int8_t, int8_t> &out, const map<int8_t, int8_t> &arg) { out = arg; }
private:
count_map counts_;
Mutex lock_;
+
};
-class ClientThread : public Runnable {
+class ClientThread: public Runnable {
public:
- ClientThread(boost::shared_ptr<TTransport> transport,
- boost::shared_ptr<ServiceClient> client,
- Monitor& monitor,
- size_t& workerCount,
- size_t loopCount,
- TType loopType)
- : _transport(transport),
- _client(client),
- _monitor(monitor),
- _workerCount(workerCount),
- _loopCount(loopCount),
- _loopType(loopType) {}
+
+ ClientThread(boost::shared_ptr<TTransport>transport, boost::shared_ptr<ServiceClient> client, Monitor& monitor, size_t& workerCount, size_t loopCount, TType loopType) :
+ _transport(transport),
+ _client(client),
+ _monitor(monitor),
+ _workerCount(workerCount),
+ _loopCount(loopCount),
+ _loopType(loopType)
+ {}
void run() {
// Wait for all worker threads to start
- {
- Synchronized s(_monitor);
- while (_workerCount == 0) {
+ {Synchronized s(_monitor);
+ while(_workerCount == 0) {
_monitor.wait();
}
}
@@ -132,25 +134,13 @@
_transport->open();
- switch (_loopType) {
- case T_VOID:
- loopEchoVoid();
- break;
- case T_BYTE:
- loopEchoByte();
- break;
- case T_I32:
- loopEchoI32();
- break;
- case T_I64:
- loopEchoI64();
- break;
- case T_STRING:
- loopEchoString();
- break;
- default:
- cerr << "Unexpected loop type" << _loopType << endl;
- break;
+ switch(_loopType) {
+ case T_VOID: loopEchoVoid(); break;
+ case T_BYTE: loopEchoByte(); break;
+ case T_I32: loopEchoI32(); break;
+ case T_I64: loopEchoI64(); break;
+ case T_STRING: loopEchoString(); break;
+ default: cerr << "Unexpected loop type" << _loopType << endl; break;
}
_endTime = Util::currentTime();
@@ -159,8 +149,7 @@
_done = true;
- {
- Synchronized s(_monitor);
+ {Synchronized s(_monitor);
_workerCount--;
@@ -181,7 +170,7 @@
for (size_t ix = 0; ix < _loopCount; ix++) {
int8_t arg = 1;
int8_t result;
- result = _client->echoByte(arg);
+ result =_client->echoByte(arg);
(void)result;
assert(result == arg);
}
@@ -191,7 +180,7 @@
for (size_t ix = 0; ix < _loopCount; ix++) {
int32_t arg = 1;
int32_t result;
- result = _client->echoI32(arg);
+ result =_client->echoI32(arg);
(void)result;
assert(result == arg);
}
@@ -201,7 +190,7 @@
for (size_t ix = 0; ix < _loopCount; ix++) {
int64_t arg = 1;
int64_t result;
- result = _client->echoI64(arg);
+ result =_client->echoI64(arg);
(void)result;
assert(result == arg);
}
@@ -228,26 +217,28 @@
Monitor _sleep;
};
-class TStartObserver : public apache::thrift::server::TServerEventHandler {
+class TStartObserver : public apache::thrift::server::TServerEventHandler
+{
public:
- TStartObserver() : awake_(false) {}
- virtual void preServe() {
- apache::thrift::concurrency::Synchronized s(m_);
- awake_ = true;
- m_.notifyAll();
- }
- void waitForService() {
- apache::thrift::concurrency::Synchronized s(m_);
- while (!awake_)
- m_.waitForever();
- }
-
-private:
- apache::thrift::concurrency::Monitor m_;
- bool awake_;
+ TStartObserver() : awake_(false) {}
+ virtual void preServe()
+ {
+ apache::thrift::concurrency::Synchronized s(m_);
+ awake_ = true;
+ m_.notifyAll();
+ }
+ void waitForService()
+ {
+ apache::thrift::concurrency::Synchronized s(m_);
+ while(!awake_)
+ m_.waitForever();
+ }
+ private:
+ apache::thrift::concurrency::Monitor m_;
+ bool awake_;
};
-int main(int argc, char** argv) {
+int main(int argc, char **argv) {
#if _WIN32
transport::TWinsockSingleton::create();
#endif
@@ -258,7 +249,7 @@
size_t workerCount = 4;
size_t clientCount = 20;
size_t loopCount = 50000;
- TType loopType = T_VOID;
+ TType loopType = T_VOID;
string callName = "echoVoid";
bool runServer = true;
bool logRequests = false;
@@ -267,34 +258,28 @@
ostringstream usage;
- usage << argv[0] << " [--port=<port number>] [--server] [--server-type=<server-type>] "
- "[--protocol-type=<protocol-type>] [--workers=<worker-count>] "
- "[--clients=<client-count>] [--loop=<loop-count>]" << endl
- << "\tclients Number of client threads to create - 0 implies no clients, i.e. "
- "server only. Default is " << clientCount << endl
- << "\thelp Prints this help text." << endl
- << "\tcall Service method to call. Default is " << callName << endl
- << "\tloop The number of remote thrift calls each client makes. Default is "
- << loopCount << endl << "\tport The port the server and clients should bind to "
- "for thrift network connections. Default is " << port << endl
- << "\tserver Run the Thrift server in this process. Default is " << runServer
- << endl << "\tserver-type Type of server, \"simple\" or \"thread-pool\". Default is "
- << serverType << endl
- << "\tprotocol-type Type of protocol, \"binary\", \"ascii\", or \"xml\". Default is "
- << protocolType << endl
- << "\tlog-request Log all request to ./requestlog.tlog. Default is " << logRequests
- << endl << "\treplay-request Replay requests from log file (./requestlog.tlog) Default is "
- << replayRequests << endl << "\tworkers Number of thread pools workers. Only valid "
- "for thread-pool server type. Default is " << workerCount
- << endl;
+ usage <<
+ argv[0] << " [--port=<port number>] [--server] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>] [--clients=<client-count>] [--loop=<loop-count>]" << endl <<
+ "\tclients Number of client threads to create - 0 implies no clients, i.e. server only. Default is " << clientCount << endl <<
+ "\thelp Prints this help text." << endl <<
+ "\tcall Service method to call. Default is " << callName << endl <<
+ "\tloop The number of remote thrift calls each client makes. Default is " << loopCount << endl <<
+ "\tport The port the server and clients should bind to for thrift network connections. Default is " << port << endl <<
+ "\tserver Run the Thrift server in this process. Default is " << runServer << endl <<
+ "\tserver-type Type of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl <<
+ "\tprotocol-type Type of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl <<
+ "\tlog-request Log all request to ./requestlog.tlog. Default is " << logRequests << endl <<
+ "\treplay-request Replay requests from log file (./requestlog.tlog) Default is " << replayRequests << endl <<
+ "\tworkers Number of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl;
- map<string, string> args;
+
+ map<string, string> args;
for (int ix = 1; ix < argc; ix++) {
string arg(argv[ix]);
- if (arg.compare(0, 2, "--") == 0) {
+ if (arg.compare(0,2, "--") == 0) {
size_t end = arg.find_first_of("=", 2);
@@ -306,7 +291,7 @@
args[key] = "true";
}
} else {
- throw invalid_argument("Unexcepted command line token: " + arg);
+ throw invalid_argument("Unexcepted command line token: "+arg);
}
}
@@ -356,7 +341,7 @@
} else {
- throw invalid_argument("Unknown server type " + serverType);
+ throw invalid_argument("Unknown server type "+serverType);
}
}
@@ -364,13 +349,12 @@
workerCount = atoi(args["workers"].c_str());
}
- } catch (std::exception& e) {
+ } catch(std::exception& e) {
cerr << e.what() << endl;
cerr << usage.str();
}
- boost::shared_ptr<PlatformThreadFactory> threadFactory
- = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
+ boost::shared_ptr<PlatformThreadFactory> threadFactory = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
// Dispatcher
boost::shared_ptr<Server> serviceHandler(new Server());
@@ -388,12 +372,15 @@
// Protocol Factory
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
- TFileProcessor fileProcessor(serviceProcessor, protocolFactory, fileTransport);
+ TFileProcessor fileProcessor(serviceProcessor,
+ protocolFactory,
+ fileTransport);
fileProcessor.process(0, true);
exit(0);
}
+
if (runServer) {
boost::shared_ptr<ServiceProcessor> serviceProcessor(new ServiceProcessor(serviceHandler));
@@ -413,34 +400,27 @@
fileTransport->setChunkSize(2 * 1024 * 1024);
fileTransport->setMaxEventSize(1024 * 16);
- transportFactory
- = boost::shared_ptr<TTransportFactory>(new TPipedTransportFactory(fileTransport));
+ transportFactory =
+ boost::shared_ptr<TTransportFactory>(new TPipedTransportFactory(fileTransport));
}
boost::shared_ptr<TServer> server;
if (serverType == "simple") {
- server.reset(
- new TSimpleServer(serviceProcessor, serverSocket, transportFactory, protocolFactory));
+ server.reset(new TSimpleServer(serviceProcessor, serverSocket, transportFactory, protocolFactory));
} else if (serverType == "threaded") {
- server.reset(
- new TThreadedServer(serviceProcessor, serverSocket, transportFactory, protocolFactory));
+ server.reset(new TThreadedServer(serviceProcessor, serverSocket, transportFactory, protocolFactory));
} else if (serverType == "thread-pool") {
- boost::shared_ptr<ThreadManager> threadManager
- = ThreadManager::newSimpleThreadManager(workerCount);
+ boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);
threadManager->threadFactory(threadFactory);
threadManager->start();
- server.reset(new TThreadPoolServer(serviceProcessor,
- serverSocket,
- transportFactory,
- protocolFactory,
- threadManager));
+ server.reset(new TThreadPoolServer(serviceProcessor, serverSocket, transportFactory, protocolFactory, threadManager));
}
boost::shared_ptr<TStartObserver> observer(new TStartObserver);
@@ -466,19 +446,12 @@
set<boost::shared_ptr<Thread> > clientThreads;
- if (callName == "echoVoid") {
- loopType = T_VOID;
- } else if (callName == "echoByte") {
- loopType = T_BYTE;
- } else if (callName == "echoI32") {
- loopType = T_I32;
- } else if (callName == "echoI64") {
- loopType = T_I64;
- } else if (callName == "echoString") {
- loopType = T_STRING;
- } else {
- throw invalid_argument("Unknown service call " + callName);
- }
+ if (callName == "echoVoid") { loopType = T_VOID;}
+ else if (callName == "echoByte") { loopType = T_BYTE;}
+ else if (callName == "echoI32") { loopType = T_I32;}
+ else if (callName == "echoI64") { loopType = T_I64;}
+ else if (callName == "echoString") { loopType = T_STRING;}
+ else {throw invalid_argument("Unknown service call "+callName);}
for (size_t ix = 0; ix < clientCount; ix++) {
@@ -487,34 +460,30 @@
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(bufferedSocket));
boost::shared_ptr<ServiceClient> serviceClient(new ServiceClient(protocol));
- clientThreads.insert(threadFactory->newThread(boost::shared_ptr<ClientThread>(
- new ClientThread(socket, serviceClient, monitor, threadCount, loopCount, loopType))));
+ clientThreads.insert(threadFactory->newThread(boost::shared_ptr<ClientThread>(new ClientThread(socket, serviceClient, monitor, threadCount, loopCount, loopType))));
}
- for (std::set<boost::shared_ptr<Thread> >::const_iterator thread = clientThreads.begin();
- thread != clientThreads.end();
- thread++) {
+ for (std::set<boost::shared_ptr<Thread> >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) {
(*thread)->start();
}
int64_t time00;
int64_t time01;
- {
- Synchronized s(monitor);
+ {Synchronized s(monitor);
threadCount = clientCount;
- cerr << "Launch " << clientCount << " client threads" << endl;
+ cerr << "Launch "<< clientCount << " client threads" << endl;
- time00 = Util::currentTime();
+ time00 = Util::currentTime();
monitor.notifyAll();
- while (threadCount > 0) {
+ while(threadCount > 0) {
monitor.wait();
}
- time01 = Util::currentTime();
+ time01 = Util::currentTime();
}
int64_t firstTime = 9223372036854775807LL;
@@ -524,12 +493,9 @@
int64_t minTime = 9223372036854775807LL;
int64_t maxTime = 0;
- for (set<boost::shared_ptr<Thread> >::iterator ix = clientThreads.begin();
- ix != clientThreads.end();
- ix++) {
+ for (set<boost::shared_ptr<Thread> >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) {
- boost::shared_ptr<ClientThread> client
- = boost::dynamic_pointer_cast<ClientThread>((*ix)->runnable());
+ boost::shared_ptr<ClientThread> client = boost::dynamic_pointer_cast<ClientThread>((*ix)->runnable());
int64_t delta = client->_endTime - client->_startTime;
@@ -551,13 +517,13 @@
maxTime = delta;
}
- averageTime += delta;
+ averageTime+= delta;
}
averageTime /= clientCount;
- cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount
- << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl;
+
+ cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl;
count_map count = serviceHandler->getCount();
count_map::iterator iter;
diff --git a/test/cpp/src/StressTestNonBlocking.cpp b/test/cpp/src/StressTestNonBlocking.cpp
index 8f161c0..20320c7 100644
--- a/test/cpp/src/StressTestNonBlocking.cpp
+++ b/test/cpp/src/StressTestNonBlocking.cpp
@@ -43,7 +43,7 @@
#include <sstream>
#include <map>
#if _WIN32
-#include <thrift/windows/TWinsockSingleton.h>
+ #include <thrift/windows/TWinsockSingleton.h>
#endif
using namespace std;
@@ -57,18 +57,23 @@
using namespace test::stress;
struct eqstr {
- bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; }
+ bool operator()(const char* s1, const char* s2) const {
+ return strcmp(s1, s2) == 0;
+ }
};
struct ltstr {
- bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; }
+ bool operator()(const char* s1, const char* s2) const {
+ return strcmp(s1, s2) < 0;
+ }
};
+
// typedef hash_map<const char*, int, hash<const char*>, eqstr> count_map;
typedef map<const char*, int, ltstr> count_map;
class Server : public ServiceIf {
-public:
+ public:
Server() {}
void count(const char* method) {
@@ -89,73 +94,58 @@
return counts_;
}
- int8_t echoByte(const int8_t arg) { return arg; }
- int32_t echoI32(const int32_t arg) { return arg; }
- int64_t echoI64(const int64_t arg) { return arg; }
- void echoString(string& out, const string& arg) {
+ int8_t echoByte(const int8_t arg) {return arg;}
+ int32_t echoI32(const int32_t arg) {return arg;}
+ int64_t echoI64(const int64_t arg) {return arg;}
+ void echoString(string& out, const string &arg) {
if (arg != "hello") {
T_ERROR_ABORT("WRONG STRING (%s)!!!!", arg.c_str());
}
out = arg;
}
- void echoList(vector<int8_t>& out, const vector<int8_t>& arg) { out = arg; }
- void echoSet(set<int8_t>& out, const set<int8_t>& arg) { out = arg; }
- void echoMap(map<int8_t, int8_t>& out, const map<int8_t, int8_t>& arg) { out = arg; }
+ void echoList(vector<int8_t> &out, const vector<int8_t> &arg) { out = arg; }
+ void echoSet(set<int8_t> &out, const set<int8_t> &arg) { out = arg; }
+ void echoMap(map<int8_t, int8_t> &out, const map<int8_t, int8_t> &arg) { out = arg; }
private:
count_map counts_;
Mutex lock_;
+
};
-class ClientThread : public Runnable {
+class ClientThread: public Runnable {
public:
- ClientThread(boost::shared_ptr<TTransport> transport,
- boost::shared_ptr<ServiceClient> client,
- Monitor& monitor,
- size_t& workerCount,
- size_t loopCount,
- TType loopType)
- : _transport(transport),
- _client(client),
- _monitor(monitor),
- _workerCount(workerCount),
- _loopCount(loopCount),
- _loopType(loopType) {}
+
+ ClientThread(boost::shared_ptr<TTransport>transport, boost::shared_ptr<ServiceClient> client, Monitor& monitor, size_t& workerCount, size_t loopCount, TType loopType) :
+ _transport(transport),
+ _client(client),
+ _monitor(monitor),
+ _workerCount(workerCount),
+ _loopCount(loopCount),
+ _loopType(loopType)
+ {}
void run() {
// Wait for all worker threads to start
- {
- Synchronized s(_monitor);
- while (_workerCount == 0) {
- _monitor.wait();
- }
+ {Synchronized s(_monitor);
+ while(_workerCount == 0) {
+ _monitor.wait();
+ }
}
_startTime = Util::currentTime();
_transport->open();
- switch (_loopType) {
- case T_VOID:
- loopEchoVoid();
- break;
- case T_BYTE:
- loopEchoByte();
- break;
- case T_I32:
- loopEchoI32();
- break;
- case T_I64:
- loopEchoI64();
- break;
- case T_STRING:
- loopEchoString();
- break;
- default:
- cerr << "Unexpected loop type" << _loopType << endl;
- break;
+ switch(_loopType) {
+ case T_VOID: loopEchoVoid(); break;
+ case T_BYTE: loopEchoByte(); break;
+ case T_I32: loopEchoI32(); break;
+ case T_I64: loopEchoI64(); break;
+ case T_STRING: loopEchoString(); break;
+ default: cerr << "Unexpected loop type" << _loopType << endl; break;
}
_endTime = Util::currentTime();
@@ -164,8 +154,7 @@
_done = true;
- {
- Synchronized s(_monitor);
+ {Synchronized s(_monitor);
_workerCount--;
@@ -186,7 +175,7 @@
for (size_t ix = 0; ix < _loopCount; ix++) {
int8_t arg = 1;
int8_t result;
- result = _client->echoByte(arg);
+ result =_client->echoByte(arg);
(void)result;
assert(result == arg);
}
@@ -196,7 +185,7 @@
for (size_t ix = 0; ix < _loopCount; ix++) {
int32_t arg = 1;
int32_t result;
- result = _client->echoI32(arg);
+ result =_client->echoI32(arg);
(void)result;
assert(result == arg);
}
@@ -206,7 +195,7 @@
for (size_t ix = 0; ix < _loopCount; ix++) {
int64_t arg = 1;
int64_t result;
- result = _client->echoI64(arg);
+ result =_client->echoI64(arg);
(void)result;
assert(result == arg);
}
@@ -233,7 +222,8 @@
Monitor _sleep;
};
-int main(int argc, char** argv) {
+
+int main(int argc, char **argv) {
#if _WIN32
transport::TWinsockSingleton::create();
#endif
@@ -244,7 +234,7 @@
uint32_t workerCount = 4;
uint32_t clientCount = 20;
uint32_t loopCount = 1000;
- TType loopType = T_VOID;
+ TType loopType = T_VOID;
string callName = "echoVoid";
bool runServer = true;
bool logRequests = false;
@@ -253,34 +243,28 @@
ostringstream usage;
- usage << argv[0] << " [--port=<port number>] [--server] [--server-type=<server-type>] "
- "[--protocol-type=<protocol-type>] [--workers=<worker-count>] "
- "[--clients=<client-count>] [--loop=<loop-count>]" << endl
- << "\tclients Number of client threads to create - 0 implies no clients, i.e. "
- "server only. Default is " << clientCount << endl
- << "\thelp Prints this help text." << endl
- << "\tcall Service method to call. Default is " << callName << endl
- << "\tloop The number of remote thrift calls each client makes. Default is "
- << loopCount << endl << "\tport The port the server and clients should bind to "
- "for thrift network connections. Default is " << port << endl
- << "\tserver Run the Thrift server in this process. Default is " << runServer
- << endl << "\tserver-type Type of server, \"simple\" or \"thread-pool\". Default is "
- << serverType << endl
- << "\tprotocol-type Type of protocol, \"binary\", \"ascii\", or \"xml\". Default is "
- << protocolType << endl
- << "\tlog-request Log all request to ./requestlog.tlog. Default is " << logRequests
- << endl << "\treplay-request Replay requests from log file (./requestlog.tlog) Default is "
- << replayRequests << endl << "\tworkers Number of thread pools workers. Only valid "
- "for thread-pool server type. Default is " << workerCount
- << endl;
+ usage <<
+ argv[0] << " [--port=<port number>] [--server] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>] [--clients=<client-count>] [--loop=<loop-count>]" << endl <<
+ "\tclients Number of client threads to create - 0 implies no clients, i.e. server only. Default is " << clientCount << endl <<
+ "\thelp Prints this help text." << endl <<
+ "\tcall Service method to call. Default is " << callName << endl <<
+ "\tloop The number of remote thrift calls each client makes. Default is " << loopCount << endl <<
+ "\tport The port the server and clients should bind to for thrift network connections. Default is " << port << endl <<
+ "\tserver Run the Thrift server in this process. Default is " << runServer << endl <<
+ "\tserver-type Type of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl <<
+ "\tprotocol-type Type of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl <<
+ "\tlog-request Log all request to ./requestlog.tlog. Default is " << logRequests << endl <<
+ "\treplay-request Replay requests from log file (./requestlog.tlog) Default is " << replayRequests << endl <<
+ "\tworkers Number of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl;
- map<string, string> args;
+
+ map<string, string> args;
for (int ix = 1; ix < argc; ix++) {
string arg(argv[ix]);
- if (arg.compare(0, 2, "--") == 0) {
+ if (arg.compare(0,2, "--") == 0) {
size_t end = arg.find_first_of("=", 2);
@@ -292,7 +276,7 @@
args[key] = "true";
}
} else {
- throw invalid_argument("Unexcepted command line token: " + arg);
+ throw invalid_argument("Unexcepted command line token: "+arg);
}
}
@@ -339,13 +323,12 @@
workerCount = atoi(args["workers"].c_str());
}
- } catch (std::exception& e) {
+ } catch(std::exception& e) {
cerr << e.what() << endl;
cerr << usage.str();
}
- boost::shared_ptr<PlatformThreadFactory> threadFactory
- = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
+ boost::shared_ptr<PlatformThreadFactory> threadFactory = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
// Dispatcher
boost::shared_ptr<Server> serviceHandler(new Server());
@@ -363,12 +346,15 @@
// Protocol Factory
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
- TFileProcessor fileProcessor(serviceProcessor, protocolFactory, fileTransport);
+ TFileProcessor fileProcessor(serviceProcessor,
+ protocolFactory,
+ fileTransport);
fileProcessor.process(0, true);
exit(0);
}
+
if (runServer) {
boost::shared_ptr<ServiceProcessor> serviceProcessor(new ServiceProcessor(serviceHandler));
@@ -377,7 +363,7 @@
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
// Transport Factory
- boost::shared_ptr<TTransportFactory> transportFactory;
+ boost::shared_ptr<TTransportFactory> transportFactory;
if (logRequests) {
// initialize the log file
@@ -385,8 +371,8 @@
fileTransport->setChunkSize(2 * 1024 * 1024);
fileTransport->setMaxEventSize(1024 * 16);
- transportFactory
- = boost::shared_ptr<TTransportFactory>(new TPipedTransportFactory(fileTransport));
+ transportFactory =
+ boost::shared_ptr<TTransportFactory>(new TPipedTransportFactory(fileTransport));
}
boost::shared_ptr<Thread> serverThread;
@@ -394,22 +380,17 @@
if (serverType == "simple") {
- serverThread = threadFactory->newThread(boost::shared_ptr<TServer>(
- new TNonblockingServer(serviceProcessor, protocolFactory, port)));
- serverThread2 = threadFactory->newThread(boost::shared_ptr<TServer>(
- new TNonblockingServer(serviceProcessor, protocolFactory, port + 1)));
+ serverThread = threadFactory->newThread(boost::shared_ptr<TServer>(new TNonblockingServer(serviceProcessor, protocolFactory, port)));
+ serverThread2 = threadFactory->newThread(boost::shared_ptr<TServer>(new TNonblockingServer(serviceProcessor, protocolFactory, port+1)));
} else if (serverType == "thread-pool") {
- boost::shared_ptr<ThreadManager> threadManager
- = ThreadManager::newSimpleThreadManager(workerCount);
+ boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);
threadManager->threadFactory(threadFactory);
threadManager->start();
- serverThread = threadFactory->newThread(boost::shared_ptr<TServer>(
- new TNonblockingServer(serviceProcessor, protocolFactory, port, threadManager)));
- serverThread2 = threadFactory->newThread(boost::shared_ptr<TServer>(
- new TNonblockingServer(serviceProcessor, protocolFactory, port + 1, threadManager)));
+ serverThread = threadFactory->newThread(boost::shared_ptr<TServer>(new TNonblockingServer(serviceProcessor, protocolFactory, port, threadManager)));
+ serverThread2 = threadFactory->newThread(boost::shared_ptr<TServer>(new TNonblockingServer(serviceProcessor, protocolFactory, port+1, threadManager)));
}
cerr << "Starting the server on port " << port << " and " << (port + 1) << endl;
@@ -433,19 +414,12 @@
set<boost::shared_ptr<Thread> > clientThreads;
- if (callName == "echoVoid") {
- loopType = T_VOID;
- } else if (callName == "echoByte") {
- loopType = T_BYTE;
- } else if (callName == "echoI32") {
- loopType = T_I32;
- } else if (callName == "echoI64") {
- loopType = T_I64;
- } else if (callName == "echoString") {
- loopType = T_STRING;
- } else {
- throw invalid_argument("Unknown service call " + callName);
- }
+ if (callName == "echoVoid") { loopType = T_VOID;}
+ else if (callName == "echoByte") { loopType = T_BYTE;}
+ else if (callName == "echoI32") { loopType = T_I32;}
+ else if (callName == "echoI64") { loopType = T_I64;}
+ else if (callName == "echoString") { loopType = T_STRING;}
+ else {throw invalid_argument("Unknown service call "+callName);}
for (uint32_t ix = 0; ix < clientCount; ix++) {
@@ -454,34 +428,30 @@
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(framedSocket));
boost::shared_ptr<ServiceClient> serviceClient(new ServiceClient(protocol));
- clientThreads.insert(threadFactory->newThread(boost::shared_ptr<ClientThread>(
- new ClientThread(socket, serviceClient, monitor, threadCount, loopCount, loopType))));
+ clientThreads.insert(threadFactory->newThread(boost::shared_ptr<ClientThread>(new ClientThread(socket, serviceClient, monitor, threadCount, loopCount, loopType))));
}
- for (std::set<boost::shared_ptr<Thread> >::const_iterator thread = clientThreads.begin();
- thread != clientThreads.end();
- thread++) {
+ for (std::set<boost::shared_ptr<Thread> >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) {
(*thread)->start();
}
int64_t time00;
int64_t time01;
- {
- Synchronized s(monitor);
+ {Synchronized s(monitor);
threadCount = clientCount;
- cerr << "Launch " << clientCount << " client threads" << endl;
+ cerr << "Launch "<< clientCount << " client threads" << endl;
- time00 = Util::currentTime();
+ time00 = Util::currentTime();
monitor.notifyAll();
- while (threadCount > 0) {
+ while(threadCount > 0) {
monitor.wait();
}
- time01 = Util::currentTime();
+ time01 = Util::currentTime();
}
int64_t firstTime = 9223372036854775807LL;
@@ -491,12 +461,9 @@
int64_t minTime = 9223372036854775807LL;
int64_t maxTime = 0;
- for (set<boost::shared_ptr<Thread> >::iterator ix = clientThreads.begin();
- ix != clientThreads.end();
- ix++) {
+ for (set<boost::shared_ptr<Thread> >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) {
- boost::shared_ptr<ClientThread> client
- = boost::dynamic_pointer_cast<ClientThread>((*ix)->runnable());
+ boost::shared_ptr<ClientThread> client = boost::dynamic_pointer_cast<ClientThread>((*ix)->runnable());
int64_t delta = client->_endTime - client->_startTime;
@@ -518,13 +485,13 @@
maxTime = delta;
}
- averageTime += delta;
+ averageTime+= delta;
}
averageTime /= clientCount;
- cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount
- << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl;
+
+ cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl;
count_map count = serviceHandler->getCount();
count_map::iterator iter;
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
old mode 100644
new mode 100755
index a6069de..8c97dc0
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -36,7 +36,7 @@
#include <boost/filesystem.hpp>
#include <thrift/cxxfunctional.h>
#if _WIN32
-#include <thrift/windows/TWinsockSingleton.h>
+ #include <thrift/windows/TWinsockSingleton.h>
#endif
#include "ThriftTest.h"
@@ -51,27 +51,24 @@
// Length of argv[0] - Length of script dir
#define EXECUTABLE_FILE_NAME_LENGTH 19
-// extern uint32_t g_socket_syscalls;
+//extern uint32_t g_socket_syscalls;
// Current time, microseconds since the epoch
-uint64_t now() {
+uint64_t now()
+{
int64_t ret;
struct timeval tv;
THRIFT_GETTIMEOFDAY(&tv, NULL);
ret = tv.tv_sec;
- ret = ret * 1000 * 1000 + tv.tv_usec;
+ ret = ret*1000*1000 + tv.tv_usec;
return ret;
}
-static void testString_clientReturn(const char* host,
- int port,
- event_base* base,
- TProtocolFactory* protocolFactory,
- ThriftTestCobClient* client) {
- (void)host;
- (void)port;
- (void)protocolFactory;
+static void testString_clientReturn(const char* host, int port, event_base *base, TProtocolFactory* protocolFactory, ThriftTestCobClient* client) {
+ (void) host;
+ (void) port;
+ (void) protocolFactory;
try {
string s;
client->recv_testString(s);
@@ -83,11 +80,7 @@
event_base_loopbreak(base); // end test
}
-static void testVoid_clientReturn(const char* host,
- int port,
- event_base* base,
- TProtocolFactory* protocolFactory,
- ThriftTestCobClient* client) {
+static void testVoid_clientReturn(const char* host, int port, event_base *base, TProtocolFactory* protocolFactory, ThriftTestCobClient* client) {
try {
client->recv_testVoid();
cout << "testVoid" << endl;
@@ -96,13 +89,7 @@
delete client;
boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host, "/", host, port, base));
client = new ThriftTestCobClient(channel, protocolFactory);
- client->testString(tcxx::bind(testString_clientReturn,
- host,
- port,
- base,
- protocolFactory,
- tcxx::placeholders::_1),
- "Test");
+ client->testString(tcxx::bind(testString_clientReturn, host, port, base, protocolFactory, tcxx::placeholders::_1), "Test");
} catch (TException& exn) {
cout << "Error: " << exn.what() << endl;
}
@@ -110,7 +97,7 @@
int main(int argc, char** argv) {
string file_path = boost::filesystem::system_complete(argv[0]).string();
- string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
+ string dir_path = file_path.substr(0, file_path.size()-EXECUTABLE_FILE_NAME_LENGTH);
#if _WIN32
transport::TWinsockSingleton::create();
#endif
@@ -124,26 +111,17 @@
bool noinsane = false;
boost::program_options::options_description desc("Allowed options");
- desc.add_options()("help,h",
- "produce help message")("host",
- boost::program_options::value<string>(&host)
- ->default_value(host),
- "Host to connect")("port",
- boost::program_options::value<int>(
- &port)->default_value(port),
- "Port number to connect")(
- "domain-socket",
- boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
- "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
- "transport",
- boost::program_options::value<string>(&transport_type)->default_value(transport_type),
- "Transport: buffered, framed, http, evhttp")(
- "protocol",
- boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
- "Protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
- "testloops,n",
- boost::program_options::value<int>(&numTests)->default_value(numTests),
- "Number of Tests")("noinsane", "Do not run insanity test");
+ desc.add_options()
+ ("help,h", "produce help message")
+ ("host", boost::program_options::value<string>(&host)->default_value(host), "Host to connect")
+ ("port", boost::program_options::value<int>(&port)->default_value(port), "Port number to connect")
+ ("domain-socket", boost::program_options::value<string>(&domain_socket)->default_value(domain_socket), "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")
+ ("transport", boost::program_options::value<string>(&transport_type)->default_value(transport_type), "Transport: buffered, framed, http, evhttp")
+ ("protocol", boost::program_options::value<string>(&protocol_type)->default_value(protocol_type), "Protocol: binary, compact, json")
+ ("ssl", "Encrypted Transport using SSL")
+ ("testloops,n", boost::program_options::value<int>(&numTests)->default_value(numTests), "Number of Tests")
+ ("noinsane", "Do not run insanity test")
+ ;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
@@ -160,17 +138,17 @@
} else if (protocol_type == "compact") {
} else if (protocol_type == "json") {
} else {
- throw invalid_argument("Unknown protocol type " + protocol_type);
+ throw invalid_argument("Unknown protocol type "+protocol_type);
}
}
- if (!transport_type.empty()) {
+ if (!transport_type.empty()) {
if (transport_type == "buffered") {
} else if (transport_type == "framed") {
} else if (transport_type == "http") {
} else if (transport_type == "evhttp") {
} else {
- throw invalid_argument("Unknown transport type " + transport_type);
+ throw invalid_argument("Unknown transport type "+transport_type);
}
}
@@ -204,7 +182,8 @@
if (domain_socket != "") {
socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
port = 0;
- } else {
+ }
+ else {
socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
}
}
@@ -212,10 +191,10 @@
if (transport_type.compare("http") == 0) {
boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
transport = httpSocket;
- } else if (transport_type.compare("framed") == 0) {
+ } else if (transport_type.compare("framed") == 0){
boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
transport = framedSocket;
- } else {
+ } else{
boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
transport = bufferedSocket;
}
@@ -226,7 +205,7 @@
} else if (protocol_type.compare("compact") == 0) {
boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
protocol = compactProtocol;
- } else {
+ } else{
boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
protocol = binaryProtocol;
}
@@ -239,7 +218,7 @@
cout << endl;
if (transport_type.compare("evhttp") == 0) {
- event_base* base = event_base_new();
+ event_base *base = event_base_new();
cout << "Libevent Version: " << event_get_version() << endl;
cout << "Libevent Method: " << event_base_get_method(base) << endl;
#if LIBEVENT_VERSION_NUMBER >= 0x02000000
@@ -248,20 +227,15 @@
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
- boost::shared_ptr<TAsyncChannel> channel(
- new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
+ boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
- client->testVoid(tcxx::bind(testVoid_clientReturn,
- host.c_str(),
- port,
- base,
- protocolFactory.get(),
- tcxx::placeholders::_1));
+ client->testVoid(tcxx::bind(testVoid_clientReturn, host.c_str(), port, base, protocolFactory.get(), tcxx::placeholders::_1));
event_base_loop(base, 0);
return 0;
}
+
ThriftTestClient testClient(protocol);
uint64_t time_min = 0;
@@ -282,7 +256,7 @@
/**
* CONNECT TEST
*/
- printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
+ printf("Test #%d, connect %s:%d\n", test+1, host.c_str(), port);
uint64_t start = now();
@@ -306,7 +280,7 @@
testClient.testString(s, "Test");
printf(" = \"%s\"\n", s.c_str());
if (s != "Test")
- failCount++;
+ failCount++;
/**
* BYTE TEST
@@ -315,7 +289,7 @@
uint8_t u8 = testClient.testByte(1);
printf(" = %d\n", (int)u8);
if (u8 != 1)
- failCount++;
+ failCount++;
/**
* I32 TEST
@@ -324,7 +298,7 @@
int32_t i32 = testClient.testI32(-1);
printf(" = %d\n", i32);
if (i32 != -1)
- failCount++;
+ failCount++;
/**
* I64 TEST
@@ -333,7 +307,7 @@
int64_t i64 = testClient.testI64(-34359738368LL);
printf(" = %" PRId64 "\n", i64);
if (i64 != -34359738368LL)
- failCount++;
+ failCount++;
/**
* DOUBLE TEST
*/
@@ -341,7 +315,7 @@
double dub = testClient.testDouble(-5.2098523);
printf(" = %f\n", dub);
if ((dub - (-5.2098523)) > 0.001)
- failCount++;
+ failCount++;
/**
* STRUCT TEST
@@ -360,7 +334,7 @@
in.i32_thing,
in.i64_thing);
if (in != out)
- failCount++;
+ failCount++;
/**
* NESTED STRUCT TEST
@@ -381,14 +355,14 @@
in.i64_thing,
in2.i32_thing);
if (in2 != out2)
- failCount++;
+ failCount++;
/**
* MAP TEST
*/
- map<int32_t, int32_t> mapout;
+ map<int32_t,int32_t> mapout;
for (int32_t i = 0; i < 5; ++i) {
- mapout.insert(make_pair(i, i - 10));
+ mapout.insert(make_pair(i, i-10));
}
printf("testMap({");
map<int32_t, int32_t>::const_iterator m_iter;
@@ -402,7 +376,7 @@
printf("%d => %d", m_iter->first, m_iter->second);
}
printf("})");
- map<int32_t, int32_t> mapin;
+ map<int32_t,int32_t> mapin;
testClient.testMap(mapin, mapout);
printf(" = {");
first = true;
@@ -416,7 +390,7 @@
}
printf("}\n");
if (mapin != mapout)
- failCount++;
+ failCount++;
/**
* STRING MAP TEST
@@ -456,7 +430,7 @@
}
printf("}\n");
if (setin != setout)
- failCount++;
+ failCount++;
/**
* LIST TEST
@@ -491,7 +465,7 @@
}
printf("}\n");
if (listin != listout)
- failCount++;
+ failCount++;
/**
* ENUM TEST
@@ -500,31 +474,31 @@
Numberz::type ret = testClient.testEnum(Numberz::ONE);
printf(" = %d\n", ret);
if (ret != Numberz::ONE)
- failCount++;
+ failCount++;
printf("testEnum(TWO)");
ret = testClient.testEnum(Numberz::TWO);
printf(" = %d\n", ret);
if (ret != Numberz::TWO)
- failCount++;
+ failCount++;
printf("testEnum(THREE)");
ret = testClient.testEnum(Numberz::THREE);
printf(" = %d\n", ret);
if (ret != Numberz::THREE)
- failCount++;
+ failCount++;
printf("testEnum(FIVE)");
ret = testClient.testEnum(Numberz::FIVE);
printf(" = %d\n", ret);
if (ret != Numberz::FIVE)
- failCount++;
+ failCount++;
printf("testEnum(EIGHT)");
ret = testClient.testEnum(Numberz::EIGHT);
printf(" = %d\n", ret);
if (ret != Numberz::EIGHT)
- failCount++;
+ failCount++;
/**
* TYPEDEF TEST
@@ -533,7 +507,7 @@
UserId uid = testClient.testTypedef(309858235082523LL);
printf(" = %" PRId64 "\n", uid);
if (uid != 309858235082523LL)
- failCount++;
+ failCount++;
/**
* NESTED MAP TEST
@@ -566,14 +540,16 @@
truck.i64_thing = 8;
insane.xtructs.push_back(truck);
printf("testInsanity()");
- map<UserId, map<Numberz::type, Insanity> > whoa;
+ map<UserId, map<Numberz::type,Insanity> > whoa;
testClient.testInsanity(whoa, insane);
printf(" = {");
- map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
+ map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
printf("%" PRId64 " => {", i_iter->first);
- map<Numberz::type, Insanity>::const_iterator i2_iter;
- for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
+ map<Numberz::type,Insanity>::const_iterator i2_iter;
+ for (i2_iter = i_iter->second.begin();
+ i2_iter != i_iter->second.end();
+ ++i2_iter) {
printf("%d => {", i2_iter->first);
map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
map<Numberz::type, UserId>::const_iterator um;
@@ -609,25 +585,25 @@
printf(" void\nFAILURE\n");
failCount++;
- } catch (Xception& e) {
+ } catch(Xception& e) {
printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
}
try {
- printf("testClient.testException(\"TException\") =>");
- testClient.testException("TException");
- printf(" void\nFAILURE\n");
- failCount++;
+ printf("testClient.testException(\"TException\") =>");
+ testClient.testException("TException");
+ printf(" void\nFAILURE\n");
+ failCount++;
- } catch (const TException&) {
- printf(" Caught TException\n");
- }
+ } catch(const TException&) {
+ printf(" Caught TException\n");
+ }
try {
printf("testClient.testException(\"success\") =>");
testClient.testException("success");
printf(" void\n");
- } catch (...) {
+ } catch(...) {
printf(" exception\nFAILURE\n");
failCount++;
}
@@ -640,7 +616,7 @@
testClient.testMultiException(result, "Xception", "test 1");
printf(" result\nFAILURE\n");
failCount++;
- } catch (Xception& e) {
+ } catch(Xception& e) {
printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
}
@@ -651,7 +627,7 @@
printf(" result\nFAILURE\n");
failCount++;
- } catch (Xception2& e) {
+ } catch(Xception2& e) {
printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
}
@@ -660,23 +636,23 @@
Xtruct result;
testClient.testMultiException(result, "success", "test 3");
printf(" {{\"%s\"}}\n", result.string_thing.c_str());
- } catch (...) {
+ } catch(...) {
printf(" exception\nFAILURE\n");
failCount++;
}
/* test oneway void */
{
- printf("testClient.testOneway(1) =>");
- uint64_t startOneway = now();
- testClient.testOneway(1);
- uint64_t elapsed = now() - startOneway;
- if (elapsed > 200 * 1000) { // 0.2 seconds
- printf(" FAILURE - took %.2f ms\n", (double)elapsed / 1000.0);
- failCount++;
- } else {
- printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
- }
+ printf("testClient.testOneway(1) =>");
+ uint64_t startOneway = now();
+ testClient.testOneway(1);
+ uint64_t elapsed = now() - startOneway;
+ if (elapsed > 200 * 1000) { // 0.2 seconds
+ printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0);
+ failCount++;
+ } else {
+ printf(" success - took %.2f ms\n", (double)elapsed/1000.0);
+ }
}
/**
@@ -694,12 +670,13 @@
i32 = testClient.testI32(-1);
printf(" = %d\n", i32);
if (i32 != -1)
- failCount++;
+ failCount++;
+
uint64_t stop = now();
- uint64_t tot = stop - start;
+ uint64_t tot = stop-start;
- printf("Total time: %" PRIu64 " us\n", stop - start);
+ printf("Total time: %" PRIu64 " us\n", stop-start);
time_tot += tot;
if (time_min == 0 || tot < time_min) {
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
old mode 100644
new mode 100755
index 6d2a260..a343221
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -50,7 +50,7 @@
#include <signal.h>
#if _WIN32
-#include <thrift/windows/TWinsockSingleton.h>
+ #include <thrift/windows/TWinsockSingleton.h>
#endif
using namespace std;
@@ -68,12 +68,14 @@
#define EXECUTABLE_FILE_NAME_LENGTH 19
class TestHandler : public ThriftTestIf {
-public:
+ public:
TestHandler() {}
- void testVoid() { printf("testVoid()\n"); }
+ void testVoid() {
+ printf("testVoid()\n");
+ }
- void testString(string& out, const string& thing) {
+ void testString(string& out, const string &thing) {
printf("testString(\"%s\")\n", thing.c_str());
out = thing;
}
@@ -98,28 +100,18 @@
return thing;
}
- void testStruct(Xtruct& out, const Xtruct& thing) {
- printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n",
- thing.string_thing.c_str(),
- (int)thing.byte_thing,
- thing.i32_thing,
- thing.i64_thing);
+ void testStruct(Xtruct& out, const Xtruct &thing) {
+ printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
out = thing;
}
void testNest(Xtruct2& out, const Xtruct2& nest) {
- const Xtruct& thing = nest.struct_thing;
- printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n",
- (int)nest.byte_thing,
- thing.string_thing.c_str(),
- (int)thing.byte_thing,
- thing.i32_thing,
- thing.i64_thing,
- nest.i32_thing);
+ const Xtruct &thing = nest.struct_thing;
+ printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing);
out = nest;
}
- void testMap(map<int32_t, int32_t>& out, const map<int32_t, int32_t>& thing) {
+ void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) {
printf("testMap({");
map<int32_t, int32_t>::const_iterator m_iter;
bool first = true;
@@ -135,8 +127,7 @@
out = thing;
}
- void testStringMap(map<std::string, std::string>& out,
- const map<std::string, std::string>& thing) {
+ void testStringMap(map<std::string, std::string> &out, const map<std::string, std::string> &thing) {
printf("testMap({");
map<std::string, std::string>::const_iterator m_iter;
bool first = true;
@@ -152,7 +143,7 @@
out = thing;
}
- void testSet(set<int32_t>& out, const set<int32_t>& thing) {
+ void testSet(set<int32_t> &out, const set<int32_t> &thing) {
printf("testSet({");
set<int32_t>::const_iterator s_iter;
bool first = true;
@@ -168,7 +159,7 @@
out = thing;
}
- void testList(vector<int32_t>& out, const vector<int32_t>& thing) {
+ void testList(vector<int32_t> &out, const vector<int32_t> &thing) {
printf("testList({");
vector<int32_t>::const_iterator l_iter;
bool first = true;
@@ -194,22 +185,23 @@
return thing;
}
- void testMapMap(map<int32_t, map<int32_t, int32_t> >& mapmap, const int32_t hello) {
+ void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) {
printf("testMapMap(%d)\n", hello);
- map<int32_t, int32_t> pos;
- map<int32_t, int32_t> neg;
+ map<int32_t,int32_t> pos;
+ map<int32_t,int32_t> neg;
for (int i = 1; i < 5; i++) {
- pos.insert(make_pair(i, i));
- neg.insert(make_pair(-i, -i));
+ pos.insert(make_pair(i,i));
+ neg.insert(make_pair(-i,-i));
}
mapmap.insert(make_pair(4, pos));
mapmap.insert(make_pair(-4, neg));
+
}
- void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) {
- (void)argument;
+ void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) {
+ (void) argument;
printf("testInsanity()\n");
Xtruct hello;
@@ -245,11 +237,13 @@
printf("return");
printf(" = {");
- map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
+ map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
printf("%" PRId64 " => {", i_iter->first);
- map<Numberz::type, Insanity>::const_iterator i2_iter;
- for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
+ map<Numberz::type,Insanity>::const_iterator i2_iter;
+ for (i2_iter = i_iter->second.begin();
+ i2_iter != i_iter->second.end();
+ ++i2_iter) {
printf("%d => {", i2_iter->first);
map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
map<Numberz::type, UserId>::const_iterator um;
@@ -263,11 +257,7 @@
vector<Xtruct>::const_iterator x;
printf("{");
for (x = xtructs.begin(); x != xtructs.end(); ++x) {
- printf("{\"%s\", %d, %d, %" PRId64 "}, ",
- x->string_thing.c_str(),
- (int)x->byte_thing,
- x->i32_thing,
- x->i64_thing);
+ printf("{\"%s\", %d, %d, %" PRId64 "}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
}
printf("}");
@@ -276,18 +266,14 @@
printf("}, ");
}
printf("}\n");
+
+
}
- void testMulti(Xtruct& hello,
- const int8_t arg0,
- const int32_t arg1,
- const int64_t arg2,
- const std::map<int16_t, std::string>& arg3,
- const Numberz::type arg4,
- const UserId arg5) {
- (void)arg3;
- (void)arg4;
- (void)arg5;
+ void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> &arg3, const Numberz::type arg4, const UserId arg5) {
+ (void) arg3;
+ (void) arg4;
+ (void) arg5;
printf("testMulti()\n");
@@ -297,7 +283,9 @@
hello.i64_thing = (int64_t)arg2;
}
- void testException(const std::string& arg) throw(Xception, apache::thrift::TException) {
+ void testException(const std::string &arg)
+ throw(Xception, apache::thrift::TException)
+ {
printf("testException(%s)\n", arg.c_str());
if (arg.compare("Xception") == 0) {
Xception e;
@@ -314,9 +302,7 @@
}
}
- void testMultiException(Xtruct& result,
- const std::string& arg0,
- const std::string& arg1) throw(Xception, Xception2) {
+ void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) {
printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
@@ -343,23 +329,28 @@
}
};
+
class TestProcessorEventHandler : public TProcessorEventHandler {
virtual void* getContext(const char* fn_name, void* serverContext) {
- (void)serverContext;
+ (void) serverContext;
return new std::string(fn_name);
}
virtual void freeContext(void* ctx, const char* fn_name) {
- (void)fn_name;
+ (void) fn_name;
delete static_cast<std::string*>(ctx);
}
- virtual void preRead(void* ctx, const char* fn_name) { communicate("preRead", ctx, fn_name); }
+ virtual void preRead(void* ctx, const char* fn_name) {
+ communicate("preRead", ctx, fn_name);
+ }
virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) {
- (void)bytes;
+ (void) bytes;
communicate("postRead", ctx, fn_name);
}
- virtual void preWrite(void* ctx, const char* fn_name) { communicate("preWrite", ctx, fn_name); }
+ virtual void preWrite(void* ctx, const char* fn_name) {
+ communicate("preWrite", ctx, fn_name);
+ }
virtual void postWrite(void* ctx, const char* fn_name, uint32_t bytes) {
- (void)bytes;
+ (void) bytes;
communicate("postWrite", ctx, fn_name);
}
virtual void asyncComplete(void* ctx, const char* fn_name) {
@@ -374,6 +365,7 @@
}
};
+
class TestHandlerAsync : public ThriftTestCobSvIf {
public:
TestHandlerAsync(boost::shared_ptr<TestHandler>& handler) : _delegate(handler) {}
@@ -384,8 +376,7 @@
cob();
}
- virtual void testString(tcxx::function<void(std::string const& _return)> cob,
- const std::string& thing) {
+ virtual void testString(tcxx::function<void(std::string const& _return)> cob, const std::string& thing) {
std::string res;
_delegate->testString(res, thing);
cob(res);
@@ -423,37 +414,31 @@
cob(res);
}
- virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob,
- const std::map<int32_t, int32_t>& thing) {
+ virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob, const std::map<int32_t, int32_t> & thing) {
std::map<int32_t, int32_t> res;
_delegate->testMap(res, thing);
cob(res);
}
- virtual void testStringMap(
- tcxx::function<void(std::map<std::string, std::string> const& _return)> cob,
- const std::map<std::string, std::string>& thing) {
+ virtual void testStringMap(tcxx::function<void(std::map<std::string, std::string> const& _return)> cob, const std::map<std::string, std::string> & thing) {
std::map<std::string, std::string> res;
_delegate->testStringMap(res, thing);
cob(res);
}
- virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob,
- const std::set<int32_t>& thing) {
+ virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob, const std::set<int32_t> & thing) {
std::set<int32_t> res;
_delegate->testSet(res, thing);
cob(res);
}
- virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob,
- const std::vector<int32_t>& thing) {
+ virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob, const std::vector<int32_t> & thing) {
std::vector<int32_t> res;
_delegate->testList(res, thing);
cob(res);
}
- virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob,
- const Numberz::type thing) {
+ virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob, const Numberz::type thing) {
Numberz::type res = _delegate->testEnum(thing);
cob(res);
}
@@ -463,56 +448,39 @@
cob(res);
}
- virtual void testMapMap(
- tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob,
- const int32_t hello) {
+ virtual void testMapMap(tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob, const int32_t hello) {
std::map<int32_t, std::map<int32_t, int32_t> > res;
_delegate->testMapMap(res, hello);
cob(res);
}
- virtual void testInsanity(
- tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob,
- const Insanity& argument) {
+ virtual void testInsanity(tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob, const Insanity& argument) {
std::map<UserId, std::map<Numberz::type, Insanity> > res;
_delegate->testInsanity(res, argument);
cob(res);
- }
+ }
- virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob,
- const int8_t arg0,
- const int32_t arg1,
- const int64_t arg2,
- const std::map<int16_t, std::string>& arg3,
- const Numberz::type arg4,
- const UserId arg5) {
+ virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> & arg3, const Numberz::type arg4, const UserId arg5) {
Xtruct res;
_delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5);
cob(res);
}
- virtual void testException(
- tcxx::function<void()> cob,
- tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
- const std::string& arg) {
+ virtual void testException(tcxx::function<void()> cob, tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, const std::string& arg) {
try {
_delegate->testException(arg);
- } catch (const apache::thrift::TException& e) {
+ } catch(const apache::thrift::TException& e) {
exn_cob(apache::thrift::TDelayedException::delayException(e));
return;
}
cob();
}
- virtual void testMultiException(
- tcxx::function<void(Xtruct const& _return)> cob,
- tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
- const std::string& arg0,
- const std::string& arg1) {
+ virtual void testMultiException(tcxx::function<void(Xtruct const& _return)> cob, tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, const std::string& arg0, const std::string& arg1) {
Xtruct res;
try {
_delegate->testMultiException(res, arg0, arg1);
- } catch (const apache::thrift::TException& e) {
+ } catch(const apache::thrift::TException& e) {
exn_cob(apache::thrift::TDelayedException::delayException(e));
return;
}
@@ -528,12 +496,13 @@
boost::shared_ptr<TestHandler> _delegate;
};
-int main(int argc, char** argv) {
+
+int main(int argc, char **argv) {
string file_path = boost::filesystem::system_complete(argv[0]).string();
- string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
+ string dir_path = file_path.substr(0, file_path.size()-EXECUTABLE_FILE_NAME_LENGTH);
-#if _WIN32
+ #if _WIN32
transport::TWinsockSingleton::create();
#endif
int port = 9090;
@@ -544,35 +513,32 @@
string domain_socket = "";
size_t workers = 4;
+
boost::program_options::options_description desc("Allowed options");
- desc.add_options()("help,h", "produce help message")(
- "port",
- boost::program_options::value<int>(&port)->default_value(port),
- "Port number to listen")("domain-socket",
- boost::program_options::value<string>(&domain_socket)
- ->default_value(domain_socket),
- "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")(
- "server-type",
- boost::program_options::value<string>(&server_type)->default_value(server_type),
- "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")(
- "transport",
- boost::program_options::value<string>(&transport_type)->default_value(transport_type),
- "transport: buffered, framed, http")(
- "protocol",
- boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
- "protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
- "processor-events",
- "processor-events")("workers,n",
- boost::program_options::value<size_t>(&workers)->default_value(workers),
- "Number of thread pools workers. Only valid for thread-pool server type");
+ desc.add_options()
+ ("help,h", "produce help message")
+ ("port", boost::program_options::value<int>(&port)->default_value(port), "Port number to listen")
+ ("domain-socket", boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
+ "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")
+ ("server-type", boost::program_options::value<string>(&server_type)->default_value(server_type),
+ "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")
+ ("transport", boost::program_options::value<string>(&transport_type)->default_value(transport_type),
+ "transport: buffered, framed, http")
+ ("protocol", boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
+ "protocol: binary, compact, json")
+ ("ssl", "Encrypted Transport using SSL")
+ ("processor-events", "processor-events")
+ ("workers,n", boost::program_options::value<size_t>(&workers)->default_value(workers),
+ "Number of thread pools workers. Only valid for thread-pool server type")
+ ;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
- cout << desc << "\n";
- return 1;
+ cout << desc << "\n";
+ return 1;
}
try {
@@ -582,7 +548,7 @@
} else if (server_type == "threaded") {
} else if (server_type == "nonblocking") {
} else {
- throw invalid_argument("Unknown server type " + server_type);
+ throw invalid_argument("Unknown server type "+server_type);
}
}
@@ -591,7 +557,7 @@
} else if (protocol_type == "compact") {
} else if (protocol_type == "json") {
} else {
- throw invalid_argument("Unknown protocol type " + protocol_type);
+ throw invalid_argument("Unknown protocol type "+protocol_type);
}
}
@@ -600,7 +566,7 @@
} else if (transport_type == "framed") {
} else if (transport_type == "http") {
} else {
- throw invalid_argument("Unknown transport type " + transport_type);
+ throw invalid_argument("Unknown transport type "+transport_type);
}
}
@@ -623,8 +589,7 @@
boost::shared_ptr<TProtocolFactory> compactProtocolFactory(new TCompactProtocolFactory());
protocolFactory = compactProtocolFactory;
} else {
- boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(
- new TBinaryProtocolFactoryT<TBufferBase>());
+ boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(new TBinaryProtocolFactoryT<TBufferBase>());
protocolFactory = binaryProtocolFactory;
}
@@ -633,8 +598,8 @@
boost::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
if (vm.count("processor-events")) {
- testProcessor->setEventHandler(
- boost::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler()));
+ testProcessor->setEventHandler(boost::shared_ptr<TProcessorEventHandler>(
+ new TestProcessorEventHandler()));
}
// Transport
@@ -672,8 +637,8 @@
}
// Server Info
- cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type
- << ") listen on: " << domain_socket;
+ cout << "Starting \"" << server_type << "\" server ("
+ << transport_type << "/" << protocol_type << ") listen on: " << domain_socket;
if (port != 0) {
cout << port;
}
@@ -683,13 +648,17 @@
boost::shared_ptr<apache::thrift::server::TServer> server;
if (server_type == "simple") {
- server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory));
+ server.reset(new TSimpleServer(testProcessor,
+ serverSocket,
+ transportFactory,
+ protocolFactory));
} else if (server_type == "thread-pool") {
- boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers);
+ boost::shared_ptr<ThreadManager> threadManager =
+ ThreadManager::newSimpleThreadManager(workers);
- boost::shared_ptr<PlatformThreadFactory> threadFactory
- = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
+ boost::shared_ptr<PlatformThreadFactory> threadFactory =
+ boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
threadManager->threadFactory(threadFactory);
@@ -702,15 +671,15 @@
threadManager));
} else if (server_type == "threaded") {
- server.reset(
- new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory));
+ server.reset(new TThreadedServer(testProcessor,
+ serverSocket,
+ transportFactory,
+ protocolFactory));
} else if (server_type == "nonblocking") {
- if (transport_type == "http") {
+ if(transport_type == "http") {
boost::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler));
- boost::shared_ptr<TAsyncProcessor> testProcessorAsync(
- new ThriftTestAsyncProcessor(testHandlerAsync));
- boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(
- new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
+ boost::shared_ptr<TAsyncProcessor> testProcessorAsync(new ThriftTestAsyncProcessor(testHandlerAsync));
+ boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
// not loading nonblockingServer into "server" because
// TEvhttpServer doesn't inherit from TServer, and doesn't
@@ -722,18 +691,17 @@
}
}
- if (server.get() != NULL) {
+ if(server.get() != NULL)
+ {
apache::thrift::concurrency::PlatformThreadFactory factory;
factory.setDetached(false);
boost::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
- boost::shared_ptr<apache::thrift::concurrency::Thread> thread
- = factory.newThread(serverThreadRunner);
+ boost::shared_ptr<apache::thrift::concurrency::Thread> thread = factory.newThread(serverThreadRunner);
thread->start();
// HACK: cross language test suite is unable to handle cin properly
// that's why we stay in a endless loop here
- while (1) {
- }
+ while(1){}
// FIXME: find another way to stop the server (e.g. a signal)
// cout<<"Press enter to stop the server."<<endl;
// cin.ignore(); //wait until a key is pressed
diff --git a/test/cpp/src/ThriftTest_extras.cpp b/test/cpp/src/ThriftTest_extras.cpp
index af5606e..33f681f 100644
--- a/test/cpp/src/ThriftTest_extras.cpp
+++ b/test/cpp/src/ThriftTest_extras.cpp
@@ -22,12 +22,12 @@
#include <thrift/protocol/TDebugProtocol.h>
#include "gen-cpp/ThriftTest_types.h"
-namespace thrift {
-namespace test {
+
+namespace thrift { namespace test {
bool Insanity::operator<(thrift::test::Insanity const& other) const {
using apache::thrift::ThriftDebugString;
return ThriftDebugString(*this) < ThriftDebugString(other);
}
-}
-}
+
+}}