blob: 1b5d5db5dea028676ccf18d680b4dce73de1f647 [file] [log] [blame]
Mark Slee07a3aab2007-03-07 05:45:10 +00001#!/usr/bin/env ruby
2
3$:.push('../gen-rb')
4
Kevin Clark29600442008-06-18 00:54:13 +00005require 'thrift/transport/tsocket'
6require 'thrift/protocol/tbinaryprotocol'
Mark Slee07a3aab2007-03-07 05:45:10 +00007
8require 'Calculator'
9
Mark Slee07a3aab2007-03-07 05:45:10 +000010begin
Christopher Piro5f5fdf32007-07-25 22:41:00 +000011 port = ARGV[0] || 9090
David Reiss0c90f6f2008-02-06 22:18:40 +000012
Christopher Piro5f5fdf32007-07-25 22:41:00 +000013 transport = TBufferedTransport.new(TSocket.new('localhost', port))
Mark Slee76791962007-03-14 02:47:35 +000014 protocol = TBinaryProtocol.new(transport)
15 client = Calculator::Client.new(protocol)
Christopher Piro5f5fdf32007-07-25 22:41:00 +000016
Mark Slee76791962007-03-14 02:47:35 +000017 transport.open()
Christopher Piro5f5fdf32007-07-25 22:41:00 +000018
Mark Slee76791962007-03-14 02:47:35 +000019 client.ping()
20 print "ping()\n"
Christopher Piro5f5fdf32007-07-25 22:41:00 +000021
Mark Slee76791962007-03-14 02:47:35 +000022 sum = client.add(1,1)
23 print "1+1=", sum, "\n"
Christopher Piro5f5fdf32007-07-25 22:41:00 +000024
25 sum = client.add(1,4)
26 print "1+4=", sum, "\n"
27
Mark Slee76791962007-03-14 02:47:35 +000028 work = Work.new()
Christopher Piro5f5fdf32007-07-25 22:41:00 +000029
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 Slee76791962007-03-14 02:47:35 +000039 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 Piro5f5fdf32007-07-25 22:41:00 +000048
49 client.zip()
50 print "zip\n"
51
Mark Slee76791962007-03-14 02:47:35 +000052 transport.close()
53
Kevin Clark29600442008-06-18 00:54:13 +000054rescue Thrift::Exception => tx
55 print 'Thrift::Exception: ', tx.message, "\n"
Mark Slee07a3aab2007-03-07 05:45:10 +000056end