THRIFT-4358: add unix domain socket option to ruby cross tests
Client: rb
This closes #1513
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 '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 @@
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"
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 @@
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 @@
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 @@
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 @@
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."