Kosuke Asami
null+****@clear*****
Thu Jul 11 16:32:11 JST 2013
Kosuke Asami 2013-07-11 16:32:11 +0900 (Thu, 11 Jul 2013) New Revision: f6b0285c58425803b2432b7cd577247ba2fd0376 https://github.com/groonga/fluent-plugin-droonga/commit/f6b0285c58425803b2432b7cd577247ba2fd0376 Message: table_create: return appropriate values Modified files: lib/droonga/plugin/groonga/table_create.rb lib/droonga/plugin/handler_groonga.rb test/plugin/groonga/test_table_create.rb test/plugin/test_handler_groonga.rb Modified: lib/droonga/plugin/groonga/table_create.rb (+11 -2) =================================================================== --- lib/droonga/plugin/groonga/table_create.rb 2013-07-11 15:45:42 +0900 (9033bf1) +++ lib/droonga/plugin/groonga/table_create.rb 2013-07-11 16:32:11 +0900 (6c66b1e) @@ -25,18 +25,27 @@ module Droonga @context = context end + def header(return_code, error_message = "") + elapsed_time = Time.now.to_f - @start_time + header = [return_code, @start_time, elapsed_time] + header.push(error_message) unless error_message.empty? + header + end + def execute(request) + @start_time = Time.now.to_f + command_class = Groonga::Command.find("table_create") command = command_class.new("table_create", request) name = command["name"] - return [false] unless name + return [header(Status::INVALID_ARGUMENT, "Should not create anonymous table"), false] unless name options = parse_command(command) Groonga::Schema.define(:context => @context) do |schema| schema.create_table(name, options) end - [true] + [header(Status::SUCCESS), true] end private Modified: lib/droonga/plugin/handler_groonga.rb (+5 -0) =================================================================== --- lib/droonga/plugin/handler_groonga.rb 2013-07-11 15:45:42 +0900 (0fb4294) +++ lib/droonga/plugin/handler_groonga.rb 2013-07-11 16:32:11 +0900 (fb9a160) @@ -29,6 +29,11 @@ module Droonga outputs = command.execute(request) post(outputs) end + + module Status + SUCCESS = 0 + INVALID_ARGUMENT = 65514 + end end end Modified: test/plugin/groonga/test_table_create.rb (+8 -2) =================================================================== --- test/plugin/groonga/test_table_create.rb 2013-07-11 15:45:42 +0900 (980ad94) +++ test/plugin/groonga/test_table_create.rb 2013-07-11 16:32:11 +0900 (5acd10d) @@ -16,12 +16,18 @@ class TableCreateTest < GroongaHandlerTest def test_success @handler.table_create({"name" => "Books"}) - assert_equal([true], @worker.body) + assert_equal( + [[Droonga::GroongaHandler::Status::SUCCESS, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], true], + [normalize_header(@worker.body.first), @worker.body.last] + ) end def test_failure @handler.table_create({}) - assert_equal([false], @worker.body) + assert_equal( + [[Droonga::GroongaHandler::Status::INVALID_ARGUMENT, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], false], + [normalize_header(@worker.body.first), @worker.body.last] + ) end def test_name Modified: test/plugin/test_handler_groonga.rb (+8 -0) =================================================================== --- test/plugin/test_handler_groonga.rb 2013-07-11 15:45:42 +0900 (70b46ee) +++ test/plugin/test_handler_groonga.rb 2013-07-11 16:32:11 +0900 (6dc4f6c) @@ -65,4 +65,12 @@ class GroongaHandlerTest < Test::Unit::TestCase database_dumper = Groonga::DatabaseDumper.new(:database => @database) database_dumper.dump end + + NORMALIZED_START_TIME = Time.parse("2013-07-11T16:04:28+0900").to_i + NORMALIZED_ELAPSED_TIME = 1 + def normalize_header(header) + start_time = NORMALIZED_START_TIME + elapsed_time = NORMALIZED_ELAPSED_TIME + [header[0], start_time, elapsed_time] + end end -------------- next part -------------- HTML����������������������������... Download