T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 2 | |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [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 | |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 22 | use strict; |
| 23 | use warnings; |
| 24 | |
| 25 | use lib '../../lib/perl/lib'; |
Kengo Seki | 58efe89 | 2019-10-09 22:23:16 +0900 | [diff] [blame] | 26 | use lib 'gen-perl'; |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 27 | |
| 28 | use Thrift; |
| 29 | use Thrift::BinaryProtocol; |
| 30 | use Thrift::Socket; |
| 31 | use Thrift::BufferedTransport; |
| 32 | |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 33 | use shared::SharedService; |
| 34 | use tutorial::Calculator; |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 35 | use shared::Types; |
| 36 | use tutorial::Types; |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 37 | |
| 38 | use Data::Dumper; |
| 39 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 40 | my $socket = Thrift::Socket->new('localhost',9090); |
| 41 | my $transport = Thrift::BufferedTransport->new($socket,1024,1024); |
| 42 | my $protocol = Thrift::BinaryProtocol->new($transport); |
| 43 | my $client = tutorial::CalculatorClient->new($protocol); |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | eval{ |
| 47 | $transport->open(); |
| 48 | |
| 49 | $client->ping(); |
| 50 | print "ping()\n"; |
| 51 | |
| 52 | |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 53 | my $sum = $client->add(1,1); |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 54 | print "1+1=$sum\n"; |
| 55 | |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 56 | my $work = tutorial::Work->new(); |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 57 | |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 58 | $work->op(tutorial::Operation::DIVIDE); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 59 | $work->num1(1); |
| 60 | $work->num2(0); |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 61 | |
| 62 | eval { |
| 63 | $client->calculate(1, $work); |
| 64 | print "Whoa! We can divide by zero?\n"; |
| 65 | }; if($@) { |
Dean Hamstead | 8a130f6 | 2018-10-17 18:48:42 +1100 | [diff] [blame] | 66 | warn 'InvalidOperation: '.Dumper($@); |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 67 | } |
| 68 | |
T Jake Luciani | 41687fc | 2008-12-23 03:45:43 +0000 | [diff] [blame] | 69 | $work->op(tutorial::Operation::SUBTRACT); |
Mark Slee | 8266443 | 2007-09-19 06:49:30 +0000 | [diff] [blame] | 70 | $work->num1(15); |
| 71 | $work->num2(10); |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 72 | my $diff = $client->calculate(1, $work); |
| 73 | print "15-10=$diff\n"; |
| 74 | |
| 75 | my $log = $client->getStruct(1); |
| 76 | print "Log: $log->{value}\n"; |
| 77 | |
| 78 | $transport->close(); |
| 79 | |
| 80 | }; if($@){ |
| 81 | warn(Dumper($@)); |
| 82 | } |