Kouhei Sutou
null+****@clear*****
Sun Nov 25 22:56:57 JST 2012
Kouhei Sutou 2012-11-25 22:56:57 +0900 (Sun, 25 Nov 2012) New Revision: 8669171152193f0903253be3cd2e878cedd86c3b https://github.com/groonga/fluent-plugin-groonga/commit/8669171152193f0903253be3cd2e878cedd86c3b Log: out: add HTTP output but doesn't work yet Modified files: lib/fluent/plugin/out_groonga.rb test/test_output.rb Modified: lib/fluent/plugin/out_groonga.rb (+31 -0) =================================================================== --- lib/fluent/plugin/out_groonga.rb 2012-11-25 22:55:47 +0900 (cd031a1) +++ lib/fluent/plugin/out_groonga.rb 2012-11-25 22:56:57 +0900 (46172d7) @@ -87,6 +87,37 @@ module Fluent config_param :host, :string, :default => "localhost" config_param :port, :integer, :default => 10041 + + def start + @loop = Coolio::Loop.new + end + + def shutdown + @loop.shutdown + @thread.join if @thread + end + + def send(command, arguments) + path = "/d/#{command}" + http_arguments = arguments.collect do |key, value| + "#{CGI.escape(key)}=#{CGI.escape(value)}" + end + unless http_arguments.empty? + path << "?#{http_arguments.join('&')}" + end + client = GroongaHTTPClient.connect(@host, @port) + client.request("GET", path) + @loop.attach(client) + if****@threa*****? + @thread = Thread.new do + @loop.run + @thread = nil + end + end + end + + class GroongaHTTPClient < Coolio::HttpClient + end end class GQTPClient Modified: test/test_output.rb (+62 -0) =================================================================== --- test/test_output.rb 2012-11-25 22:55:47 +0900 (dede1de) +++ test/test_output.rb 2012-11-25 22:56:57 +0900 (78e7e8c) @@ -45,6 +45,68 @@ class GroongaOutputTest < Test::Unit::TestCase EOC end + class HTTPTest < self + setup :before => :append + def setup_real_server + @real_host = "127.0.0.1" + @real_port = 29292 + @real_server_pid = fork do + exit + real_server = TCPServer.new(@real_host, @real_port) + response_config = WEBrick::Config::HTTP.dup.update(:Logger => $log) + real_response = WEBrick::HTTPResponse.new(response_config) + request_headers = nil + request_body = "" + client = real_server.accept + real_server.close + parser = HTTP::Parser.new + parser.on_headers_complete = lambda do |headers| + request_headers = headers + end + parser.on_body = lambda do |chunk| + request_body << chunk + end + parser.on_message_complete = lambda do + real_response.send_response(client) + client.close + end + + loop do + break if client.closed? + data = client.readpartial(4096) + break if data.nil? + parser << data + end + end + end + + teardown + def teardown_real_server + Process.kill(:INT, @pid) + Process.kill(:KILL, @pid) + Process.waitpid(@pid) + end + + def configuration + <<-EOC + protocol http + host #{@real_host} + port #{@real_port} +EOC + end + + class CommandTest < self + def test_basic_command + driver = create_driver("groonga.command.table_create") + time = Time.parse("2012-10-26T08:45:42Z").to_i + driver.emit({"name" => "Users"}, time) + driver.run + # p @request_headers + # p @request_body + end + end + end + class CommandLineTest < self setup :before => :append def setup_command -------------- next part -------------- HTML����������������������������...Download