Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 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 | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 22 | $:.push('../gen-rb') |
Kevin Clark | 2b1e10b | 2008-06-18 01:00:50 +0000 | [diff] [blame] | 23 | $:.unshift '../../lib/rb/lib' |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 24 | |
Kevin Clark | 2141153 | 2008-06-18 01:03:33 +0000 | [diff] [blame] | 25 | require 'thrift' |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 26 | |
Bryan Duxbury | b7b8af9 | 2009-05-05 18:59:49 +0000 | [diff] [blame^] | 27 | require 'calculator' |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 28 | |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 29 | begin |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 30 | port = ARGV[0] || 9090 |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 31 | |
Kevin Clark | 2141153 | 2008-06-18 01:03:33 +0000 | [diff] [blame] | 32 | transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', port)) |
| 33 | protocol = Thrift::BinaryProtocol.new(transport) |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 34 | client = Calculator::Client.new(protocol) |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 35 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 36 | transport.open() |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 37 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 38 | client.ping() |
| 39 | print "ping()\n" |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 40 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 41 | sum = client.add(1,1) |
| 42 | print "1+1=", sum, "\n" |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 43 | |
| 44 | sum = client.add(1,4) |
| 45 | print "1+4=", sum, "\n" |
| 46 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 47 | work = Work.new() |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 48 | |
| 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 Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 58 | 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 Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 67 | |
| 68 | client.zip() |
| 69 | print "zip\n" |
| 70 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 71 | transport.close() |
| 72 | |
Kevin Clark | 2960044 | 2008-06-18 00:54:13 +0000 | [diff] [blame] | 73 | rescue Thrift::Exception => tx |
| 74 | print 'Thrift::Exception: ', tx.message, "\n" |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 75 | end |