You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by hc...@apache.org on 2014/11/18 10:02:30 UTC
[02/37] thrift git commit: THRIFT-2729: C++ - .clang-format created
and applied
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/test/processor/ProcessorTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/processor/ProcessorTest.cpp b/lib/cpp/test/processor/ProcessorTest.cpp
index eee90c7..300b729 100644
--- a/lib/cpp/test/processor/ProcessorTest.cpp
+++ b/lib/cpp/test/processor/ProcessorTest.cpp
@@ -54,7 +54,7 @@ using namespace apache::thrift::test;
*/
class TSimpleServerTraits {
- public:
+public:
typedef TSimpleServer ServerType;
boost::shared_ptr<TSimpleServer> createServer(
@@ -63,13 +63,13 @@ class TSimpleServerTraits {
const boost::shared_ptr<TTransportFactory>& transportFactory,
const boost::shared_ptr<TProtocolFactory>& protocolFactory) {
boost::shared_ptr<TServerSocket> socket(new TServerSocket(port));
- return boost::shared_ptr<TSimpleServer>(new TSimpleServer(
- processor, socket, transportFactory, protocolFactory));
+ return boost::shared_ptr<TSimpleServer>(
+ new TSimpleServer(processor, socket, transportFactory, protocolFactory));
}
};
class TThreadedServerTraits {
- public:
+public:
typedef TThreadedServer ServerType;
boost::shared_ptr<TThreadedServer> createServer(
@@ -78,13 +78,13 @@ class TThreadedServerTraits {
const boost::shared_ptr<TTransportFactory>& transportFactory,
const boost::shared_ptr<TProtocolFactory>& protocolFactory) {
boost::shared_ptr<TServerSocket> socket(new TServerSocket(port));
- return boost::shared_ptr<TThreadedServer>(new TThreadedServer(
- processor, socket, transportFactory, protocolFactory));
+ return boost::shared_ptr<TThreadedServer>(
+ new TThreadedServer(processor, socket, transportFactory, protocolFactory));
}
};
class TThreadPoolServerTraits {
- public:
+public:
typedef TThreadPoolServer ServerType;
boost::shared_ptr<TThreadPoolServer> createServer(
@@ -95,19 +95,17 @@ class TThreadPoolServerTraits {
boost::shared_ptr<TServerSocket> socket(new TServerSocket(port));
boost::shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory);
- boost::shared_ptr<ThreadManager> threadManager =
- ThreadManager::newSimpleThreadManager(8);
+ boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8);
threadManager->threadFactory(threadFactory);
threadManager->start();
- return boost::shared_ptr<TThreadPoolServer>(new TThreadPoolServer(
- processor, socket, transportFactory, protocolFactory,
- threadManager));
+ return boost::shared_ptr<TThreadPoolServer>(
+ new TThreadPoolServer(processor, socket, transportFactory, protocolFactory, threadManager));
}
};
class TNonblockingServerTraits {
- public:
+public:
typedef TNonblockingServer ServerType;
boost::shared_ptr<TNonblockingServer> createServer(
@@ -118,25 +116,24 @@ class TNonblockingServerTraits {
// TNonblockingServer automatically uses TFramedTransport.
// Raise an exception if the supplied transport factory is not a
// TFramedTransportFactory
- TFramedTransportFactory* framedFactory =
- dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
+ TFramedTransportFactory* framedFactory
+ = dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
if (framedFactory == NULL) {
throw TException("TNonblockingServer must use TFramedTransport");
}
boost::shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory);
- boost::shared_ptr<ThreadManager> threadManager =
- ThreadManager::newSimpleThreadManager(8);
+ boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8);
threadManager->threadFactory(threadFactory);
threadManager->start();
- return boost::shared_ptr<TNonblockingServer>(new TNonblockingServer(
- processor, protocolFactory, port, threadManager));
+ return boost::shared_ptr<TNonblockingServer>(
+ new TNonblockingServer(processor, protocolFactory, port, threadManager));
}
};
class TNonblockingServerNoThreadsTraits {
- public:
+public:
typedef TNonblockingServer ServerType;
boost::shared_ptr<TNonblockingServer> createServer(
@@ -147,16 +144,16 @@ class TNonblockingServerNoThreadsTraits {
// TNonblockingServer automatically uses TFramedTransport.
// Raise an exception if the supplied transport factory is not a
// TFramedTransportFactory
- TFramedTransportFactory* framedFactory =
- dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
+ TFramedTransportFactory* framedFactory
+ = dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
if (framedFactory == NULL) {
throw TException("TNonblockingServer must use TFramedTransport");
}
// Use a NULL ThreadManager
boost::shared_ptr<ThreadManager> threadManager;
- return boost::shared_ptr<TNonblockingServer>(new TNonblockingServer(
- processor, protocolFactory, port, threadManager));
+ return boost::shared_ptr<TNonblockingServer>(
+ new TNonblockingServer(processor, protocolFactory, port, threadManager));
}
};
@@ -173,7 +170,7 @@ class TNonblockingServerNoThreadsTraits {
*/
class UntemplatedTraits {
- public:
+public:
typedef TBinaryProtocolFactory ProtocolFactory;
typedef TBinaryProtocol Protocol;
@@ -184,7 +181,7 @@ class UntemplatedTraits {
};
class TemplatedTraits {
- public:
+public:
typedef TBinaryProtocolFactoryT<TBufferBase> ProtocolFactory;
typedef TBinaryProtocolT<TBufferBase> Protocol;
@@ -194,10 +191,9 @@ class TemplatedTraits {
typedef ChildServiceClientT<Protocol> ChildClient;
};
-
-template<typename TemplateTraits_>
+template <typename TemplateTraits_>
class ParentServiceTraits {
- public:
+public:
typedef typename TemplateTraits_::ParentProcessor Processor;
typedef typename TemplateTraits_::ParentClient Client;
typedef ParentHandler Handler;
@@ -206,9 +202,9 @@ class ParentServiceTraits {
typedef typename TemplateTraits_::Protocol Protocol;
};
-template<typename TemplateTraits_>
+template <typename TemplateTraits_>
class ChildServiceTraits {
- public:
+public:
typedef typename TemplateTraits_::ChildProcessor Processor;
typedef typename TemplateTraits_::ChildClient Client;
typedef ChildHandler Handler;
@@ -224,17 +220,18 @@ class ChildServiceTraits {
// It would also be niec if they used covariant return types. Unfortunately,
// since they return shared_ptr instead of raw pointers, covariant return types
// won't work.
-template<typename ServerTraits_, typename ServiceTraits_,
- typename TransportFactory_ = TFramedTransportFactory,
- typename Transport_ = TFramedTransport>
+template <typename ServerTraits_,
+ typename ServiceTraits_,
+ typename TransportFactory_ = TFramedTransportFactory,
+ typename Transport_ = TFramedTransport>
class ServiceState : public ServerState {
- public:
+public:
typedef typename ServiceTraits_::Processor Processor;
typedef typename ServiceTraits_::Client Client;
typedef typename ServiceTraits_::Handler Handler;
- ServiceState() :
- port_(0),
+ ServiceState()
+ : port_(0),
log_(new EventLog),
handler_(new Handler(log_)),
processor_(new Processor(handler_)),
@@ -247,29 +244,18 @@ class ServiceState : public ServerState {
boost::shared_ptr<TServer> createServer(uint16_t port) {
ServerTraits_ serverTraits;
- return serverTraits.createServer(processor_, port, transportFactory_,
- protocolFactory_);
+ return serverTraits.createServer(processor_, port, transportFactory_, protocolFactory_);
}
- boost::shared_ptr<TServerEventHandler> getServerEventHandler() {
- return serverEventHandler_;
- }
+ boost::shared_ptr<TServerEventHandler> getServerEventHandler() { return serverEventHandler_; }
- void bindSuccessful(uint16_t port) {
- port_ = port;
- }
+ void bindSuccessful(uint16_t port) { port_ = port; }
- uint16_t getPort() const {
- return port_;
- }
+ uint16_t getPort() const { return port_; }
- const boost::shared_ptr<EventLog>& getLog() const {
- return log_;
- }
+ const boost::shared_ptr<EventLog>& getLog() const { return log_; }
- const boost::shared_ptr<Handler>& getHandler() const {
- return handler_;
- }
+ const boost::shared_ptr<Handler>& getHandler() const { return handler_; }
boost::shared_ptr<Client> createClient() {
typedef typename ServiceTraits_::Protocol Protocol;
@@ -283,7 +269,7 @@ class ServiceState : public ServerState {
return client;
}
- private:
+private:
uint16_t port_;
boost::shared_ptr<EventLog> log_;
boost::shared_ptr<Handler> handler_;
@@ -294,7 +280,6 @@ class ServiceState : public ServerState {
boost::shared_ptr<TProcessorEventHandler> processorEventHandler_;
};
-
/**
* Check that there are no more events in the log
*/
@@ -436,7 +421,7 @@ uint32_t checkCallEvents(const boost::shared_ptr<EventLog>& log,
* Test functions
*/
-template<typename State_>
+template <typename State_>
void testParentService(const boost::shared_ptr<State_>& state) {
boost::shared_ptr<typename State_::Client> client = state->createClient();
@@ -458,7 +443,7 @@ void testParentService(const boost::shared_ptr<State_>& state) {
BOOST_REQUIRE_EQUAL("asdf", strings[2]);
}
-template<typename State_>
+template <typename State_>
void testChildService(const boost::shared_ptr<State_>& state) {
boost::shared_ptr<typename State_::Client> client = state->createClient();
@@ -476,10 +461,9 @@ void testChildService(const boost::shared_ptr<State_>& state) {
BOOST_CHECK_EQUAL(99, client->getValue());
}
-template<typename ServerTraits, typename TemplateTraits>
+template <typename ServerTraits, typename TemplateTraits>
void testBasicService() {
- typedef ServiceState< ServerTraits, ParentServiceTraits<TemplateTraits> >
- State;
+ typedef ServiceState<ServerTraits, ParentServiceTraits<TemplateTraits> > State;
// Start the server
boost::shared_ptr<State> state(new State);
@@ -488,10 +472,9 @@ void testBasicService() {
testParentService(state);
}
-template<typename ServerTraits, typename TemplateTraits>
+template <typename ServerTraits, typename TemplateTraits>
void testInheritedService() {
- typedef ServiceState< ServerTraits, ChildServiceTraits<TemplateTraits> >
- State;
+ typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
// Start the server
boost::shared_ptr<State> state(new State);
@@ -505,15 +488,16 @@ void testInheritedService() {
* Test to make sure that the TServerEventHandler and TProcessorEventHandler
* methods are invoked in the correct order with the actual events.
*/
-template<typename ServerTraits, typename TemplateTraits>
+template <typename ServerTraits, typename TemplateTraits>
void testEventSequencing() {
// We use TBufferedTransport for this test, instead of TFramedTransport.
// This way the server will start processing data as soon as it is received,
// instead of waiting for the full request. This is necessary so we can
// separate the preRead() and postRead() events.
- typedef ServiceState< ServerTraits, ChildServiceTraits<TemplateTraits>,
- TBufferedTransportFactory, TBufferedTransport>
- State;
+ typedef ServiceState<ServerTraits,
+ ChildServiceTraits<TemplateTraits>,
+ TBufferedTransportFactory,
+ TBufferedTransport> State;
// Start the server
boost::shared_ptr<State> state(new State);
@@ -562,7 +546,7 @@ void testEventSequencing() {
// Send the rest of the request
protocol.writeStructBegin("ParentService_getDataNotified_pargs");
protocol.writeFieldBegin("length", apache::thrift::protocol::T_I32, 1);
- protocol.writeI32(8*1024*1024);
+ protocol.writeI32(8 * 1024 * 1024);
protocol.writeFieldEnd();
protocol.writeFieldStop();
protocol.writeStructEnd();
@@ -644,10 +628,9 @@ void testEventSequencing() {
checkNoEvents(log);
}
-template<typename ServerTraits, typename TemplateTraits>
+template <typename ServerTraits, typename TemplateTraits>
void testSeparateConnections() {
- typedef ServiceState< ServerTraits, ChildServiceTraits<TemplateTraits> >
- State;
+ typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
// Start the server
boost::shared_ptr<State> state(new State);
@@ -673,20 +656,19 @@ void testSeparateConnections() {
// Make a call, and check for the proper events
int32_t value = 5;
client1->setValue(value);
- uint32_t call1 = checkCallEvents(log, client1Id, EventLog::ET_CALL_SET_VALUE,
- "ChildService.setValue");
+ uint32_t call1
+ = checkCallEvents(log, client1Id, EventLog::ET_CALL_SET_VALUE, "ChildService.setValue");
// Make a call with client2
int32_t v = client2->getValue();
BOOST_CHECK_EQUAL(value, v);
- checkCallEvents(log, client2Id, EventLog::ET_CALL_GET_VALUE,
- "ChildService.getValue");
+ checkCallEvents(log, client2Id, EventLog::ET_CALL_GET_VALUE, "ChildService.getValue");
// Make another call with client1
v = client1->getValue();
BOOST_CHECK_EQUAL(value, v);
- uint32_t call2 = checkCallEvents(log, client1Id, EventLog::ET_CALL_GET_VALUE,
- "ChildService.getValue");
+ uint32_t call2
+ = checkCallEvents(log, client1Id, EventLog::ET_CALL_GET_VALUE, "ChildService.getValue");
BOOST_CHECK_NE(call1, call2);
// Close the second client, and check for the appropriate events
@@ -694,10 +676,9 @@ void testSeparateConnections() {
checkCloseEvents(log, client2Id);
}
-template<typename ServerTraits, typename TemplateTraits>
+template <typename ServerTraits, typename TemplateTraits>
void testOnewayCall() {
- typedef ServiceState< ServerTraits, ChildServiceTraits<TemplateTraits> >
- State;
+ typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
// Start the server
boost::shared_ptr<State> state(new State);
@@ -715,9 +696,7 @@ void testOnewayCall() {
state->getHandler()->prepareTriggeredCall();
client->onewayWait();
string callName = "ParentService.onewayWait";
- uint32_t callId = checkCallHandlerEvents(log, connId,
- EventLog::ET_CALL_ONEWAY_WAIT,
- callName);
+ uint32_t callId = checkCallHandlerEvents(log, connId, EventLog::ET_CALL_ONEWAY_WAIT, callName);
// There shouldn't be any more events
checkNoEvents(log);
@@ -749,10 +728,9 @@ void testOnewayCall() {
checkNoEvents(log);
}
-template<typename ServerTraits, typename TemplateTraits>
+template <typename ServerTraits, typename TemplateTraits>
void testExpectedError() {
- typedef ServiceState< ServerTraits, ChildServiceTraits<TemplateTraits> >
- State;
+ typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
// Start the server
boost::shared_ptr<State> state(new State);
@@ -769,9 +747,7 @@ void testExpectedError() {
string message = "test 1234 test";
client->send_exceptionWait(message);
string callName = "ParentService.exceptionWait";
- uint32_t callId = checkCallHandlerEvents(log, connId,
- EventLog::ET_CALL_EXCEPTION_WAIT,
- callName);
+ uint32_t callId = checkCallHandlerEvents(log, connId, EventLog::ET_CALL_EXCEPTION_WAIT, callName);
// There shouldn't be any more events
checkNoEvents(log);
@@ -804,10 +780,9 @@ void testExpectedError() {
checkNoEvents(log);
}
-template<typename ServerTraits, typename TemplateTraits>
+template <typename ServerTraits, typename TemplateTraits>
void testUnexpectedError() {
- typedef ServiceState< ServerTraits, ChildServiceTraits<TemplateTraits> >
- State;
+ typedef ServiceState<ServerTraits, ChildServiceTraits<TemplateTraits> > State;
// Start the server
boost::shared_ptr<State> state(new State);
@@ -824,8 +799,8 @@ void testUnexpectedError() {
string message = "1234 test 5678";
client->send_unexpectedExceptionWait(message);
string callName = "ParentService.unexpectedExceptionWait";
- uint32_t callId = checkCallHandlerEvents(
- log, connId, EventLog::ET_CALL_UNEXPECTED_EXCEPTION_WAIT, callName);
+ uint32_t callId
+ = checkCallHandlerEvents(log, connId, EventLog::ET_CALL_UNEXPECTED_EXCEPTION_WAIT, callName);
// There shouldn't be any more events
checkNoEvents(log);
@@ -871,47 +846,46 @@ void testUnexpectedError() {
checkNoEvents(log);
}
-
// Macro to define simple tests that can be used with all server types
-#define DEFINE_SIMPLE_TESTS(Server, Template) \
- BOOST_AUTO_TEST_CASE(Server##_##Template##_basicService) { \
- testBasicService<Server##Traits, Template##Traits>(); \
- } \
- BOOST_AUTO_TEST_CASE(Server##_##Template##_inheritedService) { \
- testInheritedService<Server##Traits, Template##Traits>(); \
- } \
- BOOST_AUTO_TEST_CASE(Server##_##Template##_oneway) { \
- testOnewayCall<Server##Traits, Template##Traits>(); \
- } \
- BOOST_AUTO_TEST_CASE(Server##_##Template##_exception) { \
- testExpectedError<Server##Traits, Template##Traits>(); \
- } \
- BOOST_AUTO_TEST_CASE(Server##_##Template##_unexpectedException) { \
- testUnexpectedError<Server##Traits, Template##Traits>(); \
+#define DEFINE_SIMPLE_TESTS(Server, Template) \
+ BOOST_AUTO_TEST_CASE(Server##_##Template##_basicService) { \
+ testBasicService<Server##Traits, Template##Traits>(); \
+ } \
+ BOOST_AUTO_TEST_CASE(Server##_##Template##_inheritedService) { \
+ testInheritedService<Server##Traits, Template##Traits>(); \
+ } \
+ BOOST_AUTO_TEST_CASE(Server##_##Template##_oneway) { \
+ testOnewayCall<Server##Traits, Template##Traits>(); \
+ } \
+ BOOST_AUTO_TEST_CASE(Server##_##Template##_exception) { \
+ testExpectedError<Server##Traits, Template##Traits>(); \
+ } \
+ BOOST_AUTO_TEST_CASE(Server##_##Template##_unexpectedException) { \
+ testUnexpectedError<Server##Traits, Template##Traits>(); \
}
// Tests that require the server to process multiple connections concurrently
// (i.e., not TSimpleServer)
-#define DEFINE_CONCURRENT_SERVER_TESTS(Server, Template) \
- BOOST_AUTO_TEST_CASE(Server##_##Template##_separateConnections) { \
- testSeparateConnections<Server##Traits, Template##Traits>(); \
+#define DEFINE_CONCURRENT_SERVER_TESTS(Server, Template) \
+ BOOST_AUTO_TEST_CASE(Server##_##Template##_separateConnections) { \
+ testSeparateConnections<Server##Traits, Template##Traits>(); \
}
// The testEventSequencing() test manually generates a request for the server,
// and doesn't work with TFramedTransport. Therefore we can't test it with
// TNonblockingServer.
-#define DEFINE_NOFRAME_TESTS(Server, Template) \
- BOOST_AUTO_TEST_CASE(Server##_##Template##_eventSequencing) { \
- testEventSequencing<Server##Traits, Template##Traits>(); \
+#define DEFINE_NOFRAME_TESTS(Server, Template) \
+ BOOST_AUTO_TEST_CASE(Server##_##Template##_eventSequencing) { \
+ testEventSequencing<Server##Traits, Template##Traits>(); \
}
-#define DEFINE_TNONBLOCKINGSERVER_TESTS(Server, Template) \
- DEFINE_SIMPLE_TESTS(Server, Template) \
+#define DEFINE_TNONBLOCKINGSERVER_TESTS(Server, Template) \
+ DEFINE_SIMPLE_TESTS(Server, Template) \
DEFINE_CONCURRENT_SERVER_TESTS(Server, Template)
-#define DEFINE_ALL_SERVER_TESTS(Server, Template) \
- DEFINE_SIMPLE_TESTS(Server, Template) \
- DEFINE_CONCURRENT_SERVER_TESTS(Server, Template) \
+#define DEFINE_ALL_SERVER_TESTS(Server, Template) \
+ DEFINE_SIMPLE_TESTS(Server, Template) \
+ DEFINE_CONCURRENT_SERVER_TESTS(Server, Template) \
DEFINE_NOFRAME_TESTS(Server, Template)
DEFINE_ALL_SERVER_TESTS(TThreadedServer, Templated)
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/test/processor/ServerThread.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/processor/ServerThread.cpp b/lib/cpp/test/processor/ServerThread.cpp
index 9f2087c..aa6fd7f 100644
--- a/lib/cpp/test/processor/ServerThread.cpp
+++ b/lib/cpp/test/processor/ServerThread.cpp
@@ -27,7 +27,9 @@
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TServerSocket.h>
-namespace apache { namespace thrift { namespace test {
+namespace apache {
+namespace thrift {
+namespace test {
void ServerThread::start() {
assert(!running_);
@@ -48,9 +50,8 @@ void ServerThread::start() {
}
if (error_) {
- throw transport::TTransportException(
- transport::TTransportException::NOT_OPEN,
- "failed to bind on server socket");
+ throw transport::TTransportException(transport::TTransportException::NOT_OPEN,
+ "failed to bind on server socket");
}
}
@@ -127,8 +128,8 @@ void ServerThread::preServe() {
serverState_->bindSuccessful(port_);
// Set the real server event handler (replacing ourself)
- boost::shared_ptr<server::TServerEventHandler> serverEventHandler =
- serverState_->getServerEventHandler();
+ boost::shared_ptr<server::TServerEventHandler> serverEventHandler
+ = serverState_->getServerEventHandler();
server_->setServerEventHandler(serverEventHandler);
// Notify the main thread that we have successfully started serving requests
@@ -142,7 +143,8 @@ void ServerThread::preServe() {
serverEventHandler->preServe();
}
}
-
-}}} // apache::thrift::test
+}
+}
+} // apache::thrift::test
#endif // _THRIFT_TEST_SERVERTHREAD_TCC_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/test/processor/ServerThread.h
----------------------------------------------------------------------
diff --git a/lib/cpp/test/processor/ServerThread.h b/lib/cpp/test/processor/ServerThread.h
index f7fa0d5..eed3469 100644
--- a/lib/cpp/test/processor/ServerThread.h
+++ b/lib/cpp/test/processor/ServerThread.h
@@ -26,13 +26,15 @@
#include "EventLog.h"
-namespace apache { namespace thrift { namespace test {
+namespace apache {
+namespace thrift {
+namespace test {
/**
* A helper class to tell ServerThread how to create the server
*/
class ServerState {
- public:
+public:
virtual ~ServerState() {}
/**
@@ -50,8 +52,7 @@ class ServerState {
* start serving traffic. It is invoked from the server thread, rather than
* the main thread.
*/
- virtual boost::shared_ptr<server::TServerEventHandler>
- getServerEventHandler() {
+ virtual boost::shared_ptr<server::TServerEventHandler> getServerEventHandler() {
return boost::shared_ptr<server::TServerEventHandler>();
}
@@ -61,17 +62,16 @@ class ServerState {
* Subclasses may override this method if they wish to record the final
* port that was used for the server.
*/
- virtual void bindSuccessful(uint16_t /*port*/) {
- }
+ virtual void bindSuccessful(uint16_t /*port*/) {}
};
/**
* ServerThread starts a thrift server running in a separate thread.
*/
class ServerThread {
- public:
- ServerThread(const boost::shared_ptr<ServerState>& state, bool autoStart) :
- helper_(new Helper(this)),
+public:
+ ServerThread(const boost::shared_ptr<ServerState>& state, bool autoStart)
+ : helper_(new Helper(this)),
port_(0),
running_(false),
serving_(false),
@@ -85,9 +85,7 @@ class ServerThread {
void start();
void stop();
- uint16_t getPort() const {
- return port_;
- }
+ uint16_t getPort() const { return port_; }
~ServerThread() {
if (running_) {
@@ -99,26 +97,20 @@ class ServerThread {
}
}
- protected:
+protected:
// Annoying. thrift forces us to use shared_ptr, so we have to use
// a helper class that we can allocate on the heap and give to thrift.
// It would be simpler if we could just make Runnable and TServerEventHandler
// private base classes of ServerThread.
- class Helper : public concurrency::Runnable,
- public server::TServerEventHandler {
- public:
- Helper(ServerThread* serverThread)
- : serverThread_(serverThread) {}
-
- void run() {
- serverThread_->run();
- }
+ class Helper : public concurrency::Runnable, public server::TServerEventHandler {
+ public:
+ Helper(ServerThread* serverThread) : serverThread_(serverThread) {}
- void preServe() {
- serverThread_->preServe();
- }
+ void run() { serverThread_->run(); }
+
+ void preServe() { serverThread_->preServe(); }
- private:
+ private:
ServerThread* serverThread_;
};
@@ -137,7 +129,8 @@ class ServerThread {
boost::shared_ptr<server::TServer> server_;
boost::shared_ptr<concurrency::Thread> thread_;
};
-
-}}} // apache::thrift::test
+}
+}
+} // apache::thrift::test
#endif // _THRIFT_TEST_SERVERTHREAD_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/test/cpp/Makefile.am
----------------------------------------------------------------------
diff --git a/test/cpp/Makefile.am b/test/cpp/Makefile.am
index 33e71a3..b072440 100755
--- a/test/cpp/Makefile.am
+++ b/test/cpp/Makefile.am
@@ -104,6 +104,9 @@ AM_LDFLAGS = $(BOOST_LDFLAGS) $(LIBEVENT_LDFLAGS)
clean-local:
$(RM) -r gen-cpp
+style-local:
+ $(CPPSTYLE_CMD)
+
EXTRA_DIST = \
src/TestClient.cpp \
src/TestServer.cpp \
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/test/cpp/src/StressTest.cpp
----------------------------------------------------------------------
diff --git a/test/cpp/src/StressTest.cpp b/test/cpp/src/StressTest.cpp
index dfe8350..fa468a4 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,23 +54,18 @@ using namespace apache::thrift::concurrency;
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,43 +84,46 @@ class Server : public ServiceIf {
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();
}
}
@@ -134,13 +132,25 @@ public:
_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();
@@ -149,7 +159,8 @@ public:
_done = true;
- {Synchronized s(_monitor);
+ {
+ Synchronized s(_monitor);
_workerCount--;
@@ -170,7 +181,7 @@ public:
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);
}
@@ -180,7 +191,7 @@ public:
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);
}
@@ -190,7 +201,7 @@ public:
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);
}
@@ -217,28 +228,26 @@ public:
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
@@ -249,7 +258,7 @@ int main(int argc, char **argv) {
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;
@@ -258,28 +267,34 @@ int main(int argc, char **argv) {
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;
-
-
- map<string, string> args;
+ 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;
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);
@@ -291,7 +306,7 @@ int main(int argc, char **argv) {
args[key] = "true";
}
} else {
- throw invalid_argument("Unexcepted command line token: "+arg);
+ throw invalid_argument("Unexcepted command line token: " + arg);
}
}
@@ -341,7 +356,7 @@ int main(int argc, char **argv) {
} else {
- throw invalid_argument("Unknown server type "+serverType);
+ throw invalid_argument("Unknown server type " + serverType);
}
}
@@ -349,12 +364,13 @@ int main(int argc, char **argv) {
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());
@@ -372,15 +388,12 @@ int main(int argc, char **argv) {
// 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));
@@ -400,27 +413,34 @@ int main(int argc, char **argv) {
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);
@@ -446,12 +466,19 @@ int main(int argc, char **argv) {
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++) {
@@ -460,30 +487,34 @@ int main(int argc, char **argv) {
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;
@@ -493,9 +524,12 @@ int main(int argc, char **argv) {
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;
@@ -517,13 +551,13 @@ int main(int argc, char **argv) {
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;
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/test/cpp/src/StressTestNonBlocking.cpp
----------------------------------------------------------------------
diff --git a/test/cpp/src/StressTestNonBlocking.cpp b/test/cpp/src/StressTestNonBlocking.cpp
index 20320c7..8f161c0 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,23 +57,18 @@ using namespace apache::thrift::concurrency;
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) {
@@ -94,58 +89,73 @@ class Server : public ServiceIf {
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();
@@ -154,7 +164,8 @@ public:
_done = true;
- {Synchronized s(_monitor);
+ {
+ Synchronized s(_monitor);
_workerCount--;
@@ -175,7 +186,7 @@ public:
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);
}
@@ -185,7 +196,7 @@ public:
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);
}
@@ -195,7 +206,7 @@ public:
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);
}
@@ -222,8 +233,7 @@ public:
Monitor _sleep;
};
-
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
#if _WIN32
transport::TWinsockSingleton::create();
#endif
@@ -234,7 +244,7 @@ int main(int argc, char **argv) {
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;
@@ -243,28 +253,34 @@ int main(int argc, char **argv) {
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;
-
-
- map<string, string> args;
+ 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;
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);
@@ -276,7 +292,7 @@ int main(int argc, char **argv) {
args[key] = "true";
}
} else {
- throw invalid_argument("Unexcepted command line token: "+arg);
+ throw invalid_argument("Unexcepted command line token: " + arg);
}
}
@@ -323,12 +339,13 @@ int main(int argc, char **argv) {
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());
@@ -346,15 +363,12 @@ int main(int argc, char **argv) {
// 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));
@@ -363,7 +377,7 @@ int main(int argc, char **argv) {
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
@@ -371,8 +385,8 @@ int main(int argc, char **argv) {
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;
@@ -380,17 +394,22 @@ int main(int argc, char **argv) {
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;
@@ -414,12 +433,19 @@ int main(int argc, char **argv) {
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++) {
@@ -428,30 +454,34 @@ int main(int argc, char **argv) {
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;
@@ -461,9 +491,12 @@ int main(int argc, char **argv) {
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;
@@ -485,13 +518,13 @@ int main(int argc, char **argv) {
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;
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/test/cpp/src/TestClient.cpp
----------------------------------------------------------------------
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
old mode 100755
new mode 100644
index 8c97dc0..a6069de
--- 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,24 +51,27 @@ using namespace apache::thrift::async;
// 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);
@@ -80,7 +83,11 @@ static void testString_clientReturn(const char* host, int port, event_base *base
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;
@@ -89,7 +96,13 @@ static void testVoid_clientReturn(const char* host, int port, event_base *base,
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;
}
@@ -97,7 +110,7 @@ static void testVoid_clientReturn(const char* host, int port, event_base *base,
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
@@ -111,17 +124,26 @@ int main(int argc, char** argv) {
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);
@@ -138,17 +160,17 @@ int main(int argc, char** argv) {
} 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);
}
}
@@ -182,8 +204,7 @@ int main(int argc, char** argv) {
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));
}
}
@@ -191,10 +212,10 @@ int main(int argc, char** argv) {
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;
}
@@ -205,7 +226,7 @@ int main(int argc, char** argv) {
} 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;
}
@@ -218,7 +239,7 @@ int main(int argc, char** argv) {
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
@@ -227,15 +248,20 @@ int main(int argc, char** argv) {
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;
@@ -256,7 +282,7 @@ int main(int argc, char** argv) {
/**
* 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();
@@ -280,7 +306,7 @@ int main(int argc, char** argv) {
testClient.testString(s, "Test");
printf(" = \"%s\"\n", s.c_str());
if (s != "Test")
- failCount++;
+ failCount++;
/**
* BYTE TEST
@@ -289,7 +315,7 @@ int main(int argc, char** argv) {
uint8_t u8 = testClient.testByte(1);
printf(" = %d\n", (int)u8);
if (u8 != 1)
- failCount++;
+ failCount++;
/**
* I32 TEST
@@ -298,7 +324,7 @@ int main(int argc, char** argv) {
int32_t i32 = testClient.testI32(-1);
printf(" = %d\n", i32);
if (i32 != -1)
- failCount++;
+ failCount++;
/**
* I64 TEST
@@ -307,7 +333,7 @@ int main(int argc, char** argv) {
int64_t i64 = testClient.testI64(-34359738368LL);
printf(" = %" PRId64 "\n", i64);
if (i64 != -34359738368LL)
- failCount++;
+ failCount++;
/**
* DOUBLE TEST
*/
@@ -315,7 +341,7 @@ int main(int argc, char** argv) {
double dub = testClient.testDouble(-5.2098523);
printf(" = %f\n", dub);
if ((dub - (-5.2098523)) > 0.001)
- failCount++;
+ failCount++;
/**
* STRUCT TEST
@@ -334,7 +360,7 @@ int main(int argc, char** argv) {
in.i32_thing,
in.i64_thing);
if (in != out)
- failCount++;
+ failCount++;
/**
* NESTED STRUCT TEST
@@ -355,14 +381,14 @@ int main(int argc, char** argv) {
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;
@@ -376,7 +402,7 @@ int main(int argc, char** argv) {
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;
@@ -390,7 +416,7 @@ int main(int argc, char** argv) {
}
printf("}\n");
if (mapin != mapout)
- failCount++;
+ failCount++;
/**
* STRING MAP TEST
@@ -430,7 +456,7 @@ int main(int argc, char** argv) {
}
printf("}\n");
if (setin != setout)
- failCount++;
+ failCount++;
/**
* LIST TEST
@@ -465,7 +491,7 @@ int main(int argc, char** argv) {
}
printf("}\n");
if (listin != listout)
- failCount++;
+ failCount++;
/**
* ENUM TEST
@@ -474,31 +500,31 @@ int main(int argc, char** argv) {
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
@@ -507,7 +533,7 @@ int main(int argc, char** argv) {
UserId uid = testClient.testTypedef(309858235082523LL);
printf(" = %" PRId64 "\n", uid);
if (uid != 309858235082523LL)
- failCount++;
+ failCount++;
/**
* NESTED MAP TEST
@@ -540,16 +566,14 @@ int main(int argc, char** argv) {
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;
@@ -585,25 +609,25 @@ int main(int argc, char** argv) {
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++;
}
@@ -616,7 +640,7 @@ int main(int argc, char** argv) {
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());
}
@@ -627,7 +651,7 @@ int main(int argc, char** argv) {
printf(" result\nFAILURE\n");
failCount++;
- } catch(Xception2& e) {
+ } catch (Xception2& e) {
printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
}
@@ -636,23 +660,23 @@ int main(int argc, char** argv) {
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);
+ }
}
/**
@@ -670,13 +694,12 @@ int main(int argc, char** argv) {
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) {