diff options
author | Dave Watson <davejwatson@fb.com> | 2015-01-16 11:22:01 -0800 |
---|---|---|
committer | Nobuaki Sukegawa <nsuke@apache.org> | 2015-11-04 01:25:22 +0900 |
commit | 792db4e92607a38a45eeb57f9561210cd4d4ef73 (patch) | |
tree | 09c0d82965e7c57bbf7d9b65b010e435fea7b2ba /test/cpp | |
parent | b31f0900b57b7473a8f84c7b74f73381dcff2818 (diff) | |
download | thrift-792db4e92607a38a45eeb57f9561210cd4d4ef73.tar.gz |
THRIFT-2423 Facebook's THeader protocol and transport for cpp
Client: C++ Library, Compiler
Patch: Dave Watson rebased by Nobuaki Sukegawa
This closes #357 and closes #677
Diffstat (limited to 'test/cpp')
-rwxr-xr-x | test/cpp/CMakeLists.txt | 9 | ||||
-rwxr-xr-x | test/cpp/Makefile.am | 4 | ||||
-rw-r--r-- | test/cpp/src/TestClient.cpp | 7 | ||||
-rw-r--r-- | test/cpp/src/TestServer.cpp | 14 |
4 files changed, 25 insertions, 9 deletions
diff --git a/test/cpp/CMakeLists.txt b/test/cpp/CMakeLists.txt index 2d75f2e1d..67d9510cf 100755 --- a/test/cpp/CMakeLists.txt +++ b/test/cpp/CMakeLists.txt @@ -54,23 +54,24 @@ add_library(crossstressgencpp STATIC ${crossstressgencpp_SOURCES}) LINK_AGAINST_THRIFT_LIBRARY(crossstressgencpp thrift) add_executable(TestServer src/TestServer.cpp) -target_link_libraries(TestServer crosstestgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB}) +target_link_libraries(TestServer crosstestgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB} ${ZLIB_LIBRARIES}) LINK_AGAINST_THRIFT_LIBRARY(TestServer thrift) LINK_AGAINST_THRIFT_LIBRARY(TestServer thriftnb) +LINK_AGAINST_THRIFT_LIBRARY(TestServer thriftnb) add_executable(TestClient src/TestClient.cpp) -target_link_libraries(TestClient crosstestgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB}) +target_link_libraries(TestClient crosstestgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB} ${ZLIB_LIBRARIES}) LINK_AGAINST_THRIFT_LIBRARY(TestClient thrift) LINK_AGAINST_THRIFT_LIBRARY(TestClient thriftnb) add_executable(StressTest src/StressTest.cpp) -target_link_libraries(StressTest crossstressgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB}) +target_link_libraries(StressTest crossstressgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB} ${ZLIB_LIBRARIES}) LINK_AGAINST_THRIFT_LIBRARY(StressTest thrift) LINK_AGAINST_THRIFT_LIBRARY(StressTest thriftnb) add_test(NAME StressTest COMMAND StressTest) add_executable(StressTestNonBlocking src/StressTestNonBlocking.cpp) -target_link_libraries(StressTestNonBlocking crossstressgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB}) +target_link_libraries(StressTestNonBlocking crossstressgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB} ${ZLIB_LIBRARIES}) LINK_AGAINST_THRIFT_LIBRARY(StressTestNonBlocking thrift) LINK_AGAINST_THRIFT_LIBRARY(StressTestNonBlocking thriftnb) LINK_AGAINST_THRIFT_LIBRARY(StressTestNonBlocking thriftz) diff --git a/test/cpp/Makefile.am b/test/cpp/Makefile.am index bc026b282..c609a71ac 100755 --- a/test/cpp/Makefile.am +++ b/test/cpp/Makefile.am @@ -69,7 +69,7 @@ TestServer_LDADD = \ $(top_builddir)/lib/cpp/libthrift.la \ $(top_builddir)/lib/cpp/libthriftz.la \ $(top_builddir)/lib/cpp/libthriftnb.la \ - -levent -lboost_program_options -lboost_system -lboost_filesystem + -levent -lboost_program_options -lboost_system -lboost_filesystem $(ZLIB_LIBS) TestClient_SOURCES = \ src/TestClient.cpp @@ -79,7 +79,7 @@ TestClient_LDADD = \ $(top_builddir)/lib/cpp/libthrift.la \ $(top_builddir)/lib/cpp/libthriftz.la \ $(top_builddir)/lib/cpp/libthriftnb.la \ - -levent -lboost_program_options -lboost_system -lboost_filesystem + -levent -lboost_program_options -lboost_system -lboost_filesystem $(ZLIB_LIBS) StressTest_SOURCES = \ src/StressTest.cpp diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp index 2736ee8d5..47539dcec 100644 --- a/test/cpp/src/TestClient.cpp +++ b/test/cpp/src/TestClient.cpp @@ -23,6 +23,7 @@ #include <iostream> #include <thrift/protocol/TBinaryProtocol.h> #include <thrift/protocol/TCompactProtocol.h> +#include <thrift/protocol/THeaderProtocol.h> #include <thrift/protocol/TJSONProtocol.h> #include <thrift/transport/THttpClient.h> #include <thrift/transport/TTransportUtils.h> @@ -170,7 +171,7 @@ int main(int argc, char** argv) { "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")( + "Protocol: binary, header, 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"); @@ -188,6 +189,7 @@ int main(int argc, char** argv) { if (!protocol_type.empty()) { if (protocol_type == "binary") { } else if (protocol_type == "compact") { + } else if (protocol_type == "header") { } else if (protocol_type == "json") { } else { throw invalid_argument("Unknown protocol type " + protocol_type); @@ -266,6 +268,9 @@ int main(int argc, char** argv) { } else if (protocol_type.compare("compact") == 0) { boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport)); protocol = compactProtocol; + } else if (protocol_type == "header") { + boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport)); + protocol = headerProtocol; } else { boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport)); protocol = binaryProtocol; diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp index 51169afe3..12c4b973d 100644 --- a/test/cpp/src/TestServer.cpp +++ b/test/cpp/src/TestServer.cpp @@ -24,6 +24,7 @@ #include <thrift/concurrency/PlatformThreadFactory.h> #include <thrift/protocol/TBinaryProtocol.h> #include <thrift/protocol/TCompactProtocol.h> +#include <thrift/protocol/THeaderProtocol.h> #include <thrift/protocol/TJSONProtocol.h> #include <thrift/server/TSimpleServer.h> #include <thrift/server/TThreadedServer.h> @@ -567,7 +568,7 @@ int main(int argc, char** argv) { "transport: buffered, framed, http")( "protocol", boost::program_options::value<string>(&protocol_type)->default_value(protocol_type), - "protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")( + "protocol: binary, compact, header, json")("ssl", "Encrypted Transport using SSL")( "processor-events", "processor-events")("workers,n", boost::program_options::value<size_t>(&workers)->default_value(workers), @@ -597,6 +598,7 @@ int main(int argc, char** argv) { if (protocol_type == "binary") { } else if (protocol_type == "compact") { } else if (protocol_type == "json") { + } else if (protocol_type == "header") { } else { throw invalid_argument("Unknown protocol type " + protocol_type); } @@ -633,6 +635,9 @@ int main(int argc, char** argv) { } else if (protocol_type == "compact") { boost::shared_ptr<TProtocolFactory> compactProtocolFactory(new TCompactProtocolFactory()); protocolFactory = compactProtocolFactory; + } else if (protocol_type == "header") { + boost::shared_ptr<TProtocolFactory> headerProtocolFactory(new THeaderProtocolFactory()); + protocolFactory = headerProtocolFactory; } else { boost::shared_ptr<TProtocolFactory> binaryProtocolFactory( new TBinaryProtocolFactoryT<TBufferBase>()); @@ -739,11 +744,16 @@ int main(int argc, char** argv) { TEvhttpServer nonblockingServer(testBufferProcessor, port); nonblockingServer.serve(); } else { - server.reset(new TNonblockingServer(testProcessor, port)); + server.reset(new TNonblockingServer(testProcessor, protocolFactory, port)); } } if (server.get() != NULL) { + if (protocol_type == "header") { + // Tell the server to use the same protocol for input / output + // if using header + server->setOutputProtocolFactory(boost::shared_ptr<TProtocolFactory>()); + } apache::thrift::concurrency::PlatformThreadFactory factory; factory.setDetached(false); boost::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server); |