diff options
-rwxr-xr-x | lib/cpp/test/Makefile.am | 11 | ||||
-rw-r--r-- | lib/cpp/test/processor/ProcessorTest.cpp | 162 | ||||
-rwxr-xr-x | test/cpp/Makefile.am | 2 | ||||
-rwxr-xr-x | tutorial/cpp/Makefile.am | 2 |
4 files changed, 89 insertions, 88 deletions
diff --git a/lib/cpp/test/Makefile.am b/lib/cpp/test/Makefile.am index 4d61e37dd..e404b40d9 100755 --- a/lib/cpp/test/Makefile.am +++ b/lib/cpp/test/Makefile.am @@ -30,6 +30,8 @@ nodist_libtestgencpp_la_SOURCES = \ gen-cpp/Recursive_types.h \ gen-cpp/ThriftTest_types.cpp \ gen-cpp/ThriftTest_types.h \ + gen-cpp/ThriftTest_constants.cpp \ + gen-cpp/ThriftTest_constants.h \ gen-cpp/TypedefTest_types.cpp \ gen-cpp/TypedefTest_types.h \ ThriftTest_extras.cpp \ @@ -48,7 +50,9 @@ DebugProtoTest_extras.o: gen-cpp/DebugProtoTest_types.h libtestgencpp_la_LIBADD = $(top_builddir)/lib/cpp/libthrift.la -noinst_PROGRAMS = Benchmark +noinst_PROGRAMS = Benchmark \ + processor_test \ + concurrency_test Benchmark_SOURCES = \ Benchmark.cpp @@ -71,9 +75,6 @@ check_PROGRAMS = \ link_test \ OpenSSLManualInitTest \ EnumTest -# disable these test ... too strong -# processor_test -# concurrency_test TESTS_ENVIRONMENT= \ BOOST_TEST_LOG_SINK=tests.xml \ @@ -264,7 +265,7 @@ gen-cpp/Service.cpp gen-cpp/StressTest_types.cpp: $(top_srcdir)/test/StressTest. gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_types.h: $(top_srcdir)/test/ThriftTest.thrift $(THRIFT) --gen cpp:dense $< -gen-cpp/ChildService.cpp: processor/proc.thrift +gen-cpp/ChildService.cpp gen-cpp/ParentService.cpp gen-cpp/proc_types.cpp: processor/proc.thrift $(THRIFT) --gen cpp:templates,cob_style $< AM_CPPFLAGS = $(BOOST_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src diff --git a/lib/cpp/test/processor/ProcessorTest.cpp b/lib/cpp/test/processor/ProcessorTest.cpp index 58b82fbeb..0283d20a5 100644 --- a/lib/cpp/test/processor/ProcessorTest.cpp +++ b/lib/cpp/test/processor/ProcessorTest.cpp @@ -58,13 +58,13 @@ class TSimpleServerTraits { public: typedef TSimpleServer ServerType; - shared_ptr<TSimpleServer> createServer( - const shared_ptr<TProcessor>& processor, + boost::shared_ptr<TSimpleServer> createServer( + const boost::shared_ptr<TProcessor>& processor, uint16_t port, - const shared_ptr<TTransportFactory>& transportFactory, - const shared_ptr<TProtocolFactory>& protocolFactory) { - shared_ptr<TServerSocket> socket(new TServerSocket(port)); - return shared_ptr<TSimpleServer>(new TSimpleServer( + 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)); } }; @@ -73,13 +73,13 @@ class TThreadedServerTraits { public: typedef TThreadedServer ServerType; - shared_ptr<TThreadedServer> createServer( - const shared_ptr<TProcessor>& processor, + boost::shared_ptr<TThreadedServer> createServer( + const boost::shared_ptr<TProcessor>& processor, uint16_t port, - const shared_ptr<TTransportFactory>& transportFactory, - const shared_ptr<TProtocolFactory>& protocolFactory) { - shared_ptr<TServerSocket> socket(new TServerSocket(port)); - return shared_ptr<TThreadedServer>(new TThreadedServer( + 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)); } }; @@ -88,20 +88,20 @@ class TThreadPoolServerTraits { public: typedef TThreadPoolServer ServerType; - shared_ptr<TThreadPoolServer> createServer( - const shared_ptr<TProcessor>& processor, + boost::shared_ptr<TThreadPoolServer> createServer( + const boost::shared_ptr<TProcessor>& processor, uint16_t port, - const shared_ptr<TTransportFactory>& transportFactory, - const shared_ptr<TProtocolFactory>& protocolFactory) { - shared_ptr<TServerSocket> socket(new TServerSocket(port)); + const boost::shared_ptr<TTransportFactory>& transportFactory, + const boost::shared_ptr<TProtocolFactory>& protocolFactory) { + boost::shared_ptr<TServerSocket> socket(new TServerSocket(port)); - shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory); - shared_ptr<ThreadManager> threadManager = + boost::shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory); + boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8); threadManager->threadFactory(threadFactory); threadManager->start(); - return shared_ptr<TThreadPoolServer>(new TThreadPoolServer( + return boost::shared_ptr<TThreadPoolServer>(new TThreadPoolServer( processor, socket, transportFactory, protocolFactory, threadManager)); } @@ -111,11 +111,11 @@ class TNonblockingServerTraits { public: typedef TNonblockingServer ServerType; - shared_ptr<TNonblockingServer> createServer( - const shared_ptr<TProcessor>& processor, + boost::shared_ptr<TNonblockingServer> createServer( + const boost::shared_ptr<TProcessor>& processor, uint16_t port, - const shared_ptr<TTransportFactory>& transportFactory, - const shared_ptr<TProtocolFactory>& protocolFactory) { + const boost::shared_ptr<TTransportFactory>& transportFactory, + const boost::shared_ptr<TProtocolFactory>& protocolFactory) { // TNonblockingServer automatically uses TFramedTransport. // Raise an exception if the supplied transport factory is not a // TFramedTransportFactory @@ -125,13 +125,13 @@ class TNonblockingServerTraits { throw TException("TNonblockingServer must use TFramedTransport"); } - shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory); - shared_ptr<ThreadManager> threadManager = + boost::shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory); + boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(8); threadManager->threadFactory(threadFactory); threadManager->start(); - return shared_ptr<TNonblockingServer>(new TNonblockingServer( + return boost::shared_ptr<TNonblockingServer>(new TNonblockingServer( processor, protocolFactory, port, threadManager)); } }; @@ -140,11 +140,11 @@ class TNonblockingServerNoThreadsTraits { public: typedef TNonblockingServer ServerType; - shared_ptr<TNonblockingServer> createServer( - const shared_ptr<TProcessor>& processor, + boost::shared_ptr<TNonblockingServer> createServer( + const boost::shared_ptr<TProcessor>& processor, uint16_t port, - const shared_ptr<TTransportFactory>& transportFactory, - const shared_ptr<TProtocolFactory>& protocolFactory) { + const boost::shared_ptr<TTransportFactory>& transportFactory, + const boost::shared_ptr<TProtocolFactory>& protocolFactory) { // TNonblockingServer automatically uses TFramedTransport. // Raise an exception if the supplied transport factory is not a // TFramedTransportFactory @@ -155,8 +155,8 @@ class TNonblockingServerNoThreadsTraits { } // Use a NULL ThreadManager - shared_ptr<ThreadManager> threadManager; - return shared_ptr<TNonblockingServer>(new TNonblockingServer( + boost::shared_ptr<ThreadManager> threadManager; + return boost::shared_ptr<TNonblockingServer>(new TNonblockingServer( processor, protocolFactory, port, threadManager)); } }; @@ -246,13 +246,13 @@ class ServiceState : public ServerState { processor_->setEventHandler(processorEventHandler_); } - shared_ptr<TServer> createServer(uint16_t port) { + boost::shared_ptr<TServer> createServer(uint16_t port) { ServerTraits_ serverTraits; return serverTraits.createServer(processor_, port, transportFactory_, protocolFactory_); } - shared_ptr<TServerEventHandler> getServerEventHandler() { + boost::shared_ptr<TServerEventHandler> getServerEventHandler() { return serverEventHandler_; } @@ -264,42 +264,42 @@ class ServiceState : public ServerState { return port_; } - const shared_ptr<EventLog>& getLog() const { + const boost::shared_ptr<EventLog>& getLog() const { return log_; } - const shared_ptr<Handler>& getHandler() const { + const boost::shared_ptr<Handler>& getHandler() const { return handler_; } - shared_ptr<Client> createClient() { + boost::shared_ptr<Client> createClient() { typedef typename ServiceTraits_::Protocol Protocol; - shared_ptr<TSocket> socket(new TSocket("127.0.0.1", port_)); - shared_ptr<Transport_> transport(new Transport_(socket)); - shared_ptr<Protocol> protocol(new Protocol(transport)); + boost::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", port_)); + boost::shared_ptr<Transport_> transport(new Transport_(socket)); + boost::shared_ptr<Protocol> protocol(new Protocol(transport)); transport->open(); - shared_ptr<Client> client(new Client(protocol)); + boost::shared_ptr<Client> client(new Client(protocol)); return client; } private: uint16_t port_; - shared_ptr<EventLog> log_; - shared_ptr<Handler> handler_; - shared_ptr<Processor> processor_; - shared_ptr<TTransportFactory> transportFactory_; - shared_ptr<TProtocolFactory> protocolFactory_; - shared_ptr<TServerEventHandler> serverEventHandler_; - shared_ptr<TProcessorEventHandler> processorEventHandler_; + boost::shared_ptr<EventLog> log_; + boost::shared_ptr<Handler> handler_; + boost::shared_ptr<Processor> processor_; + boost::shared_ptr<TTransportFactory> transportFactory_; + boost::shared_ptr<TProtocolFactory> protocolFactory_; + boost::shared_ptr<TServerEventHandler> serverEventHandler_; + boost::shared_ptr<TProcessorEventHandler> processorEventHandler_; }; /** * Check that there are no more events in the log */ -void checkNoEvents(const shared_ptr<EventLog>& log) { +void checkNoEvents(const boost::shared_ptr<EventLog>& log) { // Wait for an event with a very short timeout period. We don't expect // anything to be present, so we will normally wait for the full timeout. // On the other hand, a non-zero timeout is nice since it does give a short @@ -313,7 +313,7 @@ void checkNoEvents(const shared_ptr<EventLog>& log) { * * Returns the connection ID allocated by the server. */ -uint32_t checkNewConnEvents(const shared_ptr<EventLog>& log) { +uint32_t checkNewConnEvents(const boost::shared_ptr<EventLog>& log) { // Check for an ET_CONN_CREATED event Event event = log->waitForEvent(); BOOST_CHECK_EQUAL(EventLog::ET_CONN_CREATED, event.type); @@ -328,7 +328,7 @@ uint32_t checkNewConnEvents(const shared_ptr<EventLog>& log) { /** * Check for the events that should be logged when a connection is closed. */ -void checkCloseEvents(const shared_ptr<EventLog>& log, uint32_t connId) { +void checkCloseEvents(const boost::shared_ptr<EventLog>& log, uint32_t connId) { // Check for an ET_CONN_DESTROYED event Event event = log->waitForEvent(); BOOST_CHECK_EQUAL(EventLog::ET_CONN_DESTROYED, event.type); @@ -346,7 +346,7 @@ void checkCloseEvents(const shared_ptr<EventLog>& log, uint32_t connId) { * * Returns the call ID allocated by the server. */ -uint32_t checkCallHandlerEvents(const shared_ptr<EventLog>& log, +uint32_t checkCallHandlerEvents(const boost::shared_ptr<EventLog>& log, uint32_t connId, EventType callType, const string& callName) { @@ -383,7 +383,7 @@ uint32_t checkCallHandlerEvents(const shared_ptr<EventLog>& log, /** * Check for the events that should be after a handler returns. */ -void checkCallPostHandlerEvents(const shared_ptr<EventLog>& log, +void checkCallPostHandlerEvents(const boost::shared_ptr<EventLog>& log, uint32_t connId, uint32_t callId, const string& callName) { @@ -423,7 +423,7 @@ void checkCallPostHandlerEvents(const shared_ptr<EventLog>& log, * * Returns the call ID allocated by the server. */ -uint32_t checkCallEvents(const shared_ptr<EventLog>& log, +uint32_t checkCallEvents(const boost::shared_ptr<EventLog>& log, uint32_t connId, EventType callType, const string& callName) { @@ -438,8 +438,8 @@ uint32_t checkCallEvents(const shared_ptr<EventLog>& log, */ template<typename State_> -void testParentService(const shared_ptr<State_>& state) { - shared_ptr<typename State_::Client> client = state->createClient(); +void testParentService(const boost::shared_ptr<State_>& state) { + boost::shared_ptr<typename State_::Client> client = state->createClient(); int32_t gen = client->getGeneration(); int32_t newGen = client->incrementGeneration(); @@ -460,8 +460,8 @@ void testParentService(const shared_ptr<State_>& state) { } template<typename State_> -void testChildService(const shared_ptr<State_>& state) { - shared_ptr<typename State_::Client> client = state->createClient(); +void testChildService(const boost::shared_ptr<State_>& state) { + boost::shared_ptr<typename State_::Client> client = state->createClient(); // Test calling some of the parent methids via the a child client int32_t gen = client->getGeneration(); @@ -483,7 +483,7 @@ void testBasicService() { State; // Start the server - shared_ptr<State> state(new State); + boost::shared_ptr<State> state(new State); ServerThread serverThread(state, true); testParentService(state); @@ -495,7 +495,7 @@ void testInheritedService() { State; // Start the server - shared_ptr<State> state(new State); + boost::shared_ptr<State> state(new State); ServerThread serverThread(state, true); testParentService(state); @@ -517,10 +517,10 @@ void testEventSequencing() { State; // Start the server - shared_ptr<State> state(new State); + boost::shared_ptr<State> state(new State); ServerThread serverThread(state, true); - const shared_ptr<EventLog>& log = state->getLog(); + const boost::shared_ptr<EventLog>& log = state->getLog(); // Make sure we're at the end of the log checkNoEvents(log); @@ -529,7 +529,7 @@ void testEventSequencing() { // Make sure createContext() is called after a connection has been // established. We open a plain socket instead of creating a client. - shared_ptr<TSocket> socket(new TSocket("127.0.0.1", state->getPort())); + boost::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", state->getPort())); socket->open(); // Make sure the proper events occurred after a new connection @@ -651,19 +651,19 @@ void testSeparateConnections() { State; // Start the server - shared_ptr<State> state(new State); + boost::shared_ptr<State> state(new State); ServerThread serverThread(state, true); - const shared_ptr<EventLog>& log = state->getLog(); + const boost::shared_ptr<EventLog>& log = state->getLog(); // Create a client - shared_ptr<typename State::Client> client1 = state->createClient(); + boost::shared_ptr<typename State::Client> client1 = state->createClient(); // Make sure the expected events were logged uint32_t client1Id = checkNewConnEvents(log); // Create a second client - shared_ptr<typename State::Client> client2 = state->createClient(); + boost::shared_ptr<typename State::Client> client2 = state->createClient(); // Make sure the expected events were logged uint32_t client2Id = checkNewConnEvents(log); @@ -701,13 +701,13 @@ void testOnewayCall() { State; // Start the server - shared_ptr<State> state(new State); + boost::shared_ptr<State> state(new State); ServerThread serverThread(state, true); - const shared_ptr<EventLog>& log = state->getLog(); + const boost::shared_ptr<EventLog>& log = state->getLog(); // Create a client - shared_ptr<typename State::Client> client = state->createClient(); + boost::shared_ptr<typename State::Client> client = state->createClient(); uint32_t connId = checkNewConnEvents(log); // Make a oneway call @@ -756,13 +756,13 @@ void testExpectedError() { State; // Start the server - shared_ptr<State> state(new State); + boost::shared_ptr<State> state(new State); ServerThread serverThread(state, true); - const shared_ptr<EventLog>& log = state->getLog(); + const boost::shared_ptr<EventLog>& log = state->getLog(); // Create a client - shared_ptr<typename State::Client> client = state->createClient(); + boost::shared_ptr<typename State::Client> client = state->createClient(); uint32_t connId = checkNewConnEvents(log); // Send the exceptionWait() call @@ -811,13 +811,13 @@ void testUnexpectedError() { State; // Start the server - shared_ptr<State> state(new State); + boost::shared_ptr<State> state(new State); ServerThread serverThread(state, true); - const shared_ptr<EventLog>& log = state->getLog(); + const boost::shared_ptr<EventLog>& log = state->getLog(); // Create a client - shared_ptr<typename State::Client> client = state->createClient(); + boost::shared_ptr<typename State::Client> client = state->createClient(); uint32_t connId = checkNewConnEvents(log); // Send the unexpectedExceptionWait() call @@ -925,10 +925,10 @@ DEFINE_TNONBLOCKINGSERVER_TESTS(TNonblockingServer, Untemplated) DEFINE_TNONBLOCKINGSERVER_TESTS(TNonblockingServerNoThreads, Templated) DEFINE_TNONBLOCKINGSERVER_TESTS(TNonblockingServerNoThreads, Untemplated) -DEFINE_SIMPLE_TESTS(TSimpleServer, Templated); -DEFINE_SIMPLE_TESTS(TSimpleServer, Untemplated); -DEFINE_NOFRAME_TESTS(TSimpleServer, Templated); -DEFINE_NOFRAME_TESTS(TSimpleServer, Untemplated); +DEFINE_SIMPLE_TESTS(TSimpleServer, Templated) +DEFINE_SIMPLE_TESTS(TSimpleServer, Untemplated) +DEFINE_NOFRAME_TESTS(TSimpleServer, Templated) +DEFINE_NOFRAME_TESTS(TSimpleServer, Untemplated) // TODO: We should test TEventServer in the future. // For now, it is known not to work correctly with TProcessorEventHandler. diff --git a/test/cpp/Makefile.am b/test/cpp/Makefile.am index 51380ab41..33e71a315 100755 --- a/test/cpp/Makefile.am +++ b/test/cpp/Makefile.am @@ -94,7 +94,7 @@ THRIFT = $(top_builddir)/compiler/cpp/thrift gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_constants.cpp: $(top_srcdir)/test/ThriftTest.thrift $(THRIFT) --gen cpp:templates,cob_style -r $< -gen-cpp/StressTest_types.cpp gen-cpp/StressTest_constants.cpp: $(top_srcdir)/test/StressTest.thrift +gen-cpp/StressTest_types.cpp gen-cpp/StressTest_constants.cpp gen-cpp/Service.cpp: $(top_srcdir)/test/StressTest.thrift $(THRIFT) --gen cpp $< AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(LIBEVENT_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -Igen-cpp diff --git a/tutorial/cpp/Makefile.am b/tutorial/cpp/Makefile.am index e895b03d9..9768c5189 100755 --- a/tutorial/cpp/Makefile.am +++ b/tutorial/cpp/Makefile.am @@ -60,7 +60,7 @@ TutorialClient_LDADD = \ # THRIFT = $(top_builddir)/compiler/cpp/thrift -gen-cpp/Calculator.cpp gen-cpp/tutorial_types.cpp gen-cpp/tutorial_constants.cpp: $(top_srcdir)/tutorial/tutorial.thrift +gen-cpp/Calculator.cpp gen-cpp/SharedService.cpp gen-cpp/shared_constants.cpp gen-cpp/shared_types.cpp gen-cpp/tutorial_constants.cpp gen-cpp/tutorial_types.cpp: $(top_srcdir)/tutorial/tutorial.thrift $(THRIFT) --gen cpp -r $< AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(LIBEVENT_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -Igen-cpp |