blob: d2b9150f42c221ee54f248a170ac79aeb65a7009 [file] [log] [blame]
Mark Slee07a3aab2007-03-07 05:45:10 +00001#!/usr/bin/env ruby
2
3$:.push('../gen-rb')
Kevin Clark2b1e10b2008-06-18 01:00:50 +00004$:.unshift '../../lib/rb/lib'
Mark Slee07a3aab2007-03-07 05:45:10 +00005
Kevin Clark21411532008-06-18 01:03:33 +00006require 'thrift'
7require 'thrift/protocol/binaryprotocol'
Mark Slee07a3aab2007-03-07 05:45:10 +00008
9require 'Calculator'
10
Mark Slee07a3aab2007-03-07 05:45:10 +000011begin
Christopher Piro5f5fdf32007-07-25 22:41:00 +000012 port = ARGV[0] || 9090
David Reiss0c90f6f2008-02-06 22:18:40 +000013
Kevin Clark21411532008-06-18 01:03:33 +000014 transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', port))
15 protocol = Thrift::BinaryProtocol.new(transport)
Mark Slee76791962007-03-14 02:47:35 +000016 client = Calculator::Client.new(protocol)
Christopher Piro5f5fdf32007-07-25 22:41:00 +000017
Mark Slee76791962007-03-14 02:47:35 +000018 transport.open()
Christopher Piro5f5fdf32007-07-25 22:41:00 +000019
Mark Slee76791962007-03-14 02:47:35 +000020 client.ping()
21 print "ping()\n"
Christopher Piro5f5fdf32007-07-25 22:41:00 +000022
Mark Slee76791962007-03-14 02:47:35 +000023 sum = client.add(1,1)
24 print "1+1=", sum, "\n"
Christopher Piro5f5fdf32007-07-25 22:41:00 +000025
26 sum = client.add(1,4)
27 print "1+4=", sum, "\n"
28
Mark Slee76791962007-03-14 02:47:35 +000029 work = Work.new()
Christopher Piro5f5fdf32007-07-25 22:41:00 +000030
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 Slee76791962007-03-14 02:47:35 +000040 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 Piro5f5fdf32007-07-25 22:41:00 +000049
50 client.zip()
51 print "zip\n"
52
Mark Slee76791962007-03-14 02:47:35 +000053 transport.close()
54
Kevin Clark29600442008-06-18 00:54:13 +000055rescue Thrift::Exception => tx
56 print 'Thrift::Exception: ', tx.message, "\n"
Mark Slee07a3aab2007-03-07 05:45:10 +000057end