THRIFT-4548: add python cross test client multiplexed protocol support
Client: py
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index edab610..2164162 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -63,6 +63,9 @@
self.transport.open()
protocol = self.get_protocol(self.transport)
self.client = ThriftTest.Client(protocol)
+ # for multiplexed services:
+ protocol2 = self.get_protocol2(self.transport)
+ self.client2 = SecondService.Client(protocol2) if protocol2 is not None else None
def tearDown(self):
self.transport.close()
@@ -107,6 +110,11 @@
self.assertEqual(self.client.testString(s1), s1)
self.assertEqual(self.client.testString(s2), s2)
+ def testMultiplexed(self):
+ if self.client2 is not None:
+ print('testMultiplexed')
+ self.assertEqual(self.client2.secondtestString('foobar'), 'testString("foobar")')
+
def testBool(self):
print('testBool')
self.assertEqual(self.client.testBool(True), True)
@@ -260,44 +268,109 @@
self.assertEqual(self.client.testString('Python'), 'Python')
-class NormalBinaryTest(AbstractTest):
+class MultiplexedOptionalTest(AbstractTest):
+ def get_protocol2(self, transport):
+ return None
+
+
+class BinaryTest(MultiplexedOptionalTest):
def get_protocol(self, transport):
return TBinaryProtocol.TBinaryProtocolFactory().getProtocol(transport)
-class CompactTest(AbstractTest):
+class MultiplexedBinaryTest(MultiplexedOptionalTest):
def get_protocol(self, transport):
- return TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
+ wrapped_proto = TBinaryProtocol.TBinaryProtocolFactory().getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
+
+ def get_protocol2(self, transport):
+ wrapped_proto = TBinaryProtocol.TBinaryProtocolFactory().getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
-class JSONTest(AbstractTest):
- def get_protocol(self, transport):
- return TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
-
-
-class AcceleratedBinaryTest(AbstractTest):
+class AcceleratedBinaryTest(MultiplexedOptionalTest):
def get_protocol(self, transport):
return TBinaryProtocol.TBinaryProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
-class AcceleratedCompactTest(AbstractTest):
+class MultiplexedAcceleratedBinaryTest(MultiplexedOptionalTest):
+ def get_protocol(self, transport):
+ wrapped_proto = TBinaryProtocol.TBinaryProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
+
+ def get_protocol2(self, transport):
+ wrapped_proto = TBinaryProtocol.TBinaryProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
+
+
+class CompactTest(MultiplexedOptionalTest):
+ def get_protocol(self, transport):
+ return TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
+
+
+class MultiplexedCompactTest(MultiplexedOptionalTest):
+ def get_protocol(self, transport):
+ wrapped_proto = TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
+
+ def get_protocol2(self, transport):
+ wrapped_proto = TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
+
+
+class AcceleratedCompactTest(MultiplexedOptionalTest):
def get_protocol(self, transport):
return TCompactProtocol.TCompactProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
+class MultiplexedAcceleratedCompactTest(MultiplexedOptionalTest):
+ def get_protocol(self, transport):
+ wrapped_proto = TCompactProtocol.TCompactProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
+
+ def get_protocol2(self, transport):
+ wrapped_proto = TCompactProtocol.TCompactProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
+
+
+class JSONTest(MultiplexedOptionalTest):
+ def get_protocol(self, transport):
+ return TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
+
+
+class MultiplexedJSONTest(MultiplexedOptionalTest):
+ def get_protocol(self, transport):
+ wrapped_proto = TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
+
+ def get_protocol2(self, transport):
+ wrapped_proto = TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
+ return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
+
+
def suite():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
if options.proto == 'binary': # look for --proto on cmdline
- suite.addTest(loader.loadTestsFromTestCase(NormalBinaryTest))
+ suite.addTest(loader.loadTestsFromTestCase(BinaryTest))
elif options.proto == 'accel':
suite.addTest(loader.loadTestsFromTestCase(AcceleratedBinaryTest))
- elif options.proto == 'compact':
- suite.addTest(loader.loadTestsFromTestCase(CompactTest))
elif options.proto == 'accelc':
suite.addTest(loader.loadTestsFromTestCase(AcceleratedCompactTest))
+ elif options.proto == 'compact':
+ suite.addTest(loader.loadTestsFromTestCase(CompactTest))
elif options.proto == 'json':
suite.addTest(loader.loadTestsFromTestCase(JSONTest))
+ elif options.proto == 'multi':
+ suite.addTest(loader.loadTestsFromTestCase(MultiplexedBinaryTest))
+ elif options.proto == 'multia':
+ suite.addTest(loader.loadTestsFromTestCase(MultiplexedAcceleratedBinaryTest))
+ elif options.proto == 'multiac':
+ suite.addTest(loader.loadTestsFromTestCase(MultiplexedAcceleratedCompactTest))
+ elif options.proto == 'multic':
+ suite.addTest(loader.loadTestsFromTestCase(MultiplexedCompactTest))
+ elif options.proto == 'multij':
+ suite.addTest(loader.loadTestsFromTestCase(MultiplexedJSONTest))
else:
raise AssertionError('Unknown protocol given with --protocol: %s' % options.proto)
return suite
@@ -335,7 +408,7 @@
dest="verbose", const=0,
help="minimal output")
parser.add_option('--protocol', dest="proto", type="string",
- help="protocol to use, one of: accel, accelc, binary, compact, json")
+ help="protocol to use, one of: accel, accelc, binary, compact, json, multi, multia, multiac, multic, multij")
parser.add_option('--transport', dest="trans", type="string",
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')
@@ -348,6 +421,7 @@
if options.http_path:
options.trans = 'http'
+ from ThriftTest import SecondService
from ThriftTest import ThriftTest
from ThriftTest.ttypes import Xtruct, Xtruct2, Numberz, Xception, Xception2
from thrift.Thrift import TException
@@ -358,5 +432,6 @@
from thrift.protocol import TBinaryProtocol
from thrift.protocol import TCompactProtocol
from thrift.protocol import TJSONProtocol
+ from thrift.protocol import TMultiplexedProtocol
OwnArgsTestProgram(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=1))