From: Mark Slee Date: Mon, 5 Mar 2007 05:40:37 +0000 (+0000) Subject: Threads testing package update X-Git-Tag: 0.2.0~1430 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=c416a2730da7979933133c825dd576fee075436a;p=common%2Fthrift.git Threads testing package update git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665042 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/threads/Makefile b/test/threads/Makefile index 79c0134c..7e889443 100644 --- a/test/threads/Makefile +++ b/test/threads/Makefile @@ -34,7 +34,7 @@ LFL = -L$(thrift_home)/lib/cpp/.libs -lthrift CCFL = -Wall -O3 -g -I./gen-cpp $(include_flags) CFL = $(CCFL) $(LFL) -all: server +all: server client stubs: ThreadsTest.thrift $(THRIFT) -cpp -py ThreadsTest.thrift @@ -42,5 +42,8 @@ stubs: ThreadsTest.thrift server: stubs g++ -o ThreadsServer $(CFL) ThreadsServer.cpp ./gen-cpp/ThreadsTest.cpp ./gen-cpp/ThreadsTest_types.cpp +client: stubs + g++ -o ThreadsClient $(CFL) ThreadsClient.cpp ./gen-cpp/ThreadsTest.cpp ./gen-cpp/ThreadsTest_types.cpp + clean: rm -fr *.o ThreadsServer gen-cpp diff --git a/test/threads/ThreadsClient.cpp b/test/threads/ThreadsClient.cpp new file mode 100644 index 00000000..d8f67669 --- /dev/null +++ b/test/threads/ThreadsClient.cpp @@ -0,0 +1,43 @@ +// This autogenerated skeleton file illustrates how to build a server. +// You should copy it to another filename to avoid overwriting it. + +#include "ThreadsTest.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace facebook::thrift; +using namespace facebook::thrift::protocol; +using namespace facebook::thrift::transport; +using namespace facebook::thrift::server; +using namespace facebook::thrift::concurrency; + +int main(int argc, char **argv) { + int port = 9090; + std::string host = "localhost"; + + shared_ptr transport(new TSocket(host, port)); + shared_ptr protocol(new TBinaryProtocol(transport)); + + transport->open(); + + ThreadsTestClient client(protocol); + int val; + val = client.threadOne(5); + fprintf(stderr, "%d\n", val); + val = client.stop(); + fprintf(stderr, "%d\n", val); + val = client.threadTwo(5); + fprintf(stderr, "%d\n", val); + + transport->close(); + + fprintf(stderr, "done.\n"); + + return 0; +} + diff --git a/test/threads/ThreadsServer.cpp b/test/threads/ThreadsServer.cpp index 1e3494cc..f5bd665c 100644 --- a/test/threads/ThreadsServer.cpp +++ b/test/threads/ThreadsServer.cpp @@ -23,33 +23,38 @@ class ThreadsTestHandler : virtual public ThreadsTestIf { // Your initialization goes here } - void threadOne(const int32_t sleep) { + int32_t threadOne(const int32_t sleep) { // Your implementation goes here printf("threadOne\n"); go2sleep(1, sleep); + return 1; } - void threadTwo(const int32_t sleep) { + int32_t threadTwo(const int32_t sleep) { // Your implementation goes here printf("threadTwo\n"); go2sleep(2, sleep); + return 1; } - void threadThree(const int32_t sleep) { + int32_t threadThree(const int32_t sleep) { // Your implementation goes here printf("threadThree\n"); go2sleep(3, sleep); + return 1; } - void threadFour(const int32_t sleep) { + int32_t threadFour(const int32_t sleep) { // Your implementation goes here printf("threadFour\n"); go2sleep(4, sleep); + return 1; } - void stop() { + int32_t stop() { printf("stop\n"); server_->stop(); + return 1; } void setServer(boost::shared_ptr server) { diff --git a/test/threads/ThreadsTest.thrift b/test/threads/ThreadsTest.thrift index ebf2513e..ed071e5d 100755 --- a/test/threads/ThreadsTest.thrift +++ b/test/threads/ThreadsTest.thrift @@ -1,11 +1,11 @@ #!/usr/local/bin/thrift -cpp -py service ThreadsTest { - void threadOne(1: i32 sleep=15), - void threadTwo(2: i32 sleep=15), - void threadThree(3: i32 sleep=15), - void threadFour(4: i32 sleep=15) + i32 threadOne(1: i32 sleep=15), + i32 threadTwo(2: i32 sleep=15), + i32 threadThree(3: i32 sleep=15), + i32 threadFour(4: i32 sleep=15) - void stop(); + i32 stop(); }