2016-01-03 08:04:50 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import socket
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from util import add_common_args
|
2016-02-28 02:28:19 +00:00
|
|
|
from local_thrift import thrift # noqa
|
2016-01-03 08:04:50 +00:00
|
|
|
from thrift.Thrift import TMessageType, TType
|
|
|
|
from thrift.transport.TSocket import TSocket
|
|
|
|
from thrift.transport.TTransport import TBufferedTransport, TFramedTransport
|
|
|
|
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
|
2016-01-23 16:03:28 +00:00
|
|
|
from thrift.protocol.TCompactProtocol import TCompactProtocol
|
|
|
|
|
|
|
|
|
|
|
|
def test_void(proto):
|
2016-02-02 16:57:03 +00:00
|
|
|
proto.writeMessageBegin('testVoid', TMessageType.CALL, 3)
|
|
|
|
proto.writeStructBegin('testVoid_args')
|
|
|
|
proto.writeFieldStop()
|
|
|
|
proto.writeStructEnd()
|
|
|
|
proto.writeMessageEnd()
|
|
|
|
proto.trans.flush()
|
2016-01-23 16:03:28 +00:00
|
|
|
|
2016-02-02 16:57:03 +00:00
|
|
|
_, mtype, _ = proto.readMessageBegin()
|
|
|
|
assert mtype == TMessageType.REPLY
|
|
|
|
proto.readStructBegin()
|
|
|
|
_, ftype, _ = proto.readFieldBegin()
|
|
|
|
assert ftype == TType.STOP
|
|
|
|
proto.readStructEnd()
|
|
|
|
proto.readMessageEnd()
|
2016-01-03 08:04:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
# THeader stack should accept binary protocol with optionally framed transport
|
|
|
|
def main(argv):
|
2016-02-02 16:57:03 +00:00
|
|
|
p = argparse.ArgumentParser()
|
|
|
|
add_common_args(p)
|
|
|
|
# Since THeaderTransport acts as framed transport when detected frame, we
|
|
|
|
# cannot use --transport=framed as it would result in 2 layered frames.
|
|
|
|
p.add_argument('--override-transport')
|
|
|
|
p.add_argument('--override-protocol')
|
|
|
|
args = p.parse_args()
|
|
|
|
assert args.protocol == 'header'
|
|
|
|
assert args.transport == 'buffered'
|
|
|
|
assert not args.ssl
|
2016-01-03 08:04:50 +00:00
|
|
|
|
2016-02-02 16:57:03 +00:00
|
|
|
sock = TSocket(args.host, args.port, socket_family=socket.AF_INET)
|
|
|
|
if not args.override_transport or args.override_transport == 'buffered':
|
|
|
|
trans = TBufferedTransport(sock)
|
|
|
|
elif args.override_transport == 'framed':
|
|
|
|
print('TFRAMED')
|
|
|
|
trans = TFramedTransport(sock)
|
|
|
|
else:
|
|
|
|
raise ValueError('invalid transport')
|
|
|
|
trans.open()
|
2016-01-03 08:04:50 +00:00
|
|
|
|
2016-02-02 16:57:03 +00:00
|
|
|
if not args.override_protocol or args.override_protocol == 'binary':
|
|
|
|
proto = TBinaryProtocol(trans)
|
|
|
|
elif args.override_protocol == 'compact':
|
|
|
|
proto = TCompactProtocol(trans)
|
|
|
|
else:
|
|
|
|
raise ValueError('invalid transport')
|
2016-01-23 16:03:28 +00:00
|
|
|
|
2016-02-02 16:57:03 +00:00
|
|
|
test_void(proto)
|
|
|
|
test_void(proto)
|
2016-01-03 08:04:50 +00:00
|
|
|
|
2016-02-02 16:57:03 +00:00
|
|
|
trans.close()
|
2016-01-03 08:04:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-02-02 16:57:03 +00:00
|
|
|
sys.exit(main(sys.argv[1:]))
|