Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Jens Geyer | 72a714e | 2025-08-26 22:12:07 +0200 | [diff] [blame^] | 3 | # |
| 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 Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 22 | import argparse |
| 23 | import sys |
| 24 | |
| 25 | from util import add_common_args, init_protocol |
Nobuaki Sukegawa | d479e23 | 2016-02-28 11:28:19 +0900 | [diff] [blame] | 26 | from local_thrift import thrift # noqa |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 27 | from thrift.Thrift import TMessageType, TType |
| 28 | |
| 29 | |
| 30 | # TODO: generate from ThriftTest.thrift |
| 31 | def test_string(proto, value): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 32 | method_name = 'testString' |
| 33 | ttype = TType.STRING |
| 34 | proto.writeMessageBegin(method_name, TMessageType.CALL, 3) |
| 35 | proto.writeStructBegin(method_name + '_args') |
| 36 | proto.writeFieldBegin('thing', ttype, 1) |
| 37 | proto.writeString(value) |
| 38 | proto.writeFieldEnd() |
| 39 | proto.writeFieldStop() |
| 40 | proto.writeStructEnd() |
| 41 | proto.writeMessageEnd() |
| 42 | proto.trans.flush() |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 43 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 44 | _, mtype, _ = proto.readMessageBegin() |
| 45 | assert mtype == TMessageType.REPLY |
| 46 | proto.readStructBegin() |
| 47 | _, ftype, fid = proto.readFieldBegin() |
| 48 | assert fid == 0 |
| 49 | assert ftype == ttype |
| 50 | result = proto.readString() |
| 51 | proto.readFieldEnd() |
| 52 | _, ftype, _ = proto.readFieldBegin() |
| 53 | assert ftype == TType.STOP |
| 54 | proto.readStructEnd() |
| 55 | proto.readMessageEnd() |
| 56 | assert value == result |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 57 | |
| 58 | |
| 59 | def main(argv): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 60 | p = argparse.ArgumentParser() |
| 61 | add_common_args(p) |
| 62 | p.add_argument('--limit', type=int) |
| 63 | args = p.parse_args() |
| 64 | proto = init_protocol(args) |
| 65 | test_string(proto, 'a' * (args.limit - 1)) |
| 66 | test_string(proto, 'a' * (args.limit - 1)) |
| 67 | print('[OK]: limit - 1') |
| 68 | test_string(proto, 'a' * args.limit) |
| 69 | test_string(proto, 'a' * args.limit) |
| 70 | print('[OK]: just limit') |
| 71 | try: |
| 72 | test_string(proto, 'a' * (args.limit + 1)) |
James E. King, III | 350fe75 | 2017-10-25 09:57:18 -0400 | [diff] [blame] | 73 | except Exception: |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 74 | print('[OK]: limit + 1') |
| 75 | else: |
| 76 | print('[ERROR]: limit + 1') |
| 77 | assert False |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 78 | |
James E. King, III | 0ad20bd | 2017-09-30 15:44:16 -0700 | [diff] [blame] | 79 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 80 | if __name__ == '__main__': |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 81 | main(sys.argv[1:]) |