Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | $:.push('../gen-rb') |
Kevin Clark | 2b1e10b | 2008-06-18 01:00:50 +0000 | [diff] [blame] | 4 | $:.unshift '../../lib/rb/lib' |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 5 | |
Kevin Clark | 2141153 | 2008-06-18 01:03:33 +0000 | [diff] [blame^] | 6 | require 'thrift' |
| 7 | require 'thrift/protocol/binaryprotocol' |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 8 | |
| 9 | require 'Calculator' |
| 10 | |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 11 | begin |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 12 | port = ARGV[0] || 9090 |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 13 | |
Kevin Clark | 2141153 | 2008-06-18 01:03:33 +0000 | [diff] [blame^] | 14 | transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', port)) |
| 15 | protocol = Thrift::BinaryProtocol.new(transport) |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 16 | client = Calculator::Client.new(protocol) |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 17 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 18 | transport.open() |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 19 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 20 | client.ping() |
| 21 | print "ping()\n" |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 22 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 23 | sum = client.add(1,1) |
| 24 | print "1+1=", sum, "\n" |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 25 | |
| 26 | sum = client.add(1,4) |
| 27 | print "1+4=", sum, "\n" |
| 28 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 29 | work = Work.new() |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 30 | |
| 31 | work.op = Operation::SUBTRACT |
| 32 | work.num1 = 15 |
| 33 | work.num2 = 10 |
| 34 | diff = client.calculate(1, work) |
| 35 | print "15-10=", diff, "\n" |
| 36 | |
| 37 | log = client.getStruct(1) |
| 38 | print "Log: ", log.value, "\n" |
| 39 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 40 | begin |
| 41 | work.op = Operation::DIVIDE |
| 42 | work.num1 = 1 |
| 43 | work.num2 = 0 |
| 44 | quot = client.calculate(1, work) |
| 45 | puts "Whoa, we can divide by 0 now?" |
| 46 | rescue InvalidOperation => io |
| 47 | print "InvalidOperation: ", io.why, "\n" |
| 48 | end |
Christopher Piro | 5f5fdf3 | 2007-07-25 22:41:00 +0000 | [diff] [blame] | 49 | |
| 50 | client.zip() |
| 51 | print "zip\n" |
| 52 | |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 53 | transport.close() |
| 54 | |
Kevin Clark | 2960044 | 2008-06-18 00:54:13 +0000 | [diff] [blame] | 55 | rescue Thrift::Exception => tx |
| 56 | print 'Thrift::Exception: ', tx.message, "\n" |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 57 | end |