From b9acf98b33945843c2e75a64692056b23d3f5128 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Tue, 10 Oct 2006 01:57:32 +0000 Subject: [PATCH] Test code updates git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664823 13f79535-47bb-0310-9956-ffa450edef68 --- test/cpp/Makefile.thrift | 6 ++--- test/cpp/src/TestClient.cc | 10 ++++---- test/cpp/src/TestServer.cc | 19 +++++++++++--- test/java/TestClient | 2 +- test/java/TestServer | 2 +- test/java/src/TestClient.java | 47 ++++++++++++++++++++++++----------- 6 files changed, 58 insertions(+), 28 deletions(-) diff --git a/test/cpp/Makefile.thrift b/test/cpp/Makefile.thrift index 9664debb..1cbd0b73 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 -CFL = -Wall -O3 -I./gen-cpp $(include_flags) -L$(thrift_home)/lib/cpp -lthrift +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 all: server client @@ -42,7 +42,7 @@ stubs: ../ThriftTest.thrift $(THRIFT) --cpp ../ThriftTest.thrift server-debug: stubs - g++ -o TestServer $(DCFL) src/TestServer.cc ./gen-cpp/ThriftTest.cc ./gen-cpp/ThriftTest_types.cc + g++ -o TestServer $(DCFL) src/TestServer.cc ./gen-cpp/ThriftTest.cc ./gen-cpp/ThriftTest_types.cc client-debug: stubs g++ -o TestClient $(DCFL) src/TestClient.cc ./gen-cpp/ThriftTest.cc ./gen-cpp/ThriftTest_types.cc diff --git a/test/cpp/src/TestClient.cc b/test/cpp/src/TestClient.cc index 6334f080..83e8f795 100644 --- a/test/cpp/src/TestClient.cc +++ b/test/cpp/src/TestClient.cc @@ -213,12 +213,12 @@ int main(int argc, char** argv) { /** * LIST TEST */ - list listout; + vector listout; for (int32_t i = -2; i < 3; ++i) { listout.push_back(i); } printf("testList({"); - list::const_iterator l_iter; + vector::const_iterator l_iter; first = true; for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { if (first) { @@ -229,7 +229,7 @@ int main(int argc, char** argv) { printf("%d", *l_iter); } printf("})"); - list listin = testClient.testList(listout); + vector listin = testClient.testList(listout); printf(" = {"); first = true; for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { @@ -319,8 +319,8 @@ int main(int argc, char** argv) { } printf("}, "); - list xtructs = i2_iter->second.xtructs; - list::const_iterator x; + vector xtructs = i2_iter->second.xtructs; + vector::const_iterator x; printf("{"); for (x = xtructs.begin(); x != xtructs.end(); ++x) { printf("{\"%s\", %d, %d, %ld}, ", diff --git a/test/cpp/src/TestServer.cc b/test/cpp/src/TestServer.cc index db41b79d..34c9dfb5 100644 --- a/test/cpp/src/TestServer.cc +++ b/test/cpp/src/TestServer.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "ThriftTest.h" @@ -96,9 +97,9 @@ class TestHandler : public ThriftTestIf { return thing; } - list testList(list thing) { + vector testList(vector thing) { printf("testList({"); - list::const_iterator l_iter; + vector::const_iterator l_iter; bool first = true; for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) { if (first) { @@ -192,8 +193,8 @@ class TestHandler : public ThriftTestIf { } printf("}, "); - list xtructs = i2_iter->second.xtructs; - list::const_iterator x; + vector xtructs = i2_iter->second.xtructs; + vector::const_iterator x; printf("{"); for (x = xtructs.begin(); x != xtructs.end(); ++x) { printf("{\"%s\", %d, %d, %ld}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing); @@ -302,6 +303,7 @@ int main(int argc, char **argv) { serverType = args["server-type"]; if (serverType == "simple") { } else if (serverType == "thread-pool") { + } else if (serverType == "nonblocking") { } else { throw invalid_argument("Unknown server type "+serverType); } @@ -375,6 +377,15 @@ int main(int argc, char **argv) { printf("Starting the server on port %d...\n", port); threadPoolServer.serve(); + + } else if (serverType == "nonblocking") { + + TNonblockingServer nonblockingServer(testProcessor, + serverOptions, + port); + printf("Starting the nonblocking server on port %d...\n", port); + nonblockingServer.serve(); + } printf("done.\n"); diff --git a/test/java/TestClient b/test/java/TestClient index ba7d81f1..f4006d54 100755 --- a/test/java/TestClient +++ b/test/java/TestClient @@ -1,2 +1,2 @@ #!/bin/bash -v -java -cp thrifttest.jar:/usr/local/lib/libthrift.jar com.facebook.thrift.test.TestClient $1 $2 $3 +java -cp thrifttest.jar:/usr/local/lib/libthrift.jar com.facebook.thrift.test.TestClient $* diff --git a/test/java/TestServer b/test/java/TestServer index 7c272c1f..40765413 100755 --- a/test/java/TestServer +++ b/test/java/TestServer @@ -1,2 +1,2 @@ #!/bin/bash -v -java -server -cp thrifttest.jar:/usr/local/lib/libthrift.jar com.facebook.thrift.test.TestServer $1 +java -server -cp thrifttest.jar:/usr/local/lib/libthrift.jar com.facebook.thrift.test.TestServer $* diff --git a/test/java/src/TestClient.java b/test/java/src/TestClient.java index fda37de8..46a4ca5a 100644 --- a/test/java/src/TestClient.java +++ b/test/java/src/TestClient.java @@ -3,7 +3,9 @@ package com.facebook.thrift.test; // Generated code import thrift.test.*; +import com.facebook.thrift.transport.TTransport; import com.facebook.thrift.transport.TSocket; +import com.facebook.thrift.transport.THttpClient; import com.facebook.thrift.transport.TTransportException; import com.facebook.thrift.protocol.TBinaryProtocol; @@ -23,24 +25,41 @@ public class TestClient { try { String host = "localhost"; int port = 9090; + String url = null; int numTests = 1; - - if (args.length > 0) { - host = args[0]; - } - if (args.length > 1) { - port = Integer.valueOf(args[1]); - } - if (args.length > 2) { - numTests = Integer.valueOf(args[2]); + + try { + for (int i = 0; i < args.length; ++i) { + if (args[i].equals("-h")) { + String[] hostport = (args[++i]).split(";"); + host = hostport[0]; + port = Integer.valueOf(hostport[1]); + } + + if (args[i].equals("-u")) { + url = args[++i]; + } + + if (args[i].equals("-n")) { + numTests = Integer.valueOf(args[++i]); + } + } + } catch (Exception x) { + x.printStackTrace(); } - TSocket tSocket = - new TSocket(host, port); + TTransport transport; + + if (url != null) { + transport = new THttpClient(url); + } else { + transport = new TSocket(host, port); + } + TBinaryProtocol binaryProtocol = new TBinaryProtocol(); ThriftTest.Client testClient = - new ThriftTest.Client(tSocket, binaryProtocol); + new ThriftTest.Client(transport, binaryProtocol); long timeMin = 0; long timeMax = 0; @@ -53,7 +72,7 @@ public class TestClient { */ System.out.println("Test #" + (test+1) + ", " + "connect " + host + ":" + port); try { - tSocket.open(); + transport.open(); } catch (TTransportException ttx) { System.out.println("Connect failed: " + ttx.getMessage()); continue; @@ -322,7 +341,7 @@ public class TestClient { } timeTot += tot; - tSocket.close(); + transport.close(); } long timeAvg = timeTot / numTests; -- 2.17.1