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