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 79c0134..7e88944 100644
--- a/test/threads/Makefile
+++ b/test/threads/Makefile
@@ -34,7 +34,7 @@
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 @@
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 0000000..d8f6766
--- /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 <protocol/TBinaryProtocol.h>
+#include <server/TThreadPoolServer.h>
+#include <transport/TSocket.h>
+#include <transport/TTransportUtils.h>
+#include <thrift/concurrency/Monitor.h>
+#include <thrift/concurrency/ThreadManager.h>
+#include <thrift/concurrency/PosixThreadFactory.h>
+
+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<TTransport> transport(new TSocket(host, port));
+ shared_ptr<TProtocol> 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 1e3494c..f5bd665 100644
--- a/test/threads/ThreadsServer.cpp
+++ b/test/threads/ThreadsServer.cpp
@@ -23,33 +23,38 @@
// 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<TServer> server) {
diff --git a/test/threads/ThreadsTest.thrift b/test/threads/ThreadsTest.thrift
index ebf2513..ed071e5 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();
}