Fix broken thrift test code for new model
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664839 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
index 83e8f79..e508b0f 100644
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -2,7 +2,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <protocol/TBinaryProtocol.h>
-#include <transport/TBufferedTransport.h>
+#include <transport/TTransportUtils.h>
#include <transport/TSocket.h>
#include <boost/shared_ptr.hpp>
@@ -33,21 +33,50 @@
string host = "localhost";
int port = 9090;
int numTests = 1;
+ bool framed = false;
+ bool frameInput = true;
- if (argc > 1) {
- host = argv[1];
+ for (int i = 0; i < argc; ++i) {
+ if (strcmp(argv[i], "-h") == 0) {
+ char* pch = strtok(argv[++i], ":");
+ if (pch != NULL) {
+ host = string(pch);
+ }
+ pch = strtok(NULL, ":");
+ if (pch != NULL) {
+ port = atoi(pch);
+ }
+ } else if (strcmp(argv[i], "-n") == 0) {
+ numTests = atoi(argv[++i]);
+ } else if (strcmp(argv[i], "-f") == 0) {
+ framed = true;
+ } else if (strcmp(argv[i], "-fo") == 0) {
+ framed = true;
+ frameInput = false;
+ }
}
- if (argc > 2) {
- port = atoi(argv[2]);
- }
- if (argc > 3) {
- numTests = atoi(argv[3]);
- }
+
+
+ shared_ptr<TTransport> transport;
shared_ptr<TSocket> socket(new TSocket(host, port));
- shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
- shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol());
- ThriftTestClient testClient(bufferedSocket, binaryProtocol);
+
+ if (framed) {
+ shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
+ framedSocket->setRead(frameInput);
+ transport = framedSocket;
+ if (frameInput) {
+ printf("Using bi-directional framed transport mode\n");
+ } else {
+ printf("Using framed output only mode\n");
+ }
+ } else {
+ shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
+ transport = bufferedSocket;
+ }
+
+ shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport, transport));
+ ThriftTestClient testClient(protocol);
uint64_t time_min = 0;
uint64_t time_max = 0;
@@ -57,7 +86,7 @@
for (test = 0; test < numTests; ++test) {
try {
- bufferedSocket->open();
+ transport->open();
} catch (TTransportException& ttx) {
printf("Connect failed: %s\n", ttx.getMessage().c_str());
continue;
@@ -396,7 +425,7 @@
time_max = tot;
}
- bufferedSocket->close();
+ transport->close();
}
// printf("\nSocket syscalls: %u", g_socket_syscalls);
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index 34c9dfb..28a40fd 100644
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -5,7 +5,7 @@
#include <server/TThreadPoolServer.h>
#include <server/TNonblockingServer.h>
#include <transport/TServerSocket.h>
-#include <transport/TBufferedTransportFactory.h>
+#include <transport/TTransportUtils.h>
#include "ThriftTest.h"
#include <iostream>
@@ -264,13 +264,14 @@
string serverType = "simple";
string protocolType = "binary";
size_t workerCount = 4;
+ bool frameOutput = true;
ostringstream usage;
usage <<
argv[0] << " [--port=<port number>] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>]" << endl <<
- "\t\tserver-type\t\ttype of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl <<
+ "\t\tserver-type\t\ttype of server, \"simple\", \"thread-pool\", or \"nonblocking\". Default is " << serverType << endl <<
"\t\tprotocol-type\t\ttype of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl <<
@@ -285,9 +286,8 @@
if (end != string::npos) {
args[string(arg, 2, end - 2)] = string(arg, end + 1);
} else {
- args[string(arg, 2, end - 2)] = "true";
+ args[string(arg, 2)] = "true";
}
- ix++;
} else {
throw invalid_argument("Unexcepted command line token: "+arg);
}
@@ -299,6 +299,10 @@
port = atoi(args["port"].c_str());
}
+ if (!args["noframe"].empty()) {
+ frameOutput = false;
+ }
+
if (!args["server-type"].empty()) {
serverType = args["server-type"];
if (serverType == "simple") {
@@ -330,11 +334,11 @@
}
// Dispatcher
- shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol);
+ shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
shared_ptr<TestHandler> testHandler(new TestHandler());
- shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler, binaryProtocol));
+ shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
// Transport
shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
@@ -342,17 +346,13 @@
// Factory
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
- // Options
- shared_ptr<TServerOptions> serverOptions(new TServerOptions());
-
if (serverType == "simple") {
// Server
TSimpleServer simpleServer(testProcessor,
serverSocket,
transportFactory,
- serverOptions
- );
+ protocolFactory);
printf("Starting the server on port %d...\n", port);
simpleServer.serve();
@@ -372,17 +372,22 @@
TThreadPoolServer threadPoolServer(testProcessor,
serverSocket,
transportFactory,
- threadManager,
- serverOptions);
+ protocolFactory,
+ threadManager);
printf("Starting the server on port %d...\n", port);
threadPoolServer.serve();
} else if (serverType == "nonblocking") {
- TNonblockingServer nonblockingServer(testProcessor,
- serverOptions,
- port);
+ TNonblockingServer nonblockingServer(testProcessor, port);
+ nonblockingServer.setFrameResponses(frameOutput);
+ if (frameOutput) {
+ printf("Using framed output mode\n");
+ } else {
+ printf("Using non-framed output mode\n");
+ }
+
printf("Starting the nonblocking server on port %d...\n", port);
nonblockingServer.serve();