summaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
authorJames E. King III <jking@apache.org>2018-03-24 16:32:02 -0400
committerJames E. King III <jking@apache.org>2018-04-05 10:25:19 -0400
commit6f8c99e98170dcd4f311e755b79f7013868c64c5 (patch)
tree0d8a7a41c707815ed86d624bf81be5317a70185b /test/py
parenta0cf38ed312a5342eb05574719485b725fa52eee (diff)
downloadthrift-6f8c99e98170dcd4f311e755b79f7013868c64c5.tar.gz
THRIFT-3118: add http (for non-ssl and for ssl) to the python cross tests
Diffstat (limited to 'test/py')
-rwxr-xr-xtest/py/TestClient.py21
-rwxr-xr-xtest/py/TestServer.py32
2 files changed, 42 insertions, 11 deletions
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 1ab8e78ae..edab610b1 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -32,8 +32,18 @@ SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
class AbstractTest(unittest.TestCase):
def setUp(self):
- if options.http_path:
- self.transport = THttpClient.THttpClient(options.host, port=options.port, path=options.http_path)
+ if options.trans == 'http':
+ uri = '{0}://{1}:{2}{3}'.format(('https' if options.ssl else 'http'),
+ options.host,
+ options.port,
+ (options.http_path if options.http_path else '/'))
+ if options.ssl:
+ __cafile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "CA.pem")
+ __certfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.crt")
+ __keyfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.key")
+ self.transport = THttpClient.THttpClient(uri, cafile=__cafile, cert_file=__certfile, key_file=__keyfile)
+ else:
+ self.transport = THttpClient.THttpClient(uri)
else:
if options.ssl:
from thrift.transport import TSSLSocket
@@ -325,9 +335,9 @@ if __name__ == "__main__":
dest="verbose", const=0,
help="minimal output")
parser.add_option('--protocol', dest="proto", type="string",
- help="protocol to use, one of: accel, binary, compact, json")
+ help="protocol to use, one of: accel, accelc, binary, compact, json")
parser.add_option('--transport', dest="trans", type="string",
- help="transport to use, one of: buffered, framed")
+ help="transport to use, one of: buffered, framed, http")
parser.set_defaults(framed=False, http_path=None, verbose=1, host='localhost', port=9090, proto='binary')
options, args = parser.parse_args()
@@ -335,6 +345,9 @@ if __name__ == "__main__":
sys.path.insert(0, os.path.join(SCRIPT_DIR, options.genpydir))
sys.path.insert(0, local_libpath())
+ if options.http_path:
+ options.trans = 'http'
+
from ThriftTest import ThriftTest
from ThriftTest.ttypes import Xtruct, Xtruct2, Numberz, Xception, Xception2
from thrift.Thrift import TException
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index 04ad62a95..4dc4c0744 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -21,6 +21,7 @@
from __future__ import division
import logging
import os
+import signal
import sys
import time
from optparse import OptionParser
@@ -180,11 +181,11 @@ class TestHandler(object):
def main(options):
# set up the protocol factory form the --protocol option
prot_factories = {
- 'binary': TBinaryProtocol.TBinaryProtocolFactory,
'accel': TBinaryProtocol.TBinaryProtocolAcceleratedFactory,
- 'compact': TCompactProtocol.TCompactProtocolFactory,
'accelc': TCompactProtocol.TCompactProtocolAcceleratedFactory,
- 'json': TJSONProtocol.TJSONProtocolFactory,
+ 'binary': TBinaryProtocol.TBinaryProtocolFactory,
+ 'compact': TCompactProtocol.TCompactProtocolFactory,
+ 'json': TJSONProtocol.TJSONProtocolFactory
}
pfactory_cls = prot_factories.get(options.proto, None)
if pfactory_cls is None:
@@ -201,14 +202,23 @@ def main(options):
if len(args) > 1:
raise AssertionError('Only one server type may be specified, not multiple types.')
server_type = args[0]
+ if options.trans == 'http':
+ server_type = 'THttpServer'
# Set up the handler and processor objects
handler = TestHandler()
processor = ThriftTest.Processor(handler)
+ global server
+
# Handle THttpServer as a special case
if server_type == 'THttpServer':
- server = THttpServer.THttpServer(processor, ('', options.port), pfactory)
+ if options.ssl:
+ __certfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "server.crt")
+ __keyfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "server.key")
+ server = THttpServer.THttpServer(processor, ('', options.port), pfactory, cert_file=__certfile, key_file=__keyfile)
+ else:
+ server = THttpServer.THttpServer(processor, ('', options.port), pfactory)
server.serve()
sys.exit(0)
@@ -268,7 +278,15 @@ def main(options):
server.serve()
+def exit_gracefully(signum, frame):
+ print("SIGINT received\n")
+ server.shutdown() # doesn't work properly, yet
+ sys.exit(0)
+
+
if __name__ == '__main__':
+ signal.signal(signal.SIGINT, exit_gracefully)
+
parser = OptionParser()
parser.add_option('--libpydir', type='string', dest='libpydir',
help='include this directory to sys.path for locating library code')
@@ -288,12 +306,12 @@ if __name__ == '__main__':
dest="verbose", const=0,
help="minimal output")
parser.add_option('--protocol', dest="proto", type="string",
- help="protocol to use, one of: accel, binary, compact, json")
+ help="protocol to use, one of: accel, accelc, binary, compact, json")
parser.add_option('--transport', dest="trans", type="string",
- help="transport to use, one of: buffered, framed")
+ help="transport to use, one of: buffered, framed, http")
parser.add_option('--container-limit', dest='container_limit', type='int', default=None)
parser.add_option('--string-limit', dest='string_limit', type='int', default=None)
- parser.set_defaults(port=9090, verbose=1, proto='binary')
+ parser.set_defaults(port=9090, verbose=1, proto='binary', transport='buffered')
options, args = parser.parse_args()
# Print TServer log to stdout so that the test-runner can redirect it to log files