THRIFT-847 Test Framework harmonization across all languages
Added 'ssl' tests for python tests.
Added '-transport arg (=buffered) transport: buffered, framed, http' to test/py/TestServer.py and test/py/TestClient.py and removed '-framed' arguement.
Changed test/py/RunClientServer.py to match above changes.
Added tests to compact protocol in python cases.
Added tests to test BinaryAccelarated protocol with Binary Protocol.
Changed py/TestClient.py and py/TestServer.py from --proto to --protocol parameter
Patch: Chamila Dilshan Wijayarathna & Roger Meier
diff --git a/test/py/RunClientServer.py b/test/py/RunClientServer.py
index 782bd83..46c9f8a 100755
--- a/test/py/RunClientServer.py
+++ b/test/py/RunClientServer.py
@@ -34,10 +34,10 @@
help='directory extensions for generated code, used as suffixes for \"gen-py-*\" added sys.path for individual tests')
parser.add_option("--port", type="int", dest="port", default=9090,
help="port number for server to listen on")
-parser.add_option('-v', '--verbose', action="store_const",
+parser.add_option('-v', '--verbose', action="store_const",
dest="verbose", const=2,
help="verbose output")
-parser.add_option('-q', '--quiet', action="store_const",
+parser.add_option('-q', '--quiet', action="store_const",
dest="verbose", const=0,
help="minimal output")
parser.set_defaults(verbose=1)
@@ -107,14 +107,14 @@
ret = subprocess.call(script_args)
if ret != 0:
raise Exception("Script subprocess failed, retcode=%d, args: %s" % (ret, ' '.join(script_args)))
-
+
def runServiceTest(genpydir, server_class, proto, port, use_zlib, use_ssl):
# Build command line arguments
server_args = [sys.executable, relfile('TestServer.py') ]
cli_args = [sys.executable, relfile('TestClient.py') ]
for which in (server_args, cli_args):
which.append('--genpydir=%s' % genpydir)
- which.append('--proto=%s' % proto) # accel, binary or compact
+ which.append('--protocol=%s' % proto) # accel, binary or compact
which.append('--port=%d' % port) # default to 9090
if use_zlib:
which.append('--zlib')
@@ -128,7 +128,9 @@
server_args.append(server_class)
# client-specific cmdline options
if server_class in FRAMED:
- cli_args.append('--framed')
+ cli_args.append('--transport=framed')
+ else:
+ cli_args.append('--transport=buffered')
if server_class == 'THttpServer':
cli_args.append('--http=/')
if options.verbose > 0:
@@ -186,7 +188,7 @@
for genpydir in generated_dirs:
for script in SCRIPTS:
runScriptTest(genpydir, script)
-
+
print '----------------'
print ' Executing Client/Server tests with various generated code directories'
print ' Servers to be tested: ' + ', '.join(SERVERS)
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 18aea86..fd6b8e9 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -40,18 +40,18 @@
help="use SSL for encrypted transport")
parser.add_option("--multiple", action="store_true", dest="multiple",
help="use Multiple service")
-parser.add_option("--framed", action="store_true", dest="framed",
- help="use framed transport")
parser.add_option("--http", dest="http_path",
help="Use the HTTP transport with the specified path")
-parser.add_option('-v', '--verbose', action="store_const",
+parser.add_option('-v', '--verbose', action="store_const",
dest="verbose", const=2,
help="verbose output")
-parser.add_option('-q', '--quiet', action="store_const",
+parser.add_option('-q', '--quiet', action="store_const",
dest="verbose", const=0,
help="minimal output")
-parser.add_option('--proto', dest="proto", type="string",
- help="protocol to use, one of: accel, binary, compact")
+parser.add_option('--protocol', dest="proto", type="string",
+ help="protocol to use, one of: accel, binary, compact, json")
+parser.add_option('--transport', dest="trans", type="string",
+ help="transport to use, one of: buffered, framed")
parser.set_defaults(framed=False, http_path=None, verbose=1, host='localhost', port=9090, proto='binary')
options, args = parser.parse_args()
@@ -79,10 +79,13 @@
else:
socket = TSocket.TSocket(options.host, options.port)
# frame or buffer depending upon args
- if options.framed:
+ self.transport = TTransport.TBufferedTransport(socket)
+ if options.trans == 'framed':
self.transport = TTransport.TFramedTransport(socket)
- else:
+ elif options.trans == 'buffered':
self.transport = TTransport.TBufferedTransport(socket)
+ elif options.trans == '':
+ raise AssertionError('Unknown --transport option: %s' % options.trans)
if options.zlib:
self.transport = TZlibTransport.TZlibTransport(self.transport, 9)
self.transport.open()
@@ -180,7 +183,7 @@
xpected.i64_thing,
{ 0:'abc' },
Numberz.FIVE,
- 0xf0f0f0)
+ 0xf0f0f0)
self.assertEqual(y, xpected)
def testException(self):
@@ -208,7 +211,7 @@
end = time.time()
self.assertTrue(end - start < 3,
"oneway sleep took %f sec" % (end - start))
-
+
def testOnewayThenNormal(self):
self.client.testOneway(1) # type is int, not float
self.assertEqual(self.client.testString('Python'), 'Python')
@@ -241,7 +244,7 @@
elif options.proto == 'json':
suite.addTest(loader.loadTestsFromTestCase(JSONTest))
else:
- raise AssertionError('Unknown protocol given with --proto: %s' % options.proto)
+ raise AssertionError('Unknown protocol given with --protocol: %s' % options.proto)
return suite
class OwnArgsTestProgram(unittest.TestProgram):
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index 8022341..6ee0399 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -35,14 +35,16 @@
help="use SSL for encrypted transport")
parser.add_option("--multiple", action="store_true", dest="multiple",
help="use multiple service")
-parser.add_option('-v', '--verbose', action="store_const",
+parser.add_option('-v', '--verbose', action="store_const",
dest="verbose", const=2,
help="verbose output")
-parser.add_option('-q', '--quiet', action="store_const",
+parser.add_option('-q', '--quiet', action="store_const",
dest="verbose", const=0,
help="minimal output")
-parser.add_option('--proto', dest="proto", type="string",
+parser.add_option('--protocol', dest="proto", type="string",
help="protocol to use, one of: accel, binary, compact, json")
+parser.add_option('--transport', dest="trans", type="string",
+ help="transport to use, one of: buffered, framed")
parser.set_defaults(port=9090, verbose=1, proto='binary')
options, args = parser.parse_args()
@@ -185,10 +187,10 @@
byte_thing=arg0, i32_thing=arg1, i64_thing=arg2)
-# set up the protocol factory form the --proto option
+# set up the protocol factory form the --protocol option
pfactory_cls = PROT_FACTORIES.get(options.proto, None)
if pfactory_cls is None:
- raise AssertionError('Unknown --proto option: %s' % options.proto)
+ raise AssertionError('Unknown --protocol option: %s' % options.proto)
pfactory = pfactory_cls()
# get the server type (TSimpleServer, TNonblockingServer, etc...)
@@ -214,14 +216,26 @@
sys.exit(0)
# set up server transport and transport factory
+
+script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
+rel_path = "../keys/server.pem"
+abs_key_path = os.path.join(script_dir, rel_path)
+
host = None
if options.ssl:
from thrift.transport import TSSLSocket
- transport = TSSLSocket.TSSLServerSocket(host, options.port, certfile='../keys/server.pem')
+ transport = TSSLSocket.TSSLServerSocket(host, options.port, certfile=abs_key_path)
else:
transport = TSocket.TServerSocket(host, options.port)
tfactory = TTransport.TBufferedTransportFactory()
-
+if options.trans == 'buffered':
+ tfactory = TTransport.TBufferedTransportFactory()
+elif options.trans == 'framed':
+ tfactory = TTransport.TFramedTransportFactory()
+elif options.trans == '':
+ raise AssertionError('Unknown --transport option: %s' % options.trans)
+else:
+ tfactory = TTransport.TBufferedTransportFactory()
# if --zlib, then wrap server transport, and use a different transport factory
if options.zlib:
transport = TZlibTransport.TZlibTransport(transport) # wrap with zlib