blob: 0316741bc8b44a067405f3a5f7948aa957fc2b4b [file] [log] [blame]
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +09001#!/usr/bin/env python
2
3import argparse
4import socket
5import sys
6
7from util import add_common_args
8from local_thrift import thrift
9from thrift.Thrift import TMessageType, TType
10from thrift.transport.TSocket import TSocket
11from thrift.transport.TTransport import TBufferedTransport, TFramedTransport
12from thrift.protocol.TBinaryProtocol import TBinaryProtocol
13
14
15# THeader stack should accept binary protocol with optionally framed transport
16def main(argv):
17 p = argparse.ArgumentParser()
18 add_common_args(p)
19 # Since THeaderTransport acts as framed transport when detected frame, we
20 # cannot use --transport=framed as it would result in 2 layered frames.
21 p.add_argument('--override-transport')
22 args = p.parse_args()
23 assert args.protocol == 'header'
24 assert args.transport == 'buffered'
25 assert not args.ssl
26
27 sock = TSocket(args.host, args.port, socket_family=socket.AF_INET)
28 if not args.override_transport or args.override_transport == 'buffered':
29 trans = TBufferedTransport(sock)
30 elif args.override_transport == 'framed':
31 trans = TFramedTransport(sock)
32 else:
33 raise ValueError('invalid transport')
34 trans.open()
35 proto = TBinaryProtocol(trans)
36 proto.writeMessageBegin('testVoid', TMessageType.CALL, 3)
37 proto.writeStructBegin('testVoid_args')
38 proto.writeFieldStop()
39 proto.writeStructEnd()
40 proto.writeMessageEnd()
41 trans.flush()
42
43 _, mtype, _ = proto.readMessageBegin()
44 assert mtype == TMessageType.REPLY
45 proto.readStructBegin()
46 _, ftype, _ = proto.readFieldBegin()
47 assert ftype == TType.STOP
48 proto.readFieldEnd()
49 proto.readStructEnd()
50 proto.readMessageEnd()
51
52 trans.close()
53
54
55if __name__ == '__main__':
56 sys.exit(main(sys.argv[1:]))