Class: GroongaQueryLog::Command::RunRegressionTest::GroongaServer
- Inherits:
-
Object
- Object
- GroongaQueryLog::Command::RunRegressionTest::GroongaServer
- Includes:
- Loggable
- Defined in:
- lib/groonga-query-log/command/run-regression-test.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #ensure_database ⇒ Object
-
#initialize(groonga, groonga_options, database_path, options) ⇒ GroongaServer
constructor
A new instance of GroongaServer.
- #run ⇒ Object
- #shutdown ⇒ Object
- #use_persistent_cache? ⇒ Boolean
Methods included from Loggable
Constructor Details
#initialize(groonga, groonga_options, database_path, options) ⇒ GroongaServer
Returns a new instance of GroongaServer.
386 387 388 389 390 391 392 393 394 395 |
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 386 def initialize(groonga, , database_path, ) @input_directory = [:input_directory] || Pathname.new(".") @working_directory = [:working_directory] || Pathname.new(".") @groonga = groonga @groonga_options = @database_path = @working_directory + database_path @host = "127.0.0.1" @port = find_unused_port @options = end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
385 386 387 |
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 385 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
385 386 387 |
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 385 def port @port end |
Instance Method Details
#ensure_database ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 425 def ensure_database if @options[:recreate_database] FileUtils.rm_rf(@database_path.dirname.to_s) end return if @database_path.exist? FileUtils.mkdir_p(@database_path.dirname.to_s) system(@groonga, "-n", @database_path.to_s, "quit") load_files.each do |load_file| if load_file.extname == ".rb" env = { "GROONGA_LOG_PATH" => log_path.to_s, } command = [ RbConfig.ruby, load_file.to_s, @database_path.to_s, ] else env = {} command = [ @groonga, "--log-path", log_path.to_s, "--file", load_file.to_s, @database_path.to_s, ] end command_line = command.join(" ") puts("Running...: #{command_line}") pid = spawn(env, *command) begin pid, status = Process.waitpid2(pid) rescue Interrupt Process.kill(:TERM, pid) pid, status = Process.waitpid2(pid) end unless status.success? raise "Failed to run: #{command_line}" end end end |
#run ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 397 def run return unless @options[:run_queries] arguments = @groonga_options.dup arguments.concat(["--bind-address", @host]) arguments.concat(["--port", @port.to_s]) arguments.concat(["--protocol", "http"]) arguments.concat(["--log-path", log_path.to_s]) if @options[:output_query_log] arguments.concat(["--query-log-path", query_log_path.to_s]) end arguments << "-s" arguments << @database_path.to_s @pid = spawn(@groonga, *arguments) n_retries = 10 begin send_command("status") rescue SystemCallError sleep(1) n_retries -= 1 raise if n_retries.zero? retry end yield if block_given? end |
#shutdown ⇒ Object
471 472 473 474 475 476 477 |
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 471 def shutdown begin send_command("shutdown") rescue SystemCallError end Process.waitpid(@pid) end |
#use_persistent_cache? ⇒ Boolean
467 468 469 |
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 467 def use_persistent_cache? @groonga_options.include?("--cache-base-path") end |