Class: GroongaQueryLog::Command::RunRegressionTest::GroongaServer

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/groonga-query-log/command/run-regression-test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#puts

Constructor Details

#initialize(groonga, groonga_options, database_path, options) ⇒ GroongaServer

Returns a new instance of GroongaServer.



462
463
464
465
466
467
468
469
470
471
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 462

def initialize(groonga, groonga_options, database_path, options)
  @input_directory = options[:input_directory] || Pathname.new(".")
  @working_directory = options[:working_directory] || Pathname.new(".")
  @groonga = groonga
  @groonga_options = groonga_options
  @database_path = @working_directory + database_path
  @host = "127.0.0.1"
  @port = find_unused_port
  @options = options
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



461
462
463
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 461

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



461
462
463
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 461

def port
  @port
end

Instance Method Details

#ensure_databaseObject



501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 501

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

#runObject



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 473

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

#shutdownObject



547
548
549
550
551
552
553
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 547

def shutdown
  begin
    send_command("shutdown")
  rescue SystemCallError
  end
  Process.waitpid(@pid)
end

#use_persistent_cache?Boolean

Returns:

  • (Boolean)


543
544
545
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 543

def use_persistent_cache?
  @groonga_options.include?("--cache-base-path")
end