Class: Groonga::QueryLog::Command::RunRegressionTest::GroongaServer
- Inherits:
-
Object
- Object
- Groonga::QueryLog::Command::RunRegressionTest::GroongaServer
- 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, database_path, options) ⇒ GroongaServer
constructor
A new instance of GroongaServer.
- #run ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(groonga, database_path, options) ⇒ GroongaServer
Returns a new instance of GroongaServer.
176 177 178 179 180 181 182 183 184 |
# File 'lib/groonga/query-log/command/run-regression-test.rb', line 176 def initialize(groonga, database_path, ) @input_directory = [:input_directory] || Pathname.new(".") @working_directory = [:working_directory] || Pathname.new(".") @groonga = groonga @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.
175 176 177 |
# File 'lib/groonga/query-log/command/run-regression-test.rb', line 175 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
175 176 177 |
# File 'lib/groonga/query-log/command/run-regression-test.rb', line 175 def port @port end |
Instance Method Details
#ensure_database ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/groonga/query-log/command/run-regression-test.rb', line 215 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") grn_files.each do |grn_file| command = [ @groonga, "--log-path", log_path.to_s, "--file", grn_file.to_s, @database_path.to_s, ] command_line = command.join(" ") puts("Running...: #{command_line}") pid = spawn(*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
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/groonga/query-log/command/run-regression-test.rb', line 186 def run return unless @options[:run_queries] arguments = [ "--bind-address", @host, "--port", @port.to_s, "--protocol", "http", "--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 end |
#shutdown ⇒ Object
245 246 247 248 249 250 251 |
# File 'lib/groonga/query-log/command/run-regression-test.rb', line 245 def shutdown begin send_command("shutdown") rescue SystemCallError end Process.waitpid(@pid) end |