-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_client.rb
54 lines (39 loc) · 910 Bytes
/
echo_client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
$stdout.sync = true
$stderr.sync = true
require 'bundler/setup'
require 'thrift_server'
$LOAD_PATH << "#{__dir__}/gen-rb"
require 'echo_service'
host, port = ARGV[0], ARGV[1]
if !host || !port
$stdout.puts "usage: echo_client HOST PORT"
abort
end
logger = Logger.new $stdout
transport = Thrift::FramedTransport.new(Thrift::Socket.new(host, port.to_i))
transport.open
protocol = Thrift::BinaryProtocol.new transport
client = EchoService::Client.new protocol
response = client.echo "testing"
if response == 'testing'
$stdout.puts 'OK'
else
$stderr.puts 'Message not echoed'
abort
end
response = client.structEcho 'testing'
if response.message == 'testing'
$stdout.puts 'OK'
else
$stderr.puts 'Message not echoed'
abort
end
begin
client.structEcho 'exception'
rescue EchoException
$stdout.puts 'OK'
else
abort 'Protocol exception lost'
end
client.ping 'hello'
transport.close