From 3950f47d6fd95ddc7e0df4563a6a53c348a7b784 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Wed, 11 Oct 2006 02:50:15 +0000 Subject: [PATCH] -- Thrift testing changes Summary: -- Modified StressTest.thrift to work (it was out of date..) and added tests for TBufferedFileWriter -- Modified Makefiles to use the correct lib directory Reviewed By: Slee Test Plan: This is the test. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664827 13f79535-47bb-0310-9956-ffa450edef68 --- test/StressTest.thrift | 4 -- test/cpp/Makefile.stress | 32 +++++----- test/cpp/Makefile.thrift | 4 +- test/cpp/src/main.cc | 130 ++++++++++++++++----------------------- 4 files changed, 73 insertions(+), 97 deletions(-) diff --git a/test/StressTest.thrift b/test/StressTest.thrift index 3cce4ebd..000eb296 100644 --- a/test/StressTest.thrift +++ b/test/StressTest.thrift @@ -4,10 +4,6 @@ service Service { void echoVoid(), byte echoByte(byte arg), -// u16 echoU16(u16 arg), -// u32 echoU32(u32 arg), -// u64 echoU64(u64 arg), -// i16 echoI16(i16 arg), i32 echoI32(i32 arg), i64 echoI64(i64 arg), string echoString(string arg), diff --git a/test/cpp/Makefile.stress b/test/cpp/Makefile.stress index 2190cc31..cbe8bb1a 100644 --- a/test/cpp/Makefile.stress +++ b/test/cpp/Makefile.stress @@ -2,49 +2,51 @@ # # Author: # Marc Kwiatkowski +# Aditya Agarwal ifndef thrift_home -thrift_home=../../../../build +thrift_home=../.. endif #thrift_home target: all -ifndef thirdparty -thirdparty = ../../../../../../../thirdparty -endif #thirdparty - ifndef boost_home -boost_home = /usr/local/include/boost-1_33_1 -endif #thrift_home +#boost_home=../../../../../thirdparty/boost_1_33_1 +boost_home=/usr/local/include/boost-1_33_1 +endif #boost_home target: all -include_paths = $(thrift_home)/include/thrift \ +include_paths = $(thrift_home)/lib/cpp/src \ + $(thrift_home)/lib/cpp \ $(boost_home) include_flags = $(patsubst %,-I%, $(include_paths)) # Tools -THRIFT = thrift +ifndef THRIFT +THRIFT = ../../compiler/cpp/bin/thrift +endif # THRIFT + CC = g++ LD = g++ # Compiler flags -DCFL = -Wall -O3 -g -I cpp-gen $(include_flags) -L$(thrift_home)/lib -lthrift -CFL = -Wall -O3 -I cpp-gen $(include_flags) -L$(thrift_home)/lib -lthrift +DCFL = -Wall -O3 -g -I./gen-cpp $(include_flags) -L$(thrift_home)/lib/cpp/.libs -lthrift -levent +CFL = -Wall -O3 -I./gen-cpp $(include_flags) -L$(thrift_home)/lib/cpp/.libs -lthrift -levent all: stress-test debug: stress-test-debug -stubs: StressTest.thrift +stubs: ../StressTest.thrift $(THRIFT) --cpp --php ../StressTest.thrift stress-test-debug: stubs - g++ -o stress-test $(DCFL) src/main.cc cpp-gen/StressTest.cc + g++ -o stress-test $(DCFL) src/main.cc ./gen-cpp/Service.cc gen-cpp/StressTest_types.cc stress-test: stubs - g++ -o stress-test $(CFL) src/main.cc cpp-gen/StressTest.cc + g++ -o stress-test $(CFL) src/main.cc ./gen-cpp/Service.cc gen-cpp/StressTest_types.cc clean: - rm -fr stress-test cpp-gen + rm -fr stress-test gen-cpp diff --git a/test/cpp/Makefile.thrift b/test/cpp/Makefile.thrift index 1cbd0b73..4fdc4a8c 100644 --- a/test/cpp/Makefile.thrift +++ b/test/cpp/Makefile.thrift @@ -31,8 +31,8 @@ CC = g++ LD = g++ # Compiler flags -DCFL = -Wall -O3 -g -I./gen-cpp $(include_flags) -L$(thrift_home)/lib/cpp -lthrift -levent -CFL = -Wall -O3 -I./gen-cpp $(include_flags) -L$(thrift_home)/lib/cpp -lthrift -levent +DCFL = -Wall -O3 -g -I./gen-cpp $(include_flags) -L$(thrift_home)/lib/cpp/.libs -lthrift -levent +CFL = -Wall -O3 -I./gen-cpp $(include_flags) -L$(thrift_home)/lib/cpp/.libs -lthrift -levent all: server client diff --git a/test/cpp/src/main.cc b/test/cpp/src/main.cc index 062f9037..ff1237e6 100644 --- a/test/cpp/src/main.cc +++ b/test/cpp/src/main.cc @@ -8,7 +8,12 @@ #include #include #include -#include "StressTest.h" +#include +#include +#include +#include + +#include "Service.h" #include #include @@ -24,23 +29,17 @@ using namespace facebook::thrift::server; using namespace test::stress; -class Server : public ServiceServerIf { +class Server : public ServiceIf { public: - Server(shared_ptr protocol) : - ServiceServerIf(protocol) {} - + Server() {}; void echoVoid() {return;} - uint8_t echoByte(uint8_t arg) {return arg;} - int16_t echoI16(int16_t arg) {return arg;} + int8_t echoByte(int8_t arg) {return arg;} int32_t echoI32(int32_t arg) {return arg;} int64_t echoI64(int64_t arg) {return arg;} - uint16_t echoU16(uint16_t arg) {return arg;} - uint32_t echoU32(uint32_t arg) {return arg;} - uint64_t echoU64(uint64_t arg) {return arg;} string echoString(string arg) {return arg;} - list echoList(list arg) {return arg;} - set echoSet(set arg) {return arg;} - map echoMap(map arg) {return arg;} + vector echoList(vector arg) {return arg;} + set echoSet(set arg) {return arg;} + map echoMap(map arg) {return arg;} }; class ClientThread: public Runnable { @@ -72,12 +71,8 @@ public: switch(_loopType) { case T_VOID: loopEchoVoid(); break; case T_BYTE: loopEchoByte(); break; - case T_I16: loopEchoI16(); break; case T_I32: loopEchoI32(); break; case T_I64: loopEchoI64(); break; - case T_U16: loopEchoU16(); break; - case T_U32: loopEchoU32(); break; - case T_U64: loopEchoU64(); break; case T_STRING: loopEchoString(); break; default: cerr << "Unexpected loop type" << _loopType << endl; break; } @@ -107,26 +102,17 @@ public: void loopEchoByte() { for(size_t ix = 0; ix < _loopCount; ix++) { - uint8_t arg = 1; - uint8_t result; + int8_t arg = 1; + int8_t result; result =_client->echoByte(arg); assert(result == arg); } } - void loopEchoI16() { - for(size_t ix = 0; ix < _loopCount; ix++) { - uint16_t arg = 1; - uint16_t result; - result =_client->echoI16(arg); - assert(result == arg); - } - } - void loopEchoI32() { for(size_t ix = 0; ix < _loopCount; ix++) { - uint32_t arg = 1; - uint32_t result; + int32_t arg = 1; + int32_t result; result =_client->echoI32(arg); assert(result == arg); } @@ -134,40 +120,13 @@ public: void loopEchoI64() { for(size_t ix = 0; ix < _loopCount; ix++) { - uint64_t arg = 1; - uint64_t result; + int64_t arg = 1; + int64_t result; result =_client->echoI64(arg); assert(result == arg); } } - - void loopEchoU16() { - for(size_t ix = 0; ix < _loopCount; ix++) { - uint16_t arg = 1; - uint16_t result; - result =_client->echoU16(arg); - assert(result == arg); - } - } - - void loopEchoU32() { - for(size_t ix = 0; ix < _loopCount; ix++) { - uint32_t arg = 1; - uint32_t result; - result =_client->echoU32(arg); - assert(result == arg); - } - } - - void loopEchoU64() { - for(size_t ix = 0; ix < _loopCount; ix++) { - uint64_t arg = 1; - uint64_t result; - result =_client->echoU64(arg); - assert(result == arg); - } - } - + void loopEchoString() { for(size_t ix = 0; ix < _loopCount; ix++) { string arg = "hello"; @@ -200,6 +159,8 @@ int main(int argc, char **argv) { TType loopType = T_VOID; string callName = "echoVoid"; bool runServer = true; + bool logRequests = false; + string requestLogPath = "./requestlog.tlog"; ostringstream usage; @@ -213,6 +174,7 @@ int main(int argc, char **argv) { "\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 << "\tworkers Number of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl; map args; @@ -264,6 +226,10 @@ int main(int argc, char **argv) { runServer = args["server"] == "true"; } + if(!args["log-request"].empty()) { + logRequests = args["log-request"] == "true"; + } + if(!args["server-type"].empty()) { serverType = args["server-type"]; @@ -293,21 +259,36 @@ int main(int argc, char **argv) { // Dispatcher shared_ptr binaryProtocol(new TBinaryProtocol); - shared_ptr server(new Server(binaryProtocol)); + shared_ptr serviceHandler(new Server()); - // Options - shared_ptr serverOptions(new TServerOptions()); + shared_ptr serviceProcessor(new ServiceProcessor(serviceHandler, binaryProtocol)); // Transport shared_ptr serverSocket(new TServerSocket(port)); - // ThreadFactory + // Transport Factory + shared_ptr transportFactory(new TBufferedTransportFactory()); + + // Options + shared_ptr serverOptions(new TServerOptions()); + + if (logRequests) { + // initialize the log file + shared_ptr bufferedFileWriter(new TBufferedFileWriter(requestLogPath, 1000)); + bufferedFileWriter->setChunkSize(2 * 1024 * 1024); + bufferedFileWriter->setMaxEventSize(1024 * 16); + + transportFactory = shared_ptr(new TBufferedRouterTransportFactory(bufferedFileWriter)); + } shared_ptr serverThread; if(serverType == "simple") { - serverThread = threadFactory->newThread(shared_ptr(new TSimpleServer(server, serverOptions, serverSocket))); + serverThread = threadFactory->newThread(shared_ptr(new TSimpleServer(serviceProcessor, + serverSocket, + transportFactory, + serverOptions))); } else if(serverType == "thread-pool") { @@ -316,11 +297,12 @@ int main(int argc, char **argv) { threadManager->threadFactory(threadFactory); threadManager->start(); - - serverThread = threadFactory->newThread(shared_ptr(new TThreadPoolServer(server, - serverOptions, - serverSocket, - threadManager))); + + serverThread = threadFactory->newThread(shared_ptr(new TThreadPoolServer(serviceProcessor, + serverSocket, + transportFactory, + threadManager, + serverOptions))); } cerr << "Starting the server on port " << port << endl; @@ -344,12 +326,8 @@ int main(int argc, char **argv) { if(callName == "echoVoid") { loopType = T_VOID;} else if(callName == "echoByte") { loopType = T_BYTE;} - else if(callName == "echoI16") { loopType = T_I16;} else if(callName == "echoI32") { loopType = T_I32;} else if(callName == "echoI64") { loopType = T_I64;} - else if(callName == "echoU16") { loopType = T_U16;} - else if(callName == "echoU32") { loopType = T_U32;} - else if(callName == "echoU64") { loopType = T_U64;} else if(callName == "echoString") { loopType = T_STRING;} else {throw invalid_argument("Unknown service call "+callName);} @@ -358,9 +336,9 @@ int main(int argc, char **argv) { shared_ptr socket(new TSocket("127.0.01", port)); shared_ptr bufferedSocket(new TBufferedTransport(socket, 2048)); shared_ptr binaryProtocol(new TBinaryProtocol()); - shared_ptr serviceClient(new ServiceClient(bufferedSocket, binaryProtocol)); + shared_ptr serviceClient(new ServiceClient(socket, binaryProtocol)); - clientThreads.insert(threadFactory->newThread(shared_ptr(new ClientThread(bufferedSocket, serviceClient, monitor, threadCount, loopCount, loopType)))); + clientThreads.insert(threadFactory->newThread(shared_ptr(new ClientThread(socket, serviceClient, monitor, threadCount, loopCount, loopType)))); } for(std::set >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) { -- 2.17.1