Revert "THRIFT-2729: C++ - .clang-format created and applied"
This reverts commit 74260aa9099c3bb209bc8e524b0e8ba603f62c41.
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;