diff --git a/CHANGES.txt b/CHANGES.txt index 8feee654ce1..aaeba82e3b1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,14 @@ Avro 1.3.3 (Unreleased) AVRO-450. HTTP IPC for ruby. (jmhodges) + AVRO-508. Use page-backed buffers for C++ serialization input or + output. (sbanacho) + + AVRO-516. Removing unnecessary ruby StringIO calls. (jmhodges) + + AVRO-516. Ruby socket RPC should use big endian buffer lengths. + (jmhodges) + BUG FIXES AVRO-461. Skipping primitives in the ruby side (jmhodges) diff --git a/lang/ruby/lib/avro/ipc.rb b/lang/ruby/lib/avro/ipc.rb index 0ff05c3dd6e..141e644f06f 100644 --- a/lang/ruby/lib/avro/ipc.rb +++ b/lang/ruby/lib/avro/ipc.rb @@ -239,8 +239,7 @@ def initialize(local_protocol) # Called by a server to deserialize a request, compute and serialize # a response or error. Compare to 'handle()' in Thrift. def respond(call_request) - buffer_reader = StringIO.new(call_request) - buffer_decoder = Avro::IO::BinaryDecoder.new(StringIO.new(call_request)) + buffer_decoder = Avro::IO::BinaryDecoder.new(call_request) buffer_writer = StringIO.new('', 'w+') buffer_encoder = Avro::IO::BinaryEncoder.new(buffer_writer) error = nil @@ -422,7 +421,7 @@ def write_buffer(chunk) end def write_buffer_length(n) - bytes_sent = sock.write([n].pack('I')) + bytes_sent = sock.write([n].pack('N')) if bytes_sent == 0 raise ConnectionClosedException.new("socket sent 0 bytes") end @@ -433,7 +432,7 @@ def read_buffer_length if read == '' || read == nil raise ConnectionClosedException.new("Socket read 0 bytes.") end - read.unpack('I')[0] + read.unpack('N')[0] end def close diff --git a/lang/ruby/test/sample_ipc_client.rb b/lang/ruby/test/sample_ipc_client.rb index 1f6f1d74c49..0a25e58f976 100644 --- a/lang/ruby/test/sample_ipc_client.rb +++ b/lang/ruby/test/sample_ipc_client.rb @@ -66,8 +66,7 @@ def make_requestor(server_address, port, protocol) 'body' => ARGV[2] } - num_messages = ARGV[3].to_i - num_message = 1 if num_messages == 0 + num_messages = (ARGV[3] || 1).to_i # build the parameters for the request params = {'message' => message} @@ -83,4 +82,4 @@ def make_requestor(server_address, port, protocol) requestor = make_requestor('localhost', 9090, MAIL_PROTOCOL) result = requestor.request('replay', {}) puts("Replay Result: " + result) -end \ No newline at end of file +end diff --git a/lang/ruby/test/sample_ipc_server.rb b/lang/ruby/test/sample_ipc_server.rb index 144caac1ef5..c36ea051e7d 100644 --- a/lang/ruby/test/sample_ipc_server.rb +++ b/lang/ruby/test/sample_ipc_server.rb @@ -81,11 +81,12 @@ class MailHandler < RequestHandler def handle(request) responder = MailResponder.new() transport = Avro::IPC::SocketTransport.new(request) - transport.write_framed_message(responder.respond(transport)) + str = StringIO.new(transport.read_framed_message) + transport.write_framed_message(responder.respond(str)) end end if $0 == __FILE__ handler = MailHandler.new('localhost', 9090) handler.run -end \ No newline at end of file +end diff --git a/lang/ruby/test/test_socket_transport.rb b/lang/ruby/test/test_socket_transport.rb new file mode 100644 index 00000000000..78c40ebd9c6 --- /dev/null +++ b/lang/ruby/test/test_socket_transport.rb @@ -0,0 +1,24 @@ +require 'test_help' + +class TestSocketTransport < Test::Unit::TestCase + def test_buffer_writing + io = StringIO.new + st = Avro::IPC::SocketTransport.new(io) + buffer_length = "\000\000\000\006" # 6 in big-endian + message = 'abcdef' + null_ending = "\000\000\000\000" # 0 in big-endian + full = buffer_length + message + null_ending + st.write_framed_message('abcdef') + assert_equal full, io.string + end + + def test_buffer_reading + buffer_length = "\000\000\000\005" # 5 in big-endian + message = "hello" + null_ending = "\000\000\000\000" # 0 in big-endian + full = buffer_length + message + null_ending + io = StringIO.new(full) + st = Avro::IPC::SocketTransport.new(io) + assert_equal 'hello', st.read_framed_message + end +end