Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | |
| 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 | |
James E. King, III | 177c37c | 2017-03-30 17:09:04 -0400 | [diff] [blame] | 22 | use 5.10.0; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 23 | use strict; |
| 24 | use warnings; |
| 25 | use Data::Dumper; |
| 26 | use Getopt::Long qw(GetOptions); |
| 27 | use Time::HiRes qw(gettimeofday); |
| 28 | |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 29 | $SIG{INT} = \&sigint_handler; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 30 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 31 | use lib '../../lib/perl/lib'; |
| 32 | use lib 'gen-perl'; |
| 33 | |
| 34 | use Thrift; |
| 35 | use Thrift::BinaryProtocol; |
| 36 | use Thrift::BufferedTransport; |
| 37 | use Thrift::FramedTransport; |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 38 | use Thrift::MultiplexedProcessor; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 39 | use Thrift::SSLServerSocket; |
| 40 | use Thrift::ServerSocket; |
| 41 | use Thrift::Server; |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 42 | use Thrift::UnixServerSocket; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 43 | |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 44 | use ThriftTest::SecondService; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 45 | use ThriftTest::ThriftTest; |
| 46 | use ThriftTest::Types; |
| 47 | |
| 48 | $|++; |
| 49 | |
| 50 | sub usage { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 51 | print <<"EOF"; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 52 | Usage: $0 [OPTIONS] |
| 53 | |
| 54 | Options: (default) |
| 55 | --ca Certificate authority file (optional). |
| 56 | --cert Certificate file. |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 57 | Required if using --ssl. |
| 58 | --ciphers Acceptable cipher list. |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 59 | --domain-socket <file> Use a unix domain socket. |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 60 | --help Show usage. |
| 61 | --key Private key file for certificate. |
| 62 | Required if using --ssl and private key is |
| 63 | not in the certificate file. |
| 64 | --port <portnum> 9090 Port to use. |
| 65 | --protocol {binary} binary Protocol to use. |
| 66 | --ssl If present, use SSL/TLS. |
| 67 | --transport {buffered|framed} buffered Transport to use. |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 68 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 69 | EOF |
| 70 | } |
| 71 | |
| 72 | my %opts = ( |
| 73 | 'port' => 9090, |
| 74 | 'protocol' => 'binary', |
| 75 | 'transport' => 'buffered' |
| 76 | ); |
| 77 | |
| 78 | GetOptions(\%opts, qw ( |
| 79 | ca=s |
| 80 | cert=s |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 81 | ciphers=s |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 82 | domain-socket=s |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 83 | help |
| 84 | host=s |
| 85 | key=s |
| 86 | port=i |
| 87 | protocol=s |
| 88 | ssl |
| 89 | transport=s |
| 90 | )) || exit 1; |
| 91 | |
| 92 | if ($opts{help}) { |
| 93 | usage(); |
| 94 | exit 0; |
| 95 | } |
| 96 | |
| 97 | if ($opts{ssl} and not defined $opts{cert}) { |
| 98 | usage(); |
| 99 | exit 1; |
| 100 | } |
| 101 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 102 | my $handler = ThriftTestHandler->new(); |
| 103 | my $handler2 = SecondServiceHandler->new(); |
| 104 | my $processor = ThriftTest::ThriftTestProcessor->new($handler); |
| 105 | my $processor2 = ThriftTest::SecondServiceProcessor->new($handler2); |
| 106 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 107 | my $serversocket; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 108 | if ($opts{'domain-socket'}) { |
| 109 | unlink($opts{'domain-socket'}); |
| 110 | $serversocket = Thrift::UnixServerSocket->new($opts{'domain-socket'}); |
| 111 | } |
| 112 | elsif ($opts{ssl}) { |
| 113 | $serversocket = Thrift::SSLServerSocket->new(\%opts); |
| 114 | } |
| 115 | else { |
| 116 | $serversocket = Thrift::ServerSocket->new(\%opts); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 117 | } |
| 118 | my $transport; |
| 119 | if ($opts{transport} eq 'buffered') { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 120 | $transport = Thrift::BufferedTransportFactory->new(); |
| 121 | } |
| 122 | elsif ($opts{transport} eq 'framed') { |
| 123 | $transport = Thrift::FramedTransportFactory->new(); |
| 124 | } |
| 125 | else { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 126 | usage(); |
| 127 | exit 1; |
| 128 | } |
| 129 | my $protocol; |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 130 | if ($opts{protocol} eq 'binary' || $opts{protocol} eq 'multi') { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 131 | $protocol = Thrift::BinaryProtocolFactory->new(); |
| 132 | } |
| 133 | else { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 134 | usage(); |
| 135 | exit 1; |
| 136 | } |
| 137 | |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 138 | if (index($opts{protocol}, 'multi') == 0) { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 139 | my $newProcessor = Thrift::MultiplexedProcessor->new($protocol); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 140 | $newProcessor->defaultProcessor($processor); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 141 | $newProcessor->registerProcessor('ThriftTest', $processor); |
| 142 | $newProcessor->registerProcessor('SecondService', $processor2); |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 143 | $processor = $newProcessor; |
| 144 | } |
| 145 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 146 | my $ssltag = ''; |
| 147 | if ($opts{ssl}) { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 148 | $ssltag = '(SSL)'; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 149 | } |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 150 | my $listening_on = "$opts{port} $ssltag"; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 151 | if ($opts{'domain-socket'}) { |
| 152 | $listening_on = $opts{'domain-socket'}; |
James E. King, III | 49f4dc0 | 2015-10-29 15:52:23 -0400 | [diff] [blame] | 153 | } |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 154 | my $server = Thrift::SimpleServer->new($processor, $serversocket, $transport, $protocol); |
| 155 | print qq|Starting "simple" server ($opts{transport}/$opts{protocol}) listen on: $listening_on\n|; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 156 | $server->serve(); |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 157 | print "done.\n"; |
| 158 | |
| 159 | sub sigint_handler { |
| 160 | print "received SIGINT, stopping...\n"; |
| 161 | $server->stop(); |
| 162 | } |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 163 | |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 164 | ### |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 165 | ### Test server implementation |
| 166 | ### |
| 167 | |
| 168 | package ThriftTestHandler; |
| 169 | |
| 170 | use base qw( ThriftTest::ThriftTestIf ); |
| 171 | |
| 172 | sub new { |
| 173 | my $classname = shift; |
| 174 | my $self = {}; |
| 175 | return bless($self, $classname); |
| 176 | } |
| 177 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 178 | sub testVoid { |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 179 | print("testVoid()\n"); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 182 | sub testString { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 183 | my $self = shift; |
| 184 | my $thing = shift; |
| 185 | print("testString($thing)\n"); |
| 186 | return $thing; |
| 187 | } |
| 188 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 189 | sub testBool { |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 190 | my $self = shift; |
| 191 | my $thing = shift; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 192 | my $str = $thing ? 'true' : 'false'; |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 193 | print("testBool($str)\n"); |
| 194 | return $thing; |
| 195 | } |
| 196 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 197 | sub testByte { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 198 | my $self = shift; |
| 199 | my $thing = shift; |
| 200 | print("testByte($thing)\n"); |
| 201 | return $thing; |
| 202 | } |
| 203 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 204 | sub testI32 { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 205 | my $self = shift; |
| 206 | my $thing = shift; |
| 207 | print("testI32($thing)\n"); |
| 208 | return $thing; |
| 209 | } |
| 210 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 211 | sub testI64 { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 212 | my $self = shift; |
| 213 | my $thing = shift; |
| 214 | print("testI64($thing)\n"); |
| 215 | return $thing; |
| 216 | } |
| 217 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 218 | sub testDouble { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 219 | my $self = shift; |
| 220 | my $thing = shift; |
| 221 | print("testDouble($thing)\n"); |
| 222 | return $thing; |
| 223 | } |
| 224 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 225 | sub testBinary { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 226 | my $self = shift; |
| 227 | my $thing = shift; |
| 228 | my @bytes = split //, $thing; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 229 | print 'testBinary('; |
| 230 | printf( '%02lx', ord $_ ) foreach (@bytes); |
| 231 | print ")\n"; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 232 | return $thing; |
| 233 | } |
| 234 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 235 | sub testStruct { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 236 | my $self = shift; |
| 237 | my $thing = shift; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 238 | printf(qq|testStruct({"%s", %d, %d, %lld})\n|, |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 239 | $thing->{string_thing}, |
| 240 | $thing->{byte_thing}, |
| 241 | $thing->{i32_thing}, |
| 242 | $thing->{i64_thing}); |
| 243 | return $thing; |
| 244 | } |
| 245 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 246 | sub testNest { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 247 | my $self = shift; |
| 248 | my $nest = shift; |
| 249 | my $thing = $nest->{struct_thing}; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 250 | printf(qq|testNest({%d, {"%s", %d, %d, %lld}, %d})\n|, |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 251 | $nest->{byte_thing}, |
| 252 | $thing->{string_thing}, |
| 253 | $thing->{byte_thing}, |
| 254 | $thing->{i32_thing}, |
| 255 | $thing->{i64_thing}, |
| 256 | $nest->{i32_thing}); |
| 257 | return $nest; |
| 258 | } |
| 259 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 260 | sub testMap { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 261 | my $self = shift; |
| 262 | my $thing = shift; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 263 | printf "testMap({%s})\n", |
| 264 | join( ', ', |
| 265 | map { $_ . ' => ' . $thing->{$_} } |
| 266 | sort keys %$thing |
| 267 | ); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 268 | return $thing; |
| 269 | } |
| 270 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 271 | sub testStringMap { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 272 | my $self = shift; |
| 273 | my $thing = shift; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 274 | printf "testStringMap({%s})\n", |
| 275 | join( ', ', |
| 276 | map { $_ . ' => ' . $thing->{$_} } |
| 277 | sort keys %$thing |
| 278 | ); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 279 | return $thing; |
| 280 | } |
| 281 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 282 | sub testSet { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 283 | my $self = shift; |
| 284 | my $thing = shift; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 285 | my @result = sort keys %$thing; |
| 286 | printf "testSet({%s})\n", join(', ', @result ); |
| 287 | return \@result; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 290 | sub testList { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 291 | my $self = shift; |
| 292 | my $thing = shift; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 293 | print "testList({%s})\n", join(', ', @$thing); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 294 | return $thing; |
| 295 | } |
| 296 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 297 | sub testEnum { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 298 | my $self = shift; |
| 299 | my $thing = shift; |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 300 | print "testEnum($thing)\n"; |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 301 | return $thing; |
| 302 | } |
| 303 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 304 | sub testTypedef { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 305 | my $self = shift; |
| 306 | my $thing = shift; |
| 307 | print("testTypedef($thing)\n"); |
| 308 | return $thing; |
| 309 | } |
| 310 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 311 | sub testMapMap { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 312 | my $self = shift; |
| 313 | my $hello = shift; |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 314 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 315 | printf("testMapMap(%d)\n", $hello); |
| 316 | my $result = { 4 => { 1 => 1, 2 => 2, 3 => 3, 4 => 4 }, -4 => { -1 => -1, -2 => -2, -3 => -3, -4 => -4 } }; |
| 317 | return $result; |
| 318 | } |
| 319 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 320 | sub testInsanity { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 321 | my $self = shift; |
| 322 | my $argument = shift; |
| 323 | print("testInsanity()\n"); |
| 324 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 325 | my $hello = ThriftTest::Xtruct->new({string_thing => 'Hello2', byte_thing => 2, i32_thing => 2, i64_thing => 2}); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 326 | my @hellos; |
| 327 | push(@hellos, $hello); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 328 | my $goodbye = ThriftTest::Xtruct->new({string_thing => 'Goodbye4', byte_thing => 4, i32_thing => 4, i64_thing => 4}); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 329 | my @goodbyes; |
| 330 | push(@goodbyes, $goodbye); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 331 | my $crazy = ThriftTest::Insanity->new({userMap => { ThriftTest::Numberz::EIGHT => 8 }, xtructs => \@goodbyes}); |
| 332 | my $loony = ThriftTest::Insanity->new(); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 333 | my $result = { 1 => { ThriftTest::Numberz::TWO => $argument, ThriftTest::Numberz::THREE => $argument }, |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 334 | 2 => { ThriftTest::Numberz::SIX => $loony } }; |
| 335 | return $result; |
| 336 | } |
| 337 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 338 | sub testMulti { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 339 | my $self = shift; |
| 340 | my $arg0 = shift; |
| 341 | my $arg1 = shift; |
| 342 | my $arg2 = shift; |
| 343 | my $arg3 = shift; |
| 344 | my $arg4 = shift; |
| 345 | my $arg5 = shift; |
James E. King, III | 377719c | 2017-02-15 14:33:20 -0500 | [diff] [blame] | 346 | |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 347 | print("testMulti()\n"); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 348 | return ThriftTest::Xtruct->new({string_thing => 'Hello2', byte_thing => $arg0, i32_thing => $arg1, i64_thing => $arg2}); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 349 | } |
| 350 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 351 | sub testException { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 352 | my $self = shift; |
| 353 | my $arg = shift; |
| 354 | print("testException($arg)\n"); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 355 | if ($arg eq 'Xception') { |
| 356 | die ThriftTest::Xception->new({errorCode => 1001, message => $arg}); |
| 357 | } |
| 358 | elsif ($arg eq 'TException') { |
| 359 | die 'astring'; # all unhandled exceptions become TExceptions |
| 360 | } |
| 361 | else { |
| 362 | return ThriftTest::Xtruct->new({string_thing => $arg}); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 366 | sub testMultiException { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 367 | my $self = shift; |
| 368 | my $arg0 = shift; |
| 369 | my $arg1 = shift; |
| 370 | |
| 371 | printf("testMultiException(%s, %s)\n", $arg0, $arg1); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 372 | if ($arg0 eq 'Xception') { |
| 373 | die ThriftTest::Xception->new({errorCode => 1001, message => 'This is an Xception'}); |
| 374 | } |
| 375 | elsif ($arg0 eq 'Xception2') { |
| 376 | my $struct_thing = ThriftTest::Xtruct->new({string_thing => 'This is an Xception2'}); |
| 377 | die ThriftTest::Xception2->new({errorCode => 2002, struct_thing => $struct_thing}); |
| 378 | } |
| 379 | else { |
| 380 | return ThriftTest::Xtruct->new({string_thing => $arg1}); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 384 | sub testOneway { |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 385 | my $self = shift; |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 386 | my $num = shift; |
| 387 | print("testOneway($num): received\n"); |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 388 | } |
| 389 | |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 390 | ### |
| 391 | ### Test server implementation |
| 392 | ### |
| 393 | |
| 394 | package SecondServiceHandler; |
| 395 | |
| 396 | use base qw( ThriftTest::SecondServiceIf ); |
| 397 | |
| 398 | sub new { |
| 399 | my $classname = shift; |
| 400 | my $self = {}; |
| 401 | return bless($self, $classname); |
| 402 | } |
| 403 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 404 | sub secondtestString { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 405 | my $self = shift; |
| 406 | my $thing = shift; |
| 407 | print("testString($thing)\n"); |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 408 | return qq|testString("$thing")|; |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 409 | } |
Jim King | f5f1b35 | 2015-06-24 13:47:24 -0400 | [diff] [blame] | 410 | |
| 411 | 1; |