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.



265
266
267
268
269
270
271
272
273
274
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 265

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.



264
265
266
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 264

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



264
265
266
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 264

def port
  @port
end

Instance Method Details

#ensure_databaseObject



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 304

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", grn_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



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 276

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



350
351
352
353
354
355
356
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 350

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

#use_persistent_cache?Boolean

Returns:

  • (Boolean)


346
347
348
# File 'lib/groonga-query-log/command/run-regression-test.rb', line 346

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