Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 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
 
22
use strict;
23
use warnings;
24
 
25
use lib '../../lib/perl/lib';
26
use lib '../gen-perl';
27
 
28
use Thrift;
29
use Thrift::BinaryProtocol;
30
use Thrift::Socket;
31
use Thrift::BufferedTransport;
32
 
33
use shared::SharedService;
34
use tutorial::Calculator;
35
use shared::Types;
36
use tutorial::Types;
37
 
38
use Data::Dumper;
39
 
40
my $socket    = new Thrift::Socket('localhost',9090);
41
my $transport = new Thrift::BufferedTransport($socket,1024,1024);
42
my $protocol  = new Thrift::BinaryProtocol($transport);
43
my $client    = new tutorial::CalculatorClient($protocol);
44
 
45
 
46
eval{
47
    $transport->open();
48
 
49
    $client->ping();
50
    print "ping()\n";
51
 
52
 
53
    my $sum = $client->add(1,1);
54
    print "1+1=$sum\n";
55
 
56
    my $work = new tutorial::Work();
57
 
58
    $work->op(tutorial::Operation::DIVIDE);
59
    $work->num1(1);
60
    $work->num2(0);
61
 
62
    eval {
63
        $client->calculate(1, $work);
64
        print "Whoa! We can divide by zero?\n";
65
    }; if($@) {
66
        warn "InvalidOperation: ".Dumper($@);
67
    }
68
 
69
    $work->op(tutorial::Operation::SUBTRACT);
70
    $work->num1(15);
71
    $work->num2(10);
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
}