blob: 10cb725983adde38e3817abbb3346add2a8c15c7 [file] [log] [blame]
Mark Slee738ad312007-05-16 02:40:12 +00001#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use lib '../../lib/perl/lib';
7use lib '../gen-perl';
8
9use Thrift;
10use Thrift::BinaryProtocol;
11use Thrift::Socket;
12use Thrift::BufferedTransport;
13
14use SharedService;
Mark Slee738ad312007-05-16 02:40:12 +000015use Calculator;
Mark Slee27ed6ec2007-08-16 01:26:31 +000016use shared::Types;
17use tutorial::Types;
Mark Slee738ad312007-05-16 02:40:12 +000018
19use Data::Dumper;
20
21my $socket = new Thrift::Socket('localhost',9090);
22my $transport = new Thrift::BufferedTransport($socket,1024,1024);
23my $protocol = new Thrift::BinaryProtocol($transport);
24my $client = new CalculatorClient($protocol);
25
26
27eval{
28 $transport->open();
29
30 $client->ping();
31 print "ping()\n";
32
33
34 my $sum = $client->add(1000000,1);
35 print "1+1=$sum\n";
36
37 my $work = new Work();
38
39 $work->{op} = Operation::DIVIDE;
40 $work->{num1} = 1;
41 $work->{num2} = 0;
42
43 eval {
44 $client->calculate(1, $work);
45 print "Whoa! We can divide by zero?\n";
46 }; if($@) {
47 warn "InvalidOperation: ".Dumper($@);
48 }
49
50 $work->{op} = Operation::SUBTRACT;
51 $work->{num1} = 15;
52 $work->{num2} = 10;
53 my $diff = $client->calculate(1, $work);
54 print "15-10=$diff\n";
55
56 my $log = $client->getStruct(1);
57 print "Log: $log->{value}\n";
58
59 $transport->close();
60
61}; if($@){
62 warn(Dumper($@));
63}