class Drnbench::ProtocolAdapter
Attributes
port[R]
Public Class Methods
new(config)
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 22 def initialize(config) @config = config @host = @config.host @port = @config.port @receive_port = @config.receive_port @default_dataset = @config.default_dataset @application_dir = Pathname(@config.application_dir) @node = @config.node @node_options = @config.node_options end
Public Instance Methods
application_file()
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 43 def application_file @application_dir + "application.js" end
start()
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 35 def start setup end
stop()
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 39 def stop teardown end
Private Instance Methods
ready?()
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 73 def ready? begin socket = TCPSocket.new(@host, @port) socket.close true rescue Errno::ECONNREFUSED false end end
setup()
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 48 def setup command = [ @node, application_file.to_s, *@node_options, ] env = { "DROONGA_ENGINE_DEFAULT_DATASET" => @default_dataset, "DROONGA_ENGINE_HOST" => @config.engine.host, "DROONGA_ENGINE_PORT" => @config.engine.port.to_s, "DROONGA_ENGINE_TAG" => @config.engine.tag, "DROONGA_ENGINE_RECEIVE_HOST" => @host, "DROONGA_ENGINE_RECEIVE_PORT" => @receive_port.to_s, } arguments = [env, *command] @pid = Process.spawn(*arguments) wait_until_ready end
teardown()
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 68 def teardown Process.kill(:TERM, @pid) Process.wait(@pid) end
wait_until_ready()
click to toggle source
# File lib/drnbench/server/protocol-adapter.rb, line 83 def wait_until_ready until ready? sleep 1 end end