Kouhei Sutou
null+****@clear*****
Thu Jan 30 15:01:24 JST 2014
Kouhei Sutou 2014-01-30 15:01:24 +0900 (Thu, 30 Jan 2014) New Revision: ed8873ef1f09d0b75815e8e63738c326029216d5 https://github.com/droonga/fluent-plugin-droonga/commit/ed8873ef1f09d0b75815e8e63738c326029216d5 Message: test: add tests for output.format of search Modified files: test/unit/plugin/distributor/test_search_planner.rb Modified: test/unit/plugin/distributor/test_search_planner.rb (+98 -0) =================================================================== --- test/unit/plugin/distributor/test_search_planner.rb 2014-01-30 14:30:03 +0900 (6bbf07f) +++ test/unit/plugin/distributor/test_search_planner.rb 2014-01-30 15:01:24 +0900 (cd639ef) @@ -22,6 +22,28 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase planner.messages end + def broadcast_message(messages) + messages.find do |message| + message["type"] == "broadcast" + end + end + + def gather_message(messages) + messages.find do |message| + message["type"] == "search_gather" + end + end + + def dependencies(messages) + messages.collect do |message| + { + "type" => message["type"], + "inputs" => message["inputs"], + "outputs" => message["outputs"], + } + end + end + class MultipleQueriesTest < self class MultipleOutputsTest < self def setup @@ -1110,4 +1132,80 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase searcher end end + + class FormatTest < self + def setup + @output = { + "format" => "complex", + "elements" => ["records"], + "attributes" => ["_id"], + "offset" => 0, + "limit" => 10, + } + @request = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "users" => { + "source" => "User", + "output" => @output, + }, + }, + }, + } + end + + def messages + @messages ||= plan(@request) + end + + def test_dependencies + assert_equal([ + { + "type" => "search_reduce", + "inputs" => ["errors", "users"], + "outputs" => ["errors_reduced", "users_reduced"], + }, + { + "type" => "search_gather", + "inputs" => ["errors_reduced", "users_reduced"], + "outputs" => nil, + }, + { + "type" => "broadcast", + "inputs" => nil, + "outputs" => ["errors", "users"], + }, + ], + dependencies(messages)) + end + + def test_broadcast_body + changed_output_parameters = { + "format" => "simple" + } + assert_equal({ + "queries" => { + "users" => { + "source" => "User", + "output" => @output.merge(changed_output_parameters), + }, + }, + }, + broadcast_message(messages)["body"]) + end + + def test_gather_records + records =****@outpu*****("type" => "sort") + records.delete("elements") + assert_equal({ + "elements" => { + "records" => records, + }, + "output" => "users", + }, + gather_message(messages)["body"]["users_reduced"]) + end + end end -------------- next part -------------- HTML����������������������������... 下載