Revert "THRIFT-2729: C++ - .clang-format created and applied"
This reverts commit 74260aa9099c3bb209bc8e524b0e8ba603f62c41.
diff --git a/lib/cpp/test/processor/EventLog.cpp b/lib/cpp/test/processor/EventLog.cpp
index d4b8372..0ac3028 100644
--- a/lib/cpp/test/processor/EventLog.cpp
+++ b/lib/cpp/test/processor/EventLog.cpp
@@ -36,11 +36,10 @@
fprintf(stderr, "\n");
}
+
}
-namespace apache {
-namespace thrift {
-namespace test {
+namespace apache { namespace thrift { namespace test {
uint32_t EventLog::nextId_ = 0;
@@ -75,12 +74,11 @@
debug("New log: %d", id_);
}
-void EventLog::append(EventType type,
- uint32_t connectionId,
- uint32_t callId,
+void EventLog::append(EventType type, uint32_t connectionId, uint32_t callId,
const string& message) {
Synchronized s(monitor_);
- debug("%d <-- %u, %u, %s \"%s\"", id_, connectionId, callId, type, message.c_str());
+ debug("%d <-- %u, %u, %s \"%s\"", id_, connectionId, callId, type,
+ message.c_str());
Event e(type, connectionId, callId, message);
events_.push_back(e);
@@ -127,6 +125,5 @@
}
}
}
-}
-}
-} // apache::thrift::test
+
+}}} // apache::thrift::test
diff --git a/lib/cpp/test/processor/EventLog.h b/lib/cpp/test/processor/EventLog.h
index 4f8275d..d731cec 100644
--- a/lib/cpp/test/processor/EventLog.h
+++ b/lib/cpp/test/processor/EventLog.h
@@ -21,9 +21,7 @@
#include <thrift/concurrency/Monitor.h>
-namespace apache {
-namespace thrift {
-namespace test {
+namespace apache { namespace thrift { namespace test {
// Initially I made EventType an enum, but using char* results
// in much more readable error messages when there is a mismatch.
@@ -33,17 +31,21 @@
typedef const char* EventType;
struct Event {
- Event(EventType type, uint32_t connectionId, uint32_t callId, const std::string& message)
- : type(type), connectionId(connectionId), callId(callId), message(message) {}
+ Event(EventType type, uint32_t connectionId, uint32_t callId,
+ const std::string& message) :
+ type(type),
+ connectionId(connectionId),
+ callId(callId),
+ message(message) {}
EventType type;
- uint32_t connectionId;
- uint32_t callId;
- std::string message;
+ uint32_t connectionId;
+ uint32_t callId;
+ std::string message;
};
class EventLog {
-public:
+ public:
static EventType ET_LOG_END;
static EventType ET_CONN_CREATED;
static EventType ET_CONN_DESTROYED;
@@ -71,15 +73,13 @@
EventLog();
- void append(EventType type,
- uint32_t connectionId,
- uint32_t callId,
+ void append(EventType type, uint32_t connectionId, uint32_t callId,
const std::string& message = "");
Event waitForEvent(int64_t timeout = 500);
Event waitForConnEvent(uint32_t connId, int64_t timeout = 500);
-protected:
+ protected:
typedef std::list<Event> EventList;
concurrency::Monitor monitor_;
@@ -88,8 +88,7 @@
static uint32_t nextId_;
};
-}
-}
-} // apache::thrift::test
+
+}}} // apache::thrift::test
#endif // _THRIFT_TEST_EVENTLOG_H_
diff --git a/lib/cpp/test/processor/Handlers.h b/lib/cpp/test/processor/Handlers.h
index d894107..75f4349 100644
--- a/lib/cpp/test/processor/Handlers.h
+++ b/lib/cpp/test/processor/Handlers.h
@@ -23,14 +23,15 @@
#include "gen-cpp/ParentService.h"
#include "gen-cpp/ChildService.h"
-namespace apache {
-namespace thrift {
-namespace test {
+namespace apache { namespace thrift { namespace test {
class ParentHandler : virtual public ParentServiceIf {
-public:
- ParentHandler(const boost::shared_ptr<EventLog>& log)
- : triggerMonitor(&mutex_), generation_(0), wait_(false), log_(log) {}
+ public:
+ ParentHandler(const boost::shared_ptr<EventLog>& log) :
+ triggerMonitor(&mutex_),
+ generation_(0),
+ wait_(false),
+ log_(log) { }
int32_t incrementGeneration() {
concurrency::Guard g(mutex_);
@@ -115,7 +116,7 @@
triggerMonitor.notifyAll();
}
-protected:
+ protected:
/**
* blockUntilTriggered() won't return until triggerPendingCalls() is invoked
* in another thread.
@@ -140,8 +141,10 @@
};
class ChildHandler : public ParentHandler, virtual public ChildServiceIf {
-public:
- ChildHandler(const boost::shared_ptr<EventLog>& log) : ParentHandler(log), value_(0) {}
+ public:
+ ChildHandler(const boost::shared_ptr<EventLog>& log) :
+ ParentHandler(log),
+ value_(0) {}
int32_t setValue(int32_t value) {
concurrency::Guard g(mutex_);
@@ -159,16 +162,18 @@
return value_;
}
-protected:
+ protected:
int32_t value_;
};
struct ConnContext {
-public:
+ public:
ConnContext(boost::shared_ptr<protocol::TProtocol> in,
boost::shared_ptr<protocol::TProtocol> out,
- uint32_t id)
- : input(in), output(out), id(id) {}
+ uint32_t id) :
+ input(in),
+ output(out),
+ id(id) {}
boost::shared_ptr<protocol::TProtocol> input;
boost::shared_ptr<protocol::TProtocol> output;
@@ -176,18 +181,22 @@
};
struct CallContext {
-public:
- CallContext(ConnContext* context, uint32_t id, const std::string& name)
- : connContext(context), name(name), id(id) {}
+ public:
+ CallContext(ConnContext *context, uint32_t id, const std::string& name) :
+ connContext(context),
+ name(name),
+ id(id) {}
- ConnContext* connContext;
+ ConnContext *connContext;
std::string name;
uint32_t id;
};
class ServerEventHandler : public server::TServerEventHandler {
-public:
- ServerEventHandler(const boost::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
+ public:
+ ServerEventHandler(const boost::shared_ptr<EventLog>& log) :
+ nextId_(1),
+ log_(log) {}
virtual void preServe() {}
@@ -200,8 +209,8 @@
}
virtual void deleteContext(void* serverContext,
- boost::shared_ptr<protocol::TProtocol> input,
- boost::shared_ptr<protocol::TProtocol> output) {
+ boost::shared_ptr<protocol::TProtocol>input,
+ boost::shared_ptr<protocol::TProtocol>output) {
ConnContext* context = reinterpret_cast<ConnContext*>(serverContext);
if (input != context->input) {
@@ -216,21 +225,22 @@
delete context;
}
- virtual void processContext(void* serverContext,
- boost::shared_ptr<transport::TTransport> transport) {
-// TODO: We currently don't test the behavior of the processContext()
-// calls. The various server implementations call processContext() at
-// slightly different times, and it is too annoying to try and account for
-// their various differences.
-//
-// TThreadedServer, TThreadPoolServer, and TSimpleServer usually wait until
-// they see the first byte of a request before calling processContext().
-// However, they don't wait for the first byte of the very first request,
-// and instead immediately call processContext() before any data is
-// received.
-//
-// TNonblockingServer always waits until receiving the full request before
-// calling processContext().
+ virtual void processContext(
+ void* serverContext,
+ boost::shared_ptr<transport::TTransport> transport) {
+ // TODO: We currently don't test the behavior of the processContext()
+ // calls. The various server implementations call processContext() at
+ // slightly different times, and it is too annoying to try and account for
+ // their various differences.
+ //
+ // TThreadedServer, TThreadPoolServer, and TSimpleServer usually wait until
+ // they see the first byte of a request before calling processContext().
+ // However, they don't wait for the first byte of the very first request,
+ // and instead immediately call processContext() before any data is
+ // received.
+ //
+ // TNonblockingServer always waits until receiving the full request before
+ // calling processContext().
#if 0
ConnContext* context = reinterpret_cast<ConnContext*>(serverContext);
log_->append(EventLog::ET_PROCESS, context->id, 0);
@@ -240,14 +250,16 @@
#endif
}
-protected:
+ protected:
uint32_t nextId_;
boost::shared_ptr<EventLog> log_;
};
class ProcessorEventHandler : public TProcessorEventHandler {
-public:
- ProcessorEventHandler(const boost::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
+ public:
+ ProcessorEventHandler(const boost::shared_ptr<EventLog>& log) :
+ nextId_(1),
+ log_(log) {}
void* getContext(const char* fnName, void* serverContext) {
ConnContext* connContext = reinterpret_cast<ConnContext*>(serverContext);
@@ -255,65 +267,71 @@
CallContext* context = new CallContext(connContext, nextId_, fnName);
++nextId_;
- log_->append(EventLog::ET_CALL_STARTED, connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_CALL_STARTED, connContext->id, context->id,
+ fnName);
return context;
}
void freeContext(void* ctx, const char* fnName) {
CallContext* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
- log_->append(EventLog::ET_CALL_FINISHED, context->connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_CALL_FINISHED, context->connContext->id,
+ context->id, fnName);
delete context;
}
void preRead(void* ctx, const char* fnName) {
CallContext* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
- log_->append(EventLog::ET_PRE_READ, context->connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_PRE_READ, context->connContext->id, context->id,
+ fnName);
}
void postRead(void* ctx, const char* fnName, uint32_t bytes) {
THRIFT_UNUSED_VARIABLE(bytes);
CallContext* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
- log_->append(EventLog::ET_POST_READ, context->connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_POST_READ, context->connContext->id, context->id,
+ fnName);
}
void preWrite(void* ctx, const char* fnName) {
CallContext* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
- log_->append(EventLog::ET_PRE_WRITE, context->connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_PRE_WRITE, context->connContext->id, context->id,
+ fnName);
}
void postWrite(void* ctx, const char* fnName, uint32_t bytes) {
THRIFT_UNUSED_VARIABLE(bytes);
CallContext* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
- log_->append(EventLog::ET_POST_WRITE, context->connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_POST_WRITE, context->connContext->id,
+ context->id, fnName);
}
void asyncComplete(void* ctx, const char* fnName) {
CallContext* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
- log_->append(EventLog::ET_ASYNC_COMPLETE, context->connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_ASYNC_COMPLETE, context->connContext->id,
+ context->id, fnName);
}
void handlerError(void* ctx, const char* fnName) {
CallContext* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
- log_->append(EventLog::ET_HANDLER_ERROR, context->connContext->id, context->id, fnName);
+ log_->append(EventLog::ET_HANDLER_ERROR, context->connContext->id,
+ context->id, fnName);
}
-protected:
+ protected:
void checkName(const CallContext* context, const char* fnName) {
// Note: we can't use BOOST_CHECK_EQUAL here, since the handler runs in a
// different thread from the test functions. Just abort if the names are
// different
if (context->name != fnName) {
- fprintf(stderr,
- "call context name mismatch: \"%s\" != \"%s\"\n",
- context->name.c_str(),
- fnName);
+ fprintf(stderr, "call context name mismatch: \"%s\" != \"%s\"\n",
+ context->name.c_str(), fnName);
fflush(stderr);
abort();
}
@@ -322,8 +340,7 @@
uint32_t nextId_;
boost::shared_ptr<EventLog> log_;
};
-}
-}
-} // apache::thrift::test
+
+}}} // apache::thrift::test
#endif // _THRIFT_PROCESSOR_TEST_HANDLERS_H_
diff --git a/lib/cpp/test/processor/ProcessorTest.cpp b/lib/cpp/test/processor/ProcessorTest.cpp
index 300b729..eee90c7 100644
--- a/lib/cpp/test/processor/ProcessorTest.cpp
+++ b/lib/cpp/test/processor/ProcessorTest.cpp
@@ -54,7 +54,7 @@
*/
class TSimpleServerTraits {
-public:
+ public:
typedef TSimpleServer ServerType;
boost::shared_ptr<TSimpleServer> createServer(
@@ -63,13 +63,13 @@
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 @@
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,17 +95,19 @@
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(
@@ -116,24 +118,25 @@
// 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(
@@ -144,16 +147,16 @@
// 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));
}
};
@@ -170,7 +173,7 @@
*/
class UntemplatedTraits {
-public:
+ public:
typedef TBinaryProtocolFactory ProtocolFactory;
typedef TBinaryProtocol Protocol;
@@ -181,7 +184,7 @@
};
class TemplatedTraits {
-public:
+ public:
typedef TBinaryProtocolFactoryT<TBufferBase> ProtocolFactory;
typedef TBinaryProtocolT<TBufferBase> Protocol;
@@ -191,9 +194,10 @@
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;
@@ -202,9 +206,9 @@
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;
@@ -220,18 +224,17 @@
// 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_)),
@@ -244,18 +247,29 @@
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;
@@ -269,7 +283,7 @@
return client;
}
-private:
+ private:
uint16_t port_;
boost::shared_ptr<EventLog> log_;
boost::shared_ptr<Handler> handler_;
@@ -280,6 +294,7 @@
boost::shared_ptr<TProcessorEventHandler> processorEventHandler_;
};
+
/**
* Check that there are no more events in the log
*/
@@ -421,7 +436,7 @@
* 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();
@@ -443,7 +458,7 @@
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();
@@ -461,9 +476,10 @@
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);
@@ -472,9 +488,10 @@
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);
@@ -488,16 +505,15 @@
* 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);
@@ -546,7 +562,7 @@
// 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();
@@ -628,9 +644,10 @@
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);
@@ -656,19 +673,20 @@
// 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
@@ -676,9 +694,10 @@
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);
@@ -696,7 +715,9 @@
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);
@@ -728,9 +749,10 @@
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);
@@ -747,7 +769,9 @@
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);
@@ -780,9 +804,10 @@
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);
@@ -799,8 +824,8 @@
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);
@@ -846,46 +871,47 @@
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)
diff --git a/lib/cpp/test/processor/ServerThread.cpp b/lib/cpp/test/processor/ServerThread.cpp
index aa6fd7f..9f2087c 100644
--- a/lib/cpp/test/processor/ServerThread.cpp
+++ b/lib/cpp/test/processor/ServerThread.cpp
@@ -27,9 +27,7 @@
#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_);
@@ -50,8 +48,9 @@
}
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");
}
}
@@ -128,8 +127,8 @@
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
@@ -143,8 +142,7 @@
serverEventHandler->preServe();
}
}
-}
-}
-} // apache::thrift::test
+
+}}} // apache::thrift::test
#endif // _THRIFT_TEST_SERVERTHREAD_TCC_
diff --git a/lib/cpp/test/processor/ServerThread.h b/lib/cpp/test/processor/ServerThread.h
index eed3469..f7fa0d5 100644
--- a/lib/cpp/test/processor/ServerThread.h
+++ b/lib/cpp/test/processor/ServerThread.h
@@ -26,15 +26,13 @@
#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() {}
/**
@@ -52,7 +50,8 @@
* 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>();
}
@@ -62,16 +61,17 @@
* 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,7 +85,9 @@
void start();
void stop();
- uint16_t getPort() const { return port_; }
+ uint16_t getPort() const {
+ return port_;
+ }
~ServerThread() {
if (running_) {
@@ -97,20 +99,26 @@
}
}
-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) {}
+ class Helper : public concurrency::Runnable,
+ public server::TServerEventHandler {
+ public:
+ Helper(ServerThread* serverThread)
+ : serverThread_(serverThread) {}
- void run() { serverThread_->run(); }
+ void run() {
+ serverThread_->run();
+ }
- void preServe() { serverThread_->preServe(); }
+ void preServe() {
+ serverThread_->preServe();
+ }
- private:
+ private:
ServerThread* serverThread_;
};
@@ -129,8 +137,7 @@
boost::shared_ptr<server::TServer> server_;
boost::shared_ptr<concurrency::Thread> thread_;
};
-}
-}
-} // apache::thrift::test
+
+}}} // apache::thrift::test
#endif // _THRIFT_TEST_SERVERTHREAD_H_