blob: 1d596568dfc0cbf3752047c06444afa6a157915c [file] [log] [blame]
T Jake Luciani41687fc2008-12-23 03:45:43 +00001#!/usr/bin/env perl
Mark Slee738ad312007-05-16 02:40:12 +00002
David Reissea2cba82009-03-30 21:35:00 +00003#
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 Slee738ad312007-05-16 02:40:12 +000022use strict;
23use warnings;
24
25use lib '../../lib/perl/lib';
26use lib '../gen-perl';
27
28use Thrift;
29use Thrift::BinaryProtocol;
30use Thrift::Socket;
31use Thrift::BufferedTransport;
32
T Jake Luciani41687fc2008-12-23 03:45:43 +000033use shared::SharedService;
34use tutorial::Calculator;
Mark Slee27ed6ec2007-08-16 01:26:31 +000035use shared::Types;
36use tutorial::Types;
Mark Slee738ad312007-05-16 02:40:12 +000037
38use Data::Dumper;
39
40my $socket = new Thrift::Socket('localhost',9090);
41my $transport = new Thrift::BufferedTransport($socket,1024,1024);
42my $protocol = new Thrift::BinaryProtocol($transport);
T Jake Luciani41687fc2008-12-23 03:45:43 +000043my $client = new tutorial::CalculatorClient($protocol);
Mark Slee738ad312007-05-16 02:40:12 +000044
45
46eval{
47 $transport->open();
48
49 $client->ping();
50 print "ping()\n";
51
52
Mark Slee82664432007-09-19 06:49:30 +000053 my $sum = $client->add(1,1);
Mark Slee738ad312007-05-16 02:40:12 +000054 print "1+1=$sum\n";
55
Mark Slee82664432007-09-19 06:49:30 +000056 my $work = new tutorial::Work();
Mark Slee738ad312007-05-16 02:40:12 +000057
T Jake Luciani41687fc2008-12-23 03:45:43 +000058 $work->op(tutorial::Operation::DIVIDE);
Mark Slee82664432007-09-19 06:49:30 +000059 $work->num1(1);
60 $work->num2(0);
Mark Slee738ad312007-05-16 02:40:12 +000061
62 eval {
63 $client->calculate(1, $work);
64 print "Whoa! We can divide by zero?\n";
65 }; if($@) {
66 warn "InvalidOperation: ".Dumper($@);
67 }
68
T Jake Luciani41687fc2008-12-23 03:45:43 +000069 $work->op(tutorial::Operation::SUBTRACT);
Mark Slee82664432007-09-19 06:49:30 +000070 $work->num1(15);
71 $work->num2(10);
Mark Slee738ad312007-05-16 02:40:12 +000072 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}