blob: cdf09931b28e896095c5b460cbc1deffc4068c02 [file] [log] [blame]
Nobuaki Sukegawa85650612016-01-08 03:26:44 +09001#!/usr/bin/env python
2
Jens Geyer72a714e2025-08-26 22:12:07 +02003#
4# Licensed to the Apache Software Foundation (ASF) under one
5# or more contributor license agreements. See the NOTICE file
6# distributed with this work for additional information
7# regarding copyright ownership. The ASF licenses this file
8# to you under the Apache License, Version 2.0 (the
9# "License"); you may not use this file except in compliance
10# with the License. You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17# KIND, either express or implied. See the License for the
18# specific language governing permissions and limitations
19# under the License.
20#
21
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090022import argparse
23import sys
24
25from util import add_common_args, init_protocol
Nobuaki Sukegawad479e232016-02-28 11:28:19 +090026from local_thrift import thrift # noqa
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090027from thrift.Thrift import TMessageType, TType
28
29
30# TODO: generate from ThriftTest.thrift
31def test_list(proto, value):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090032 method_name = 'testList'
33 ttype = TType.LIST
34 etype = TType.I32
35 proto.writeMessageBegin(method_name, TMessageType.CALL, 3)
36 proto.writeStructBegin(method_name + '_args')
37 proto.writeFieldBegin('thing', ttype, 1)
38 proto.writeListBegin(etype, len(value))
39 for e in value:
40 proto.writeI32(e)
41 proto.writeListEnd()
42 proto.writeFieldEnd()
43 proto.writeFieldStop()
44 proto.writeStructEnd()
45 proto.writeMessageEnd()
46 proto.trans.flush()
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090047
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090048 _, mtype, _ = proto.readMessageBegin()
49 assert mtype == TMessageType.REPLY
50 proto.readStructBegin()
51 _, ftype, fid = proto.readFieldBegin()
52 assert fid == 0
53 assert ftype == ttype
54 etype2, len2 = proto.readListBegin()
55 assert etype == etype2
56 assert len2 == len(value)
57 for i in range(len2):
58 v = proto.readI32()
59 assert v == value[i]
60 proto.readListEnd()
61 proto.readFieldEnd()
62 _, ftype, _ = proto.readFieldBegin()
63 assert ftype == TType.STOP
64 proto.readStructEnd()
65 proto.readMessageEnd()
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090066
67
68def main(argv):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090069 p = argparse.ArgumentParser()
70 add_common_args(p)
71 p.add_argument('--limit', type=int)
72 args = p.parse_args()
73 proto = init_protocol(args)
74 # TODO: test set and map
75 test_list(proto, list(range(args.limit - 1)))
76 test_list(proto, list(range(args.limit - 1)))
77 print('[OK]: limit - 1')
78 test_list(proto, list(range(args.limit)))
79 test_list(proto, list(range(args.limit)))
80 print('[OK]: just limit')
81 try:
82 test_list(proto, list(range(args.limit + 1)))
James E. King, III350fe752017-10-25 09:57:18 -040083 except Exception:
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090084 print('[OK]: limit + 1')
85 else:
86 print('[ERROR]: limit + 1')
87 assert False
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090088
89
90if __name__ == '__main__':
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090091 sys.exit(main(sys.argv[1:]))