blob: fd7269951f1b1e72558c430e90559090ee5076e1 [file] [log] [blame]
Mark Slee07a3aab2007-03-07 05:45:10 +00001#!/usr/bin/env ruby
2
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 Slee07a3aab2007-03-07 05:45:10 +000022$:.push('../gen-rb')
Kevin Clark2b1e10b2008-06-18 01:00:50 +000023$:.unshift '../../lib/rb/lib'
Mark Slee07a3aab2007-03-07 05:45:10 +000024
Kevin Clark21411532008-06-18 01:03:33 +000025require 'thrift'
Mark Slee07a3aab2007-03-07 05:45:10 +000026
Bryan Duxburyb7b8af92009-05-05 18:59:49 +000027require 'calculator'
Mark Slee07a3aab2007-03-07 05:45:10 +000028
Mark Slee07a3aab2007-03-07 05:45:10 +000029begin
Christopher Piro5f5fdf32007-07-25 22:41:00 +000030 port = ARGV[0] || 9090
David Reiss0c90f6f2008-02-06 22:18:40 +000031
Kevin Clark21411532008-06-18 01:03:33 +000032 transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', port))
33 protocol = Thrift::BinaryProtocol.new(transport)
Mark Slee76791962007-03-14 02:47:35 +000034 client = Calculator::Client.new(protocol)
Christopher Piro5f5fdf32007-07-25 22:41:00 +000035
Mark Slee76791962007-03-14 02:47:35 +000036 transport.open()
Christopher Piro5f5fdf32007-07-25 22:41:00 +000037
Mark Slee76791962007-03-14 02:47:35 +000038 client.ping()
39 print "ping()\n"
Christopher Piro5f5fdf32007-07-25 22:41:00 +000040
Mark Slee76791962007-03-14 02:47:35 +000041 sum = client.add(1,1)
42 print "1+1=", sum, "\n"
Christopher Piro5f5fdf32007-07-25 22:41:00 +000043
44 sum = client.add(1,4)
45 print "1+4=", sum, "\n"
46
Mark Slee76791962007-03-14 02:47:35 +000047 work = Work.new()
Christopher Piro5f5fdf32007-07-25 22:41:00 +000048
49 work.op = Operation::SUBTRACT
50 work.num1 = 15
51 work.num2 = 10
52 diff = client.calculate(1, work)
53 print "15-10=", diff, "\n"
54
55 log = client.getStruct(1)
56 print "Log: ", log.value, "\n"
57
Mark Slee76791962007-03-14 02:47:35 +000058 begin
59 work.op = Operation::DIVIDE
60 work.num1 = 1
61 work.num2 = 0
62 quot = client.calculate(1, work)
63 puts "Whoa, we can divide by 0 now?"
64 rescue InvalidOperation => io
65 print "InvalidOperation: ", io.why, "\n"
66 end
Christopher Piro5f5fdf32007-07-25 22:41:00 +000067
68 client.zip()
69 print "zip\n"
70
Mark Slee76791962007-03-14 02:47:35 +000071 transport.close()
72
Kevin Clark29600442008-06-18 00:54:13 +000073rescue Thrift::Exception => tx
74 print 'Thrift::Exception: ', tx.message, "\n"
Mark Slee07a3aab2007-03-07 05:45:10 +000075end