Repository: thrift Updated Branches: refs/heads/master 22bd3450c -> 9aaf29580
THRIFT-4358: add unix domain socket option to ruby cross tests Client: rb This closes #1513 Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/9aaf2958 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/9aaf2958 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/9aaf2958 Branch: refs/heads/master Commit: 9aaf295806d32eab5715b4f0681f7da9b64c1fa5 Parents: 22bd345 Author: James E. King III <jk...@apache.org> Authored: Tue Mar 20 15:06:08 2018 -0400 Committer: James E. King III <jk...@apache.org> Committed: Wed Mar 21 01:02:11 2018 -0400 ---------------------------------------------------------------------- lib/rb/lib/thrift/protocol/base_protocol.rb | 10 +++- lib/rb/lib/thrift/protocol/binary_protocol.rb | 9 +++- .../protocol/binary_protocol_accelerated.rb | 8 ++++ lib/rb/lib/thrift/protocol/compact_protocol.rb | 8 ++++ lib/rb/lib/thrift/protocol/json_protocol.rb | 8 ++++ .../lib/thrift/protocol/multiplexed_protocol.rb | 6 ++- lib/rb/lib/thrift/server/base_server.rb | 10 +++- lib/rb/lib/thrift/server/simple_server.rb | 6 ++- lib/rb/lib/thrift/server/thread_pool_server.rb | 6 ++- lib/rb/lib/thrift/server/threaded_server.rb | 6 ++- .../thrift/transport/base_server_transport.rb | 2 +- lib/rb/lib/thrift/transport/base_transport.rb | 8 ++++ .../lib/thrift/transport/buffered_transport.rb | 10 +++- lib/rb/lib/thrift/transport/framed_transport.rb | 10 +++- .../thrift/transport/http_client_transport.rb | 4 ++ .../lib/thrift/transport/io_stream_transport.rb | 5 +- .../thrift/transport/memory_buffer_transport.rb | 4 ++ lib/rb/lib/thrift/transport/server_socket.rb | 7 ++- lib/rb/lib/thrift/transport/socket.rb | 6 ++- .../lib/thrift/transport/ssl_server_socket.rb | 4 ++ lib/rb/lib/thrift/transport/ssl_socket.rb | 4 ++ .../lib/thrift/transport/unix_server_socket.rb | 6 ++- lib/rb/lib/thrift/transport/unix_socket.rb | 6 ++- lib/rb/spec/base_protocol_spec.rb | 9 ++++ lib/rb/spec/base_transport_spec.rb | 38 ++++++++++++++++ lib/rb/spec/binary_protocol_accelerated_spec.rb | 6 ++- lib/rb/spec/binary_protocol_spec.rb | 8 ++++ lib/rb/spec/compact_protocol_spec.rb | 15 ++++++ lib/rb/spec/http_client_spec.rb | 4 ++ lib/rb/spec/json_protocol_spec.rb | 8 ++++ lib/rb/spec/server_socket_spec.rb | 5 ++ lib/rb/spec/server_spec.rb | 48 ++++++++++++++++++-- lib/rb/spec/socket_spec.rb | 9 +++- lib/rb/spec/ssl_server_socket_spec.rb | 34 ++++++++++++++ lib/rb/spec/ssl_socket_spec.rb | 4 ++ lib/rb/spec/unix_socket_spec.rb | 9 ++++ test/crossrunner/report.py | 1 + test/rb/integration/TestClient.rb | 14 +++++- test/rb/integration/TestServer.rb | 36 +++++++++------ test/tests.json | 7 +-- 40 files changed, 366 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/protocol/base_protocol.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/protocol/base_protocol.rb b/lib/rb/lib/thrift/protocol/base_protocol.rb index 88f44d4..5c693e9 100644 --- a/lib/rb/lib/thrift/protocol/base_protocol.rb +++ b/lib/rb/lib/thrift/protocol/base_protocol.rb @@ -369,11 +369,19 @@ module Thrift read_list_end end end + + def to_s + "#{trans.to_s}" + end end class BaseProtocolFactory def get_protocol(trans) raise NotImplementedError end + + def to_s + "base" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/protocol/binary_protocol.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/protocol/binary_protocol.rb b/lib/rb/lib/thrift/protocol/binary_protocol.rb index e70b1e3..d8279db 100644 --- a/lib/rb/lib/thrift/protocol/binary_protocol.rb +++ b/lib/rb/lib/thrift/protocol/binary_protocol.rb @@ -226,12 +226,19 @@ module Thrift size = read_i32 trans.read_all(size) end - + + def to_s + "binary(#{super.to_s})" + end end class BinaryProtocolFactory < BaseProtocolFactory def get_protocol(trans) return Thrift::BinaryProtocol.new(trans) end + + def to_s + "binary" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb b/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb index 70ea652..09b0264 100644 --- a/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb +++ b/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb @@ -35,5 +35,13 @@ module Thrift BinaryProtocol.new(trans) end end + + def to_s + if (defined? BinaryProtocolAccelerated) + "binary-accel" + else + "binary" + end + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/protocol/compact_protocol.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/protocol/compact_protocol.rb b/lib/rb/lib/thrift/protocol/compact_protocol.rb index 605eea6..1f9bd30 100644 --- a/lib/rb/lib/thrift/protocol/compact_protocol.rb +++ b/lib/rb/lib/thrift/protocol/compact_protocol.rb @@ -345,6 +345,10 @@ module Thrift size = read_varint32() trans.read_all(size) end + + def to_s + "compact(#{super.to_s})" + end private @@ -431,5 +435,9 @@ module Thrift def get_protocol(trans) CompactProtocol.new(trans) end + + def to_s + "compact" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/protocol/json_protocol.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/protocol/json_protocol.rb b/lib/rb/lib/thrift/protocol/json_protocol.rb index 514bdbf..91e74e4 100644 --- a/lib/rb/lib/thrift/protocol/json_protocol.rb +++ b/lib/rb/lib/thrift/protocol/json_protocol.rb @@ -768,11 +768,19 @@ module Thrift def read_binary read_json_base64 end + + def to_s + "json(#{super.to_s})" + end end class JsonProtocolFactory < BaseProtocolFactory def get_protocol(trans) return Thrift::JsonProtocol.new(trans) end + + def to_s + "json" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/protocol/multiplexed_protocol.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/protocol/multiplexed_protocol.rb b/lib/rb/lib/thrift/protocol/multiplexed_protocol.rb index 13c9d93..b4428a7 100644 --- a/lib/rb/lib/thrift/protocol/multiplexed_protocol.rb +++ b/lib/rb/lib/thrift/protocol/multiplexed_protocol.rb @@ -36,5 +36,9 @@ module Thrift @protocol.write_message_begin(name, type, seqid) end end + + def to_s + "multiplexed(#{@service_name=@protocol.to_s})" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/server/base_server.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/server/base_server.rb b/lib/rb/lib/thrift/server/base_server.rb index 1ee1213..aa4d09c 100644 --- a/lib/rb/lib/thrift/server/base_server.rb +++ b/lib/rb/lib/thrift/server/base_server.rb @@ -26,6 +26,12 @@ module Thrift @protocol_factory = protocol_factory ? protocol_factory : Thrift::BinaryProtocolFactory.new end - def serve; nil; end + def serve + raise NotImplementedError + end + + def to_s + "server(#{@protocol_factory.to_s}(#{@transport_factory.to_s}(#{@server_transport.to_s})))" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/server/simple_server.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/server/simple_server.rb b/lib/rb/lib/thrift/server/simple_server.rb index 21e8659..905fe9b 100644 --- a/lib/rb/lib/thrift/server/simple_server.rb +++ b/lib/rb/lib/thrift/server/simple_server.rb @@ -39,5 +39,9 @@ module Thrift @server_transport.close end end + + def to_s + "simple(#{super.to_s})" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/server/thread_pool_server.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/server/thread_pool_server.rb b/lib/rb/lib/thrift/server/thread_pool_server.rb index 8cec805..bb754ad 100644 --- a/lib/rb/lib/thrift/server/thread_pool_server.rb +++ b/lib/rb/lib/thrift/server/thread_pool_server.rb @@ -71,5 +71,9 @@ module Thrift @server_transport.close end end + + def to_s + "threadpool(#{super.to_s})" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/server/threaded_server.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/server/threaded_server.rb b/lib/rb/lib/thrift/server/threaded_server.rb index a2c917c..88ee183 100644 --- a/lib/rb/lib/thrift/server/threaded_server.rb +++ b/lib/rb/lib/thrift/server/threaded_server.rb @@ -43,5 +43,9 @@ module Thrift @server_transport.close end end + + def to_s + "threaded(#{super.to_s})" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/base_server_transport.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/base_server_transport.rb b/lib/rb/lib/thrift/transport/base_server_transport.rb index 68c5af0..0105463 100644 --- a/lib/rb/lib/thrift/transport/base_server_transport.rb +++ b/lib/rb/lib/thrift/transport/base_server_transport.rb @@ -34,4 +34,4 @@ module Thrift raise NotImplementedError end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/base_transport.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/base_transport.rb b/lib/rb/lib/thrift/transport/base_transport.rb index 8790326..97e5935 100644 --- a/lib/rb/lib/thrift/transport/base_transport.rb +++ b/lib/rb/lib/thrift/transport/base_transport.rb @@ -99,11 +99,19 @@ module Thrift alias_method :<<, :write def flush; end + + def to_s + "base" + end end class BaseTransportFactory def get_transport(trans) return trans end + + def to_s + "base" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/buffered_transport.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/buffered_transport.rb b/lib/rb/lib/thrift/transport/buffered_transport.rb index 781d3c6..4fe9c41 100644 --- a/lib/rb/lib/thrift/transport/buffered_transport.rb +++ b/lib/rb/lib/thrift/transport/buffered_transport.rb @@ -104,11 +104,19 @@ module Thrift @transport.flush end + + def to_s + "buffered(#{@transport.to_s})" + end end class BufferedTransportFactory < BaseTransportFactory def get_transport(transport) return BufferedTransport.new(transport) end + + def to_s + "buffered" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/framed_transport.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/framed_transport.rb b/lib/rb/lib/thrift/transport/framed_transport.rb index d806ce0..9531778 100644 --- a/lib/rb/lib/thrift/transport/framed_transport.rb +++ b/lib/rb/lib/thrift/transport/framed_transport.rb @@ -99,6 +99,10 @@ module Thrift @wbuf = Bytes.empty_byte_buffer end + def to_s + "framed(#{@transport.to_s})" + end + private def read_frame @@ -113,5 +117,9 @@ module Thrift def get_transport(transport) return FramedTransport.new(transport) end + + def to_s + "framed" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/http_client_transport.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/http_client_transport.rb b/lib/rb/lib/thrift/transport/http_client_transport.rb index c9c4fec..5c1dd5c 100644 --- a/lib/rb/lib/thrift/transport/http_client_transport.rb +++ b/lib/rb/lib/thrift/transport/http_client_transport.rb @@ -53,5 +53,9 @@ module Thrift ensure @outbuf = Bytes.empty_byte_buffer end + + def to_s + "@{self.url}" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/io_stream_transport.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/io_stream_transport.rb b/lib/rb/lib/thrift/transport/io_stream_transport.rb index e3c8379..ccec68f 100644 --- a/lib/rb/lib/thrift/transport/io_stream_transport.rb +++ b/lib/rb/lib/thrift/transport/io_stream_transport.rb @@ -35,5 +35,8 @@ module Thrift def write(buf); @output.write(Bytes.force_binary_encoding(buf)) end def close; @input.close; @output.close end def to_io; @input end # we're assuming this is used in a IO.select for reading + def to_s + "iostream(input=#{@input.to_s},output=#{@output.to_s})" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/memory_buffer_transport.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/memory_buffer_transport.rb b/lib/rb/lib/thrift/transport/memory_buffer_transport.rb index ad5ad85..469ea73 100644 --- a/lib/rb/lib/thrift/transport/memory_buffer_transport.rb +++ b/lib/rb/lib/thrift/transport/memory_buffer_transport.rb @@ -121,5 +121,9 @@ module Thrift end out.join(" ") end + + def to_s + "memory" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/server_socket.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/server_socket.rb b/lib/rb/lib/thrift/transport/server_socket.rb index 7feb9ab..5000232 100644 --- a/lib/rb/lib/thrift/transport/server_socket.rb +++ b/lib/rb/lib/thrift/transport/server_socket.rb @@ -59,5 +59,10 @@ module Thrift end alias to_io handle + + def to_s + "socket(#{@host}:#{@port})" + end + end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/socket.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb index 517d112..f5e6f3b 100644 --- a/lib/rb/lib/thrift/transport/socket.rb +++ b/lib/rb/lib/thrift/transport/socket.rb @@ -134,8 +134,10 @@ module Thrift @handle = nil end - def to_io - @handle + alias to_io handle + + def to_s + "socket(#{@host}:#{@port})" end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/ssl_server_socket.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/ssl_server_socket.rb b/lib/rb/lib/thrift/transport/ssl_server_socket.rb index abc1343..3abd5ec 100644 --- a/lib/rb/lib/thrift/transport/ssl_server_socket.rb +++ b/lib/rb/lib/thrift/transport/ssl_server_socket.rb @@ -33,5 +33,9 @@ module Thrift socket = TCPServer.new(@host, @port) @handle = OpenSSL::SSL::SSLServer.new(socket, @ssl_context) end + + def to_s + "ssl(#{super.to_s})" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/ssl_socket.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/ssl_socket.rb b/lib/rb/lib/thrift/transport/ssl_socket.rb index dbbcc94..7ab96ab 100644 --- a/lib/rb/lib/thrift/transport/ssl_socket.rb +++ b/lib/rb/lib/thrift/transport/ssl_socket.rb @@ -43,5 +43,9 @@ module Thrift raise TransportException.new(TransportException::NOT_OPEN, "Could not connect to #{@desc}: #{e}") end end + + def to_s + "ssl(#{super.to_s})" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/unix_server_socket.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/unix_server_socket.rb b/lib/rb/lib/thrift/transport/unix_server_socket.rb index a135d25..057d122 100644 --- a/lib/rb/lib/thrift/transport/unix_server_socket.rb +++ b/lib/rb/lib/thrift/transport/unix_server_socket.rb @@ -56,5 +56,9 @@ module Thrift end alias to_io handle + + def to_s + "domain(#{@path})" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/lib/thrift/transport/unix_socket.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/transport/unix_socket.rb b/lib/rb/lib/thrift/transport/unix_socket.rb index 8f692e4..5dffd59 100644 --- a/lib/rb/lib/thrift/transport/unix_socket.rb +++ b/lib/rb/lib/thrift/transport/unix_socket.rb @@ -36,5 +36,9 @@ module Thrift raise TransportException.new(TransportException::NOT_OPEN, "Could not open UNIX socket at #{@path}") end end + + def to_s + "domain(#{@path})" + end end -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/base_protocol_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/base_protocol_spec.rb b/lib/rb/spec/base_protocol_spec.rb index ec50c48..d31e811 100644 --- a/lib/rb/spec/base_protocol_spec.rb +++ b/lib/rb/spec/base_protocol_spec.rb @@ -29,6 +29,11 @@ describe 'BaseProtocol' do describe Thrift::BaseProtocol do # most of the methods are stubs, so we can ignore them + it "should provide a reasonable to_s" do + @trans.should_receive(:to_s).once.and_return("trans") + @prot.to_s.should == "trans" + end + it "should make trans accessible" do @prot.trans.should eql(@trans) end @@ -213,5 +218,9 @@ describe 'BaseProtocol' do # returning nil since Protocol is just an abstract class lambda {Thrift::BaseProtocolFactory.new.get_protocol(mock("MockTransport"))}.should raise_error(NotImplementedError) end + + it "should provide a reasonable to_s" do + Thrift::BaseProtocolFactory.new.to_s.should == "base" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/base_transport_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/base_transport_spec.rb b/lib/rb/spec/base_transport_spec.rb index 4196572..0a05df2 100644 --- a/lib/rb/spec/base_transport_spec.rb +++ b/lib/rb/spec/base_transport_spec.rb @@ -48,6 +48,10 @@ describe 'BaseTransport' do it "should alias << to write" do Thrift::BaseTransport.instance_method(:<<).should == Thrift::BaseTransport.instance_method(:write) end + + it "should provide a reasonable to_s" do + Thrift::BaseTransport.new.to_s.should == "base" + end end describe Thrift::BaseServerTransport do @@ -63,9 +67,19 @@ describe 'BaseTransport' do transport = mock("Transport") Thrift::BaseTransportFactory.new.get_transport(transport).should eql(transport) end + + it "should provide a reasonable to_s" do + Thrift::BaseTransportFactory.new.to_s.should == "base" + end end describe Thrift::BufferedTransport do + it "should provide a to_s that describes the encapsulation" do + trans = mock("Transport") + trans.should_receive(:to_s).and_return("mock") + Thrift::BufferedTransport.new(trans).to_s.should == "buffered(mock)" + end + it "should pass through everything but write/flush/read" do trans = mock("Transport") trans.should_receive(:open?).ordered.and_return("+ open?") @@ -135,6 +149,10 @@ describe 'BaseTransport' do Thrift::BufferedTransport.should_receive(:new).with(trans).and_return(btrans) Thrift::BufferedTransportFactory.new.get_transport(trans).should == btrans end + + it "should provide a reasonable to_s" do + Thrift::BufferedTransportFactory.new.to_s.should == "buffered" + end end describe Thrift::FramedTransport do @@ -142,6 +160,12 @@ describe 'BaseTransport' do @trans = mock("Transport") end + it "should provide a to_s that describes the encapsulation" do + trans = mock("Transport") + trans.should_receive(:to_s).and_return("mock") + Thrift::FramedTransport.new(trans).to_s.should == "framed(mock)" + end + it "should pass through open?/open/close" do ftrans = Thrift::FramedTransport.new(@trans) @trans.should_receive(:open?).ordered.and_return("+ open?") @@ -247,6 +271,10 @@ describe 'BaseTransport' do Thrift::FramedTransport.should_receive(:new).with(trans) Thrift::FramedTransportFactory.new.get_transport(trans) end + + it "should provide a reasonable to_s" do + Thrift::FramedTransportFactory.new.to_s.should == "framed" + end end describe Thrift::MemoryBufferTransport do @@ -254,6 +282,10 @@ describe 'BaseTransport' do @buffer = Thrift::MemoryBufferTransport.new end + it "should provide a reasonable to_s" do + @buffer.to_s.should == "memory" + end + it "should accept a buffer on input and use it directly" do s = "this is a test" @buffer = Thrift::MemoryBufferTransport.new(s) @@ -323,6 +355,12 @@ describe 'BaseTransport' do @trans = Thrift::IOStreamTransport.new(@input, @output) end + it "should provide a reasonable to_s" do + @input.should_receive(:to_s).and_return("mock_input") + @output.should_receive(:to_s).and_return("mock_output") + @trans.to_s.should == "iostream(input=mock_input,output=mock_output)" + end + it "should be open as long as both input or output are open" do @trans.should be_open @input.stub!(:closed?).and_return(true) http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/binary_protocol_accelerated_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/binary_protocol_accelerated_spec.rb b/lib/rb/spec/binary_protocol_accelerated_spec.rb index bac9ea7..d49404a 100644 --- a/lib/rb/spec/binary_protocol_accelerated_spec.rb +++ b/lib/rb/spec/binary_protocol_accelerated_spec.rb @@ -35,8 +35,12 @@ if defined? Thrift::BinaryProtocolAccelerated it "should create a BinaryProtocolAccelerated" do Thrift::BinaryProtocolAcceleratedFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::BinaryProtocolAccelerated) end + + it "should provide a reasonable to_s" do + Thrift::BinaryProtocolAcceleratedFactory.new.to_s.should == "binary-accel" + end end end else puts "skipping BinaryProtocolAccelerated spec because it is not defined." -end \ No newline at end of file +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/binary_protocol_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/binary_protocol_spec.rb b/lib/rb/spec/binary_protocol_spec.rb index 32772d3..cccfc48 100644 --- a/lib/rb/spec/binary_protocol_spec.rb +++ b/lib/rb/spec/binary_protocol_spec.rb @@ -56,11 +56,19 @@ describe 'BinaryProtocol' do e.type == Thrift::ProtocolException::BAD_VERSION end end + + it "should provide a reasonable to_s" do + @prot.to_s.should == "binary(memory)" + end end describe Thrift::BinaryProtocolFactory do it "should create a BinaryProtocol" do Thrift::BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::BinaryProtocol) end + + it "should provide a reasonable to_s" do + Thrift::BinaryProtocolFactory.new.to_s.should == "binary" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/compact_protocol_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/compact_protocol_spec.rb b/lib/rb/spec/compact_protocol_spec.rb index 8a1a228..71ddc0e 100644 --- a/lib/rb/spec/compact_protocol_spec.rb +++ b/lib/rb/spec/compact_protocol_spec.rb @@ -127,6 +127,11 @@ describe Thrift::CompactProtocol do struct.should == struct2 end + it "should provide a reasonable to_s" do + trans = Thrift::MemoryBufferTransport.new + Thrift::CompactProtocol.new(trans).to_s.should == "compact(memory)" + end + class JankyHandler def Janky(i32arg) i32arg * 2 @@ -141,3 +146,13 @@ describe Thrift::CompactProtocol do "read_#{sym.to_s}" end end + +describe Thrift::CompactProtocolFactory do + it "should create a CompactProtocol" do + Thrift::CompactProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::CompactProtocol) + end + + it "should provide a reasonable to_s" do + Thrift::CompactProtocolFactory.new.to_s.should == "compact" + end +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/http_client_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/http_client_spec.rb b/lib/rb/spec/http_client_spec.rb index 5e8da24..70747ed 100644 --- a/lib/rb/spec/http_client_spec.rb +++ b/lib/rb/spec/http_client_spec.rb @@ -25,6 +25,10 @@ describe 'Thrift::HTTPClientTransport' do before(:each) do @client = Thrift::HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value") end + + it "should provide a reasonable to_s" do + @client.to_s == "http://my.domain.com/path/to/service?param=value" + end it "should always be open" do @client.should be_open http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/json_protocol_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/json_protocol_spec.rb b/lib/rb/spec/json_protocol_spec.rb index b6b46bf..57e9401 100644 --- a/lib/rb/spec/json_protocol_spec.rb +++ b/lib/rb/spec/json_protocol_spec.rb @@ -534,11 +534,19 @@ describe 'JsonProtocol' do @trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"") @prot.read_binary.bytes.to_a.should == (0...256).to_a end + + it "should provide a reasonable to_s" do + @prot.to_s.should == "json(memory)" + end end describe Thrift::JsonProtocolFactory do it "should create a JsonProtocol" do Thrift::JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::JsonProtocol) end + + it "should provide a reasonable to_s" do + Thrift::JsonProtocolFactory.new.to_s.should == "json" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/server_socket_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/server_socket_spec.rb b/lib/rb/spec/server_socket_spec.rb index 1301d54..126948f 100644 --- a/lib/rb/spec/server_socket_spec.rb +++ b/lib/rb/spec/server_socket_spec.rb @@ -35,6 +35,7 @@ describe 'Thrift::ServerSocket' do it "should accept an optional host argument" do @socket = Thrift::ServerSocket.new('localhost', 1234) TCPServer.should_receive(:new).with('localhost', 1234) + @socket.to_s == "server(localhost:1234)" @socket.listen end @@ -75,5 +76,9 @@ describe 'Thrift::ServerSocket' do handle.stub!(:closed?).and_return(true) @socket.should be_closed end + + it "should provide a reasonable to_s" do + @socket.to_s.should == "socket(:1234)" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/server_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/server_spec.rb b/lib/rb/spec/server_spec.rb index 93b9195..bc4d598 100644 --- a/lib/rb/spec/server_spec.rb +++ b/lib/rb/spec/server_spec.rb @@ -21,13 +21,30 @@ require 'spec_helper' describe 'Server' do describe Thrift::BaseServer do + before(:each) do + @processor = mock("Processor") + @serverTrans = mock("ServerTransport") + @trans = mock("BaseTransport") + @prot = mock("BaseProtocol") + @server = described_class.new(@processor, @serverTrans, @trans, @prot) + end + it "should default to BaseTransportFactory and BinaryProtocolFactory when not specified" do - server = Thrift::BaseServer.new(mock("Processor"), mock("BaseServerTransport")) - server.instance_variable_get(:'@transport_factory').should be_an_instance_of(Thrift::BaseTransportFactory) - server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(Thrift::BinaryProtocolFactory) + @server = Thrift::BaseServer.new(mock("Processor"), mock("BaseServerTransport")) + @server.instance_variable_get(:'@transport_factory').should be_an_instance_of(Thrift::BaseTransportFactory) + @server.instance_variable_get(:'@protocol_factory').should be_an_instance_of(Thrift::BinaryProtocolFactory) end - # serve is a noop, so can't test that + it "should not serve" do + expect { @server.serve()}.to raise_error(NotImplementedError) + end + + it "should provide a reasonable to_s" do + @serverTrans.should_receive(:to_s).once.and_return("serverTrans") + @trans.should_receive(:to_s).once.and_return("trans") + @prot.should_receive(:to_s).once.and_return("prot") + @server.to_s.should == "server(prot(trans(serverTrans)))" + end end describe Thrift::SimpleServer do @@ -40,6 +57,13 @@ describe 'Server' do @server = described_class.new(@processor, @serverTrans, @trans, @prot) end + it "should provide a reasonable to_s" do + @serverTrans.should_receive(:to_s).once.and_return("serverTrans") + @trans.should_receive(:to_s).once.and_return("trans") + @prot.should_receive(:to_s).once.and_return("prot") + @server.to_s.should == "simple(server(prot(trans(serverTrans))))" + end + it "should serve in the main thread" do @serverTrans.should_receive(:listen).ordered @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client) @@ -69,6 +93,13 @@ describe 'Server' do @server = described_class.new(@processor, @serverTrans, @trans, @prot) end + it "should provide a reasonable to_s" do + @serverTrans.should_receive(:to_s).once.and_return("serverTrans") + @trans.should_receive(:to_s).once.and_return("trans") + @prot.should_receive(:to_s).once.and_return("prot") + @server.to_s.should == "threaded(server(prot(trans(serverTrans))))" + end + it "should serve using threads" do @serverTrans.should_receive(:listen).ordered @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client) @@ -97,9 +128,16 @@ describe 'Server' do @prot = mock("BaseProtocol") @client = mock("Client") @server = described_class.new(@processor, @server_trans, @trans, @prot) - sleep(0.1) + sleep(0.15) end + it "should provide a reasonable to_s" do + @server_trans.should_receive(:to_s).once.and_return("server_trans") + @trans.should_receive(:to_s).once.and_return("trans") + @prot.should_receive(:to_s).once.and_return("prot") + @server.to_s.should == "threadpool(server(prot(trans(server_trans))))" + end + it "should serve inside a thread" do exception_q = @server.instance_variable_get(:@exception_q) described_class.any_instance.should_receive(:serve) do http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/socket_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/socket_spec.rb b/lib/rb/spec/socket_spec.rb index 8e1ef50..df56ba5 100644 --- a/lib/rb/spec/socket_spec.rb +++ b/lib/rb/spec/socket_spec.rb @@ -43,6 +43,7 @@ describe 'Socket' do ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true, :setsockopt => nil)) ::Socket.should_receive(:getaddrinfo).with("localhost", 9090, nil, ::Socket::SOCK_STREAM).and_return([[]]) ::Socket.should_receive(:sockaddr_in) + @socket.to_s == "socket(localhost:9090)" @socket.open end @@ -50,12 +51,18 @@ describe 'Socket' do ::Socket.should_receive(:new).and_return(mock("Handle", :connect_nonblock => true, :setsockopt => nil)) ::Socket.should_receive(:getaddrinfo).with("my.domain", 1234, nil, ::Socket::SOCK_STREAM).and_return([[]]) ::Socket.should_receive(:sockaddr_in) - Thrift::Socket.new('my.domain', 1234).open + @socket = Thrift::Socket.new('my.domain', 1234).open + @socket.to_s == "socket(my.domain:1234)" end it "should accept an optional timeout" do ::Socket.stub!(:new) Thrift::Socket.new('localhost', 8080, 5).timeout.should == 5 end + + it "should provide a reasonable to_s" do + ::Socket.stub!(:new) + Thrift::Socket.new('myhost', 8090).to_s.should == "socket(myhost:8090)" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/ssl_server_socket_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/ssl_server_socket_spec.rb b/lib/rb/spec/ssl_server_socket_spec.rb new file mode 100644 index 0000000..55f3fe2 --- /dev/null +++ b/lib/rb/spec/ssl_server_socket_spec.rb @@ -0,0 +1,34 @@ +# +# 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. +# + +require 'spec_helper' +require File.expand_path("#{File.dirname(__FILE__)}/socket_spec_shared") + +describe 'SSLServerSocket' do + + describe Thrift::SSLServerSocket do + before(:each) do + @socket = Thrift::SSLServerSocket.new(1234) + end + + it "should provide a reasonable to_s" do + @socket.to_s.should == "ssl(socket(:1234))" + end + end +end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/ssl_socket_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/ssl_socket_spec.rb b/lib/rb/spec/ssl_socket_spec.rb index a8bc785..9ee946b 100644 --- a/lib/rb/spec/ssl_socket_spec.rb +++ b/lib/rb/spec/ssl_socket_spec.rb @@ -70,5 +70,9 @@ describe 'SSLSocket' do it "should accept an optional context" do Thrift::SSLSocket.new('localhost', 8080, 5, @context).ssl_context.should == @context end + + it "should provide a reasonable to_s" do + Thrift::SSLSocket.new('myhost', 8090).to_s.should == "ssl(socket(myhost:8090))" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/lib/rb/spec/unix_socket_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/unix_socket_spec.rb b/lib/rb/spec/unix_socket_spec.rb index cb6cff3..0bea829 100644 --- a/lib/rb/spec/unix_socket_spec.rb +++ b/lib/rb/spec/unix_socket_spec.rb @@ -42,6 +42,11 @@ describe 'UNIXSocket' do ::UNIXSocket.stub!(:new) Thrift::UNIXSocket.new(@path, 5).timeout.should == 5 end + + it "should provide a reasonable to_s" do + ::UNIXSocket.stub!(:new) + Thrift::UNIXSocket.new(@path).to_s.should == "domain(#{@path})" + end end describe Thrift::UNIXServerSocket do @@ -103,5 +108,9 @@ describe 'UNIXSocket' do handle.stub!(:closed?).and_return(true) @socket.should be_closed end + + it "should provide a reasonable to_s" do + @socket.to_s.should == "domain(#{@path})" + end end end http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/test/crossrunner/report.py ---------------------------------------------------------------------- diff --git a/test/crossrunner/report.py b/test/crossrunner/report.py index 75f36db..5878222 100644 --- a/test/crossrunner/report.py +++ b/test/crossrunner/report.py @@ -158,6 +158,7 @@ class ExecReporter(TestReporter): 'client': list(map(re.compile, [ '[Cc]onnection refused', 'Could not connect to', + 'Could not open UNIX ', # domain socket (rb) 'ECONNREFUSED', 'econnrefused', # erl 'CONNECTION-REFUSED-ERROR', # cl http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/test/rb/integration/TestClient.rb ---------------------------------------------------------------------- diff --git a/test/rb/integration/TestClient.rb b/test/rb/integration/TestClient.rb index beebe44..5259680 100755 --- a/test/rb/integration/TestClient.rb +++ b/test/rb/integration/TestClient.rb @@ -26,19 +26,24 @@ require 'test_helper' require 'thrift' require 'thrift_test' +$domain_socket = nil $protocolType = "binary" $host = "localhost" $port = 9090 $transport = "buffered" + ARGV.each do|a| if a == "--help" puts "Allowed options:" puts "\t -h [ --help ] \t produce help message" + puts "\t--domain-socket arg (=) \t Unix domain socket path - if not empty, host and port are ignored" puts "\t--host arg (=localhost) \t Host to connect" puts "\t--port arg (=9090) \t Port number to listen" - puts "\t--protocol arg (=binary) \t protocol: binary, accel" + puts "\t--protocol arg (=binary) \t protocol: accel, binary, compact, json" puts "\t--transport arg (=buffered) transport: buffered, framed, http" exit + elsif a.start_with?("--domain-socket") + $domain_socket = a.split("=")[1] elsif a.start_with?("--host") $host = a.split("=")[1] elsif a.start_with?("--protocol") @@ -54,7 +59,12 @@ ARGV=[] class SimpleClientTest < Test::Unit::TestCase def setup unless @socket - @socket = Thrift::Socket.new($host, $port) + if $domain_socket.to_s.strip.empty? + @socket = Thrift::Socket.new($host, $port) + else + @socket = Thrift::UNIXSocket.new($domain_socket) + end + if $transport == "buffered" transportFactory = Thrift::BufferedTransport.new(@socket) elsif $transport == "framed" http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/test/rb/integration/TestServer.rb ---------------------------------------------------------------------- diff --git a/test/rb/integration/TestServer.rb b/test/rb/integration/TestServer.rb index bab723a..079298d 100755 --- a/test/rb/integration/TestServer.rb +++ b/test/rb/integration/TestServer.rb @@ -106,19 +106,24 @@ class SimpleHandler end -protocol = "binary" +domain_socket = nil port = 9090 +protocol = "binary" +@protocolFactory = nil transport = "buffered" -@transportFactory = Thrift::BufferedTransportFactory.new -@protocolFactory = Thrift::BinaryProtocolFactory.new +@transportFactory = nil + ARGV.each do|a| if a == "--help" puts "Allowed options:" puts "\t -h [ --help ] \t produce help message" + puts "\t--domain-socket arg (=) \t Unix domain socket path - if not empty, port is ignored" puts "\t--port arg (=9090) \t Port number to listen" - puts "\t--protocol arg (=binary) \t protocol: binary, accel" + puts "\t--protocol arg (=binary) \t protocol: accel, binary, compact, json" puts "\t--transport arg (=buffered) transport: buffered, framed, http" exit + elsif a.start_with?("--domain-socket") + domain_socket = a.split("=")[1] elsif a.start_with?("--protocol") protocol = a.split("=")[1] elsif a.start_with?("--transport") @@ -128,9 +133,7 @@ ARGV.each do|a| end end -if protocol == "binary" - @protocolFactory = Thrift::BinaryProtocolFactory.new -elsif protocol == "" +if protocol == "binary" || protocol.to_s.strip.empty? @protocolFactory = Thrift::BinaryProtocolFactory.new elsif protocol == "compact" @protocolFactory = Thrift::CompactProtocolFactory.new @@ -142,9 +145,7 @@ else raise 'Unknown protocol type' end -if transport == "buffered" - @transportFactory = Thrift::BufferedTransportFactory.new -elsif transport == "" +if transport == "buffered" || transport.to_s.strip.empty? @transportFactory = Thrift::BufferedTransportFactory.new elsif transport == "framed" @transportFactory = Thrift::FramedTransportFactory.new @@ -152,8 +153,17 @@ else raise 'Unknown transport type' end -@handler = SimpleHandler.new +@handler = SimpleHandler.new @processor = Thrift::Test::ThriftTest::Processor.new(@handler) -@transport = Thrift::ServerSocket.new(port) -@server = Thrift::ThreadedServer.new(@processor, @transport, @transportFactory, @protocolFactory) +@transport = nil +if domain_socket.to_s.strip.empty? + @transport = Thrift::ServerSocket.new(port) +else + @transport = Thrift::UNIXServerSocket.new(domain_socket) +end + +@server = Thrift::ThreadedServer.new(@processor, @transport, @transportFactory, @protocolFactory) + +puts "Starting TestServer #{@server.to_s}" @server.serve +puts "done." http://git-wip-us.apache.org/repos/asf/thrift/blob/9aaf2958/test/tests.json ---------------------------------------------------------------------- diff --git a/test/tests.json b/test/tests.json index 9c7668d..99050a1 100644 --- a/test/tests.json +++ b/test/tests.json @@ -373,13 +373,14 @@ "framed" ], "sockets": [ + "domain", "ip" ], "protocols": [ - "compact", "binary", - "json", - "binary:accel" + "binary:accel", + "compact", + "json" ], "workdir": "rb/gen-rb" },