YUKI Hiroshi
null+****@clear*****
Fri Jan 31 17:23:25 JST 2014
YUKI Hiroshi 2014-01-31 17:23:25 +0900 (Fri, 31 Jan 2014) New Revision: deaddbe4a242d887129d5a37faca5f37efcdb75b https://github.com/droonga/fluent-plugin-droonga/commit/deaddbe4a242d887129d5a37faca5f37efcdb75b Message: Migrate tests offset and limit around sortBy and output Modified files: test/unit/plugin/distributor/test_search_planner.rb Modified: test/unit/plugin/distributor/test_search_planner.rb (+186 -0) =================================================================== --- test/unit/plugin/distributor/test_search_planner.rb 2014-01-31 16:56:18 +0900 (3867e99) +++ test/unit/plugin/distributor/test_search_planner.rb 2014-01-31 17:23:25 +0900 (1093de0) @@ -858,6 +858,192 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase gather_message["body"]["users_reduced"]) end end + + class SortByOffsetLimitTest < self + def max_limit + [@sort_by["limit"], @output["limit"]].max + end + + def min_limit + [@sort_by["limit"], @output["limit"]].min + end + + def total_offset + @sort_by["offset"] + @output["offset"] + end + + class RegularRangeTest < self + def setup + @output = { + "elements" => ["records"], + "attributes" => ["_key"], + "offset" => 4, + "limit" => 8, + } + @sort_by = { + "keys" => ["_key"], + "offset" => 1, + "limit" => 2, + } + @request = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "users" => { + "source" => "User", + "sortBy" => @sort_by, + "output" => @output, + }, + }, + }, + } + end + + def test_dependencies + reduce_inputs = ["errors", "users"] + gather_inputs = ["errors_reduced", "users_reduced"] + assert_equal(expected_dependencies(reduce_inputs, gather_inputs), + dependencies) + end + + def test_broadcast_body + changed_sort_by_parameters = { + "offset" => 0, + "limit" => total_offset + max_limit, + } + changed_output_parameters = { + "offset" => 0, + "limit" => total_offset + min_limit, + } + assert_equal({ + "queries" => { + "users" => { + "source" => "User", + "sortBy" => @sort_by.merge(changed_sort_by_parameters), + "output" => @output.merge(changed_output_parameters), + }, + }, + }, + broadcast_message["body"]) + end + + def test_reduce_body + assert_equal({ + "users_reduced" => { + "records" => { + "type" => "sort", + "operators" => [ + { "column" => 0, "operator" => "<" }, + ], + "limit" => total_offset + min_limit, + }, + }, + }, + reduce_message["body"]["users"]) + end + + def test_gather_records + assert_equal({ + "elements" => { + "records" => { + "attributes" => ["_key"], + "offset" => total_offset, + "limit" => min_limit, + }, + }, + "output" => "users", + }, + gather_message["body"]["users_reduced"]) + end + end + + class InfinitOutputLimitTest < self + def setup + @output = { + "elements" => ["records"], + "attributes" => ["_key"], + "offset" => 4, + "limit" => -1, + } + @sort_by = { + "keys" => ["_key"], + "offset" => 1, + "limit" => 2, + } + @request = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "users" => { + "source" => "User", + "sortBy" => @sort_by, + "output" => @output, + }, + }, + }, + } + end + + def test_dependencies + reduce_inputs = ["errors", "users"] + gather_inputs = ["errors_reduced", "users_reduced"] + assert_equal(expected_dependencies(reduce_inputs, gather_inputs), + dependencies) + end + + def test_broadcast_body + changed_sort_by_parameters = { + "offset" => 0, + "limit" => total_offset + max_limit, + } + changed_output_parameters = { + "offset" => 0, + "limit" => total_offset + max_limit, + } + assert_equal({ + "queries" => { + "users" => { + "source" => "User", + "sortBy" => @sort_by.merge(changed_sort_by_parameters), + "output" => @output.merge(changed_output_parameters), + }, + }, + }, + broadcast_message["body"]) + end + + def test_reduce_body + assert_equal({ + "users_reduced" => { + "records" => { + "type" => "sort", + "operators" => [ + { "column" => 0, "operator" => "<" }, + ], + "limit" => total_offset + max_limit, + }, + }, + }, + reduce_message["body"]["users"]) + end + + def test_gather_records + assert_equal({ + "elements" => { + "records" => { + "attributes" => ["_key"], + "offset" => total_offset, + "limit" => max_limit, + }, + }, + "output" => "users", + }, + gather_message["body"]["users_reduced"]) + end + end + end end -------------- next part -------------- HTML����������������������������... Download