Roger Meier | 32f3982 | 2014-06-18 22:43:17 +0200 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 2 | # encoding: utf-8 |
Roger Meier | 32f3982 | 2014-06-18 22:43:17 +0200 | [diff] [blame] | 3 | |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 4 | # |
| 5 | # Licensed to the Apache Software Foundation (ASF) under one |
| 6 | # or more contributor license agreements. See the NOTICE file |
| 7 | # distributed with this work for additional information |
| 8 | # regarding copyright ownership. The ASF licenses this file |
| 9 | # to you under the Apache License, Version 2.0 (the |
| 10 | # "License"); you may not use this file except in compliance |
| 11 | # with the License. You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, |
| 16 | # software distributed under the License is distributed on an |
| 17 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 18 | # KIND, either express or implied. See the License for the |
| 19 | # specific language governing permissions and limitations |
| 20 | # under the License. |
| 21 | # |
| 22 | |
Roger Meier | c95d5df | 2014-01-19 21:53:02 +0100 | [diff] [blame] | 23 | $:.push File.dirname(__FILE__) + '/..' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 24 | |
Roger Meier | c95d5df | 2014-01-19 21:53:02 +0100 | [diff] [blame] | 25 | require 'test_helper' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 26 | require 'thrift' |
Roger Meier | c95d5df | 2014-01-19 21:53:02 +0100 | [diff] [blame] | 27 | require 'thrift_test' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 28 | |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 29 | $protocolType = "binary" |
| 30 | $host = "localhost" |
| 31 | $port = 9090 |
| 32 | $transport = "buffered" |
| 33 | ARGV.each do|a| |
| 34 | if a == "--help" |
| 35 | puts "Allowed options:" |
| 36 | puts "\t -h [ --help ] \t produce help message" |
| 37 | puts "\t--host arg (=localhost) \t Host to connect" |
| 38 | puts "\t--port arg (=9090) \t Port number to listen" |
| 39 | puts "\t--protocol arg (=binary) \t protocol: binary, accel" |
| 40 | puts "\t--transport arg (=buffered) transport: buffered, framed, http" |
| 41 | exit |
| 42 | elsif a.start_with?("--host") |
| 43 | $host = a.split("=")[1] |
| 44 | elsif a.start_with?("--protocol") |
| 45 | $protocolType = a.split("=")[1] |
| 46 | elsif a.start_with?("--transport") |
| 47 | $transport = a.split("=")[1] |
| 48 | elsif a.start_with?("--port") |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 49 | $port = a.split("=")[1].to_i |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 50 | end |
| 51 | end |
| 52 | ARGV=[] |
| 53 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 54 | class SimpleClientTest < Test::Unit::TestCase |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 55 | def setup |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 56 | unless @socket |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 57 | @socket = Thrift::Socket.new($host, $port) |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 58 | if $transport == "buffered" |
| 59 | transportFactory = Thrift::BufferedTransport.new(@socket) |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 60 | elsif $transport == "framed" |
| 61 | transportFactory = Thrift::FramedTransport.new(@socket) |
| 62 | else |
| 63 | raise 'Unknown transport type' |
| 64 | end |
| 65 | |
| 66 | if $protocolType == "binary" |
| 67 | @protocol = Thrift::BinaryProtocol.new(transportFactory) |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 68 | elsif $protocolType == "compact" |
| 69 | @protocol = Thrift::CompactProtocol.new(transportFactory) |
| 70 | elsif $protocolType == "json" |
| 71 | @protocol = Thrift::JsonProtocol.new(transportFactory) |
| 72 | elsif $protocolType == "accel" |
| 73 | @protocol = Thrift::BinaryProtocolAccelerated.new(transportFactory) |
| 74 | else |
| 75 | raise 'Unknown protocol type' |
| 76 | end |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 77 | @client = Thrift::Test::ThriftTest::Client.new(@protocol) |
| 78 | @socket.open |
| 79 | end |
| 80 | end |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 81 | |
| 82 | def teardown |
| 83 | @socket.close |
| 84 | end |
| 85 | |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 86 | def test_void |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 87 | p 'test_void' |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 88 | @client.testVoid() |
| 89 | end |
| 90 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 91 | def test_string |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 92 | p 'test_string' |
Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 93 | test_string = |
| 94 | 'quote: \" backslash:' + |
| 95 | ' forwardslash-escaped: \/ ' + |
| 96 | ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + |
| 97 | ' now-all-of-them-together: "\\\/\b\n\r\t' + |
| 98 | ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' + |
| 99 | ' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ' |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 100 | test_string = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " + |
| 101 | "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " + |
| 102 | "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " + |
| 103 | "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " + |
| 104 | "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " + |
| 105 | "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " + |
| 106 | "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " + |
| 107 | "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " + |
| 108 | "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " + |
| 109 | "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " + |
| 110 | "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " + |
| 111 | "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " + |
| 112 | "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " + |
| 113 | "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " + |
| 114 | "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " + |
| 115 | "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " + |
| 116 | "Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " + |
| 117 | "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " + |
| 118 | "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " + |
| 119 | "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " + |
| 120 | "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " + |
| 121 | "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " + |
| 122 | "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " + |
| 123 | "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " + |
| 124 | "Bân-lâm-gú, 粵語" |
Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 125 | |
| 126 | result_string = @client.testString(test_string) |
| 127 | assert_equal(test_string, result_string.force_encoding(Encoding::UTF_8)) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 128 | end |
| 129 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 130 | def test_bool |
| 131 | p 'test_bool' |
| 132 | assert_equal(@client.testBool(true), true) |
| 133 | assert_equal(@client.testBool(false), false) |
| 134 | end |
| 135 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 136 | def test_byte |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 137 | p 'test_byte' |
| 138 | val = 120 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 139 | assert_equal(@client.testByte(val), val) |
| 140 | assert_equal(@client.testByte(-val), -val) |
| 141 | end |
| 142 | |
| 143 | def test_i32 |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 144 | p 'test_i32' |
| 145 | val = 2000000032 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 146 | assert_equal(@client.testI32(val), val) |
| 147 | assert_equal(@client.testI32(-val), -val) |
| 148 | end |
| 149 | |
| 150 | def test_i64 |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 151 | p 'test_i64' |
| 152 | val = 9000000000000000064 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 153 | assert_equal(@client.testI64(val), val) |
| 154 | assert_equal(@client.testI64(-val), -val) |
| 155 | end |
| 156 | |
| 157 | def test_double |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 158 | p 'test_double' |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 159 | val = 3.14159265358979323846 |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 160 | assert_equal(@client.testDouble(val), val) |
| 161 | assert_equal(@client.testDouble(-val), -val) |
| 162 | assert_kind_of(Float, @client.testDouble(val)) |
| 163 | end |
| 164 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 165 | def test_binary |
| 166 | p 'test_binary' |
Jens Geyer | 123258b | 2015-10-02 00:38:17 +0200 | [diff] [blame] | 167 | val = (0...256).reverse_each.to_a |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 168 | ret = @client.testBinary(val.pack('C*')) |
| 169 | assert_equal(val, ret.bytes.to_a) |
| 170 | end |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 171 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 172 | def test_map |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 173 | p 'test_map' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 174 | val = {1 => 1, 2 => 2, 3 => 3} |
| 175 | assert_equal(@client.testMap(val), val) |
| 176 | assert_kind_of(Hash, @client.testMap(val)) |
| 177 | end |
| 178 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 179 | def test_string_map |
| 180 | p 'test_string_map' |
| 181 | val = {'a' => '2', 'b' => 'blah', 'some' => 'thing'} |
| 182 | ret = @client.testStringMap(val) |
| 183 | assert_equal(val, ret) |
| 184 | assert_kind_of(Hash, ret) |
| 185 | end |
| 186 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 187 | def test_list |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 188 | p 'test_list' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 189 | val = [1,2,3,4,5] |
| 190 | assert_equal(@client.testList(val), val) |
| 191 | assert_kind_of(Array, @client.testList(val)) |
| 192 | end |
| 193 | |
| 194 | def test_enum |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 195 | p 'test_enum' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 196 | val = Thrift::Test::Numberz::SIX |
| 197 | ret = @client.testEnum(val) |
| 198 | |
| 199 | assert_equal(ret, 6) |
| 200 | assert_kind_of(Fixnum, ret) |
| 201 | end |
| 202 | |
| 203 | def test_typedef |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 204 | p 'test_typedef' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 205 | #UserId testTypedef(1: UserId thing), |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 206 | assert_equal(@client.testTypedef(309858235082523), 309858235082523) |
| 207 | assert_kind_of(Fixnum, @client.testTypedef(309858235082523)) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 208 | true |
| 209 | end |
| 210 | |
| 211 | def test_set |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 212 | p 'test_set' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 213 | val = Set.new([1,2,3]) |
| 214 | assert_equal(@client.testSet(val), val) |
| 215 | assert_kind_of(Set, @client.testSet(val)) |
| 216 | end |
| 217 | |
| 218 | def get_struct |
| 219 | Thrift::Test::Xtruct.new({'string_thing' => 'hi!', 'i32_thing' => 4 }) |
| 220 | end |
| 221 | |
| 222 | def test_struct |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 223 | p 'test_struct' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 224 | ret = @client.testStruct(get_struct) |
| 225 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 226 | # TODO: not sure what unspecified "default" requiredness values should be |
| 227 | assert(ret.byte_thing == nil || ret.byte_thing == 0) |
| 228 | assert(ret.i64_thing == nil || ret.i64_thing == 0) |
| 229 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 230 | assert_equal(ret.string_thing, 'hi!') |
| 231 | assert_equal(ret.i32_thing, 4) |
| 232 | assert_kind_of(Thrift::Test::Xtruct, ret) |
| 233 | end |
| 234 | |
| 235 | def test_nest |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 236 | p 'test_nest' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 237 | struct2 = Thrift::Test::Xtruct2.new({'struct_thing' => get_struct, 'i32_thing' => 10}) |
| 238 | |
| 239 | ret = @client.testNest(struct2) |
| 240 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 241 | # TODO: not sure what unspecified "default" requiredness values should be |
| 242 | assert(ret.struct_thing.byte_thing == nil || ret.struct_thing.byte_thing == 0) |
| 243 | assert(ret.struct_thing.i64_thing == nil || ret.struct_thing.i64_thing == 0) |
| 244 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 245 | assert_equal(ret.struct_thing.string_thing, 'hi!') |
| 246 | assert_equal(ret.struct_thing.i32_thing, 4) |
| 247 | assert_equal(ret.i32_thing, 10) |
| 248 | |
| 249 | assert_kind_of(Thrift::Test::Xtruct, ret.struct_thing) |
| 250 | assert_kind_of(Thrift::Test::Xtruct2, ret) |
| 251 | end |
| 252 | |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 253 | def test_insanity |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 254 | p 'test_insanity' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 255 | insane = Thrift::Test::Insanity.new({ |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 256 | 'userMap' => { |
| 257 | Thrift::Test::Numberz::FIVE => 5, |
| 258 | Thrift::Test::Numberz::EIGHT => 8, |
| 259 | }, |
| 260 | 'xtructs' => [ |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 261 | Thrift::Test::Xtruct.new({ |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 262 | 'string_thing' => 'Goodbye4', |
| 263 | 'byte_thing' => 4, |
| 264 | 'i32_thing' => 4, |
| 265 | 'i64_thing' => 4, |
| 266 | }), |
| 267 | Thrift::Test::Xtruct.new({ |
| 268 | 'string_thing' => 'Hello2', |
| 269 | 'byte_thing' => 2, |
| 270 | 'i32_thing' => 2, |
| 271 | 'i64_thing' => 2, |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 272 | }) |
| 273 | ] |
| 274 | }) |
| 275 | |
| 276 | ret = @client.testInsanity(insane) |
| 277 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 278 | assert_equal(insane, ret[1][2]) |
| 279 | assert_equal(insane, ret[1][3]) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 280 | |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 281 | assert(ret[2][6].userMap == nil || ret[2][6].userMap.length == 0) |
| 282 | assert(ret[2][6].xtructs == nil || ret[2][6].xtructs.length == 0) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 283 | end |
| 284 | |
| 285 | def test_map_map |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 286 | p 'test_map_map' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 287 | ret = @client.testMapMap(4) |
| 288 | assert_kind_of(Hash, ret) |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 289 | expected = { |
| 290 | -4 => { |
| 291 | -4 => -4, |
| 292 | -3 => -3, |
| 293 | -2 => -2, |
| 294 | -1 => -1, |
| 295 | }, |
| 296 | 4 => { |
| 297 | 4 => 4, |
| 298 | 3 => 3, |
| 299 | 2 => 2, |
| 300 | 1 => 1, |
| 301 | } |
| 302 | } |
| 303 | assert_equal(expected, ret) |
| 304 | end |
| 305 | |
| 306 | def test_multi |
| 307 | p 'test_multi' |
| 308 | ret = @client.testMulti(42, 4242, 424242, {1 => 'blah', 2 => 'thing'}, Thrift::Test::Numberz::EIGHT, 24) |
| 309 | expected = Thrift::Test::Xtruct.new({ |
| 310 | :string_thing => 'Hello2', |
| 311 | :byte_thing => 42, |
| 312 | :i32_thing => 4242, |
| 313 | :i64_thing => 424242 |
| 314 | }) |
| 315 | assert_equal(expected, ret) |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 316 | end |
| 317 | |
| 318 | def test_exception |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 319 | p 'test_exception' |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 320 | assert_raise Thrift::Test::Xception do |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 321 | @client.testException('Xception') |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 322 | end |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 323 | begin |
| 324 | @client.testException('TException') |
| 325 | rescue => e |
| 326 | assert e.class.ancestors.include?(Thrift::Exception) |
| 327 | end |
| 328 | assert_nothing_raised do |
| 329 | @client.testException('test') |
| 330 | end |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 331 | end |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 332 | |
| 333 | def test_multi_exception |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 334 | p 'test_multi_exception' |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 335 | assert_raise Thrift::Test::Xception do |
| 336 | @client.testMultiException("Xception", "test 1") |
| 337 | end |
| 338 | assert_raise Thrift::Test::Xception2 do |
| 339 | @client.testMultiException("Xception2", "test 2") |
| 340 | end |
| 341 | assert_equal( @client.testMultiException("Success", "test 3").string_thing, "test 3") |
| 342 | end |
| 343 | |
| 344 | def test_oneway |
Nobuaki Sukegawa | 6823829 | 2015-09-21 23:28:22 +0900 | [diff] [blame] | 345 | p 'test_oneway' |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 346 | time1 = Time.now.to_f |
Nobuaki Sukegawa | a6ab1f5 | 2015-11-28 15:04:39 +0900 | [diff] [blame] | 347 | @client.testOneway(1) |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 348 | time2 = Time.now.to_f |
Nobuaki Sukegawa | a6ab1f5 | 2015-11-28 15:04:39 +0900 | [diff] [blame] | 349 | assert_operator (time2-time1), :<, 0.1 |
Roger Meier | a3570ac | 2014-06-10 22:16:14 +0200 | [diff] [blame] | 350 | end |
| 351 | |
Kevin Clark | 4bd8916 | 2008-07-08 00:47:49 +0000 | [diff] [blame] | 352 | end |
| 353 | |