2007-03-07 05:45:10 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2009-03-30 21:35:00 +00:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
|
2007-03-07 05:45:10 +00:00
|
|
|
$:.push('../gen-rb')
|
2008-06-18 01:00:50 +00:00
|
|
|
$:.unshift '../../lib/rb/lib'
|
2007-03-07 05:45:10 +00:00
|
|
|
|
2008-06-18 01:03:33 +00:00
|
|
|
require 'thrift'
|
2007-03-07 05:45:10 +00:00
|
|
|
|
2009-05-05 18:59:49 +00:00
|
|
|
require 'calculator'
|
2007-03-07 05:45:10 +00:00
|
|
|
|
|
|
|
begin
|
2007-07-25 22:41:00 +00:00
|
|
|
port = ARGV[0] || 9090
|
2008-02-06 22:18:40 +00:00
|
|
|
|
2008-06-18 01:03:33 +00:00
|
|
|
transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', port))
|
|
|
|
protocol = Thrift::BinaryProtocol.new(transport)
|
2007-03-14 02:47:35 +00:00
|
|
|
client = Calculator::Client.new(protocol)
|
2007-07-25 22:41:00 +00:00
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
transport.open()
|
2007-07-25 22:41:00 +00:00
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
client.ping()
|
|
|
|
print "ping()\n"
|
2007-07-25 22:41:00 +00:00
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
sum = client.add(1,1)
|
|
|
|
print "1+1=", sum, "\n"
|
2007-07-25 22:41:00 +00:00
|
|
|
|
|
|
|
sum = client.add(1,4)
|
|
|
|
print "1+4=", sum, "\n"
|
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
work = Work.new()
|
2007-07-25 22:41:00 +00:00
|
|
|
|
|
|
|
work.op = Operation::SUBTRACT
|
|
|
|
work.num1 = 15
|
|
|
|
work.num2 = 10
|
|
|
|
diff = client.calculate(1, work)
|
|
|
|
print "15-10=", diff, "\n"
|
|
|
|
|
|
|
|
log = client.getStruct(1)
|
|
|
|
print "Log: ", log.value, "\n"
|
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
begin
|
|
|
|
work.op = Operation::DIVIDE
|
|
|
|
work.num1 = 1
|
|
|
|
work.num2 = 0
|
|
|
|
quot = client.calculate(1, work)
|
|
|
|
puts "Whoa, we can divide by 0 now?"
|
|
|
|
rescue InvalidOperation => io
|
|
|
|
print "InvalidOperation: ", io.why, "\n"
|
|
|
|
end
|
2007-07-25 22:41:00 +00:00
|
|
|
|
|
|
|
client.zip()
|
|
|
|
print "zip\n"
|
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
transport.close()
|
|
|
|
|
2008-06-18 00:54:13 +00:00
|
|
|
rescue Thrift::Exception => tx
|
|
|
|
print 'Thrift::Exception: ', tx.message, "\n"
|
2007-03-07 05:45:10 +00:00
|
|
|
end
|