YUKI Hiroshi
null+****@clear*****
Fri Jan 31 17:31:27 JST 2014
YUKI Hiroshi 2014-01-31 17:31:27 +0900 (Fri, 31 Jan 2014) New Revision: 0148e7c527c250d7dbd4be18755d4928f3b2f7f8 https://github.com/droonga/fluent-plugin-droonga/commit/0148e7c527c250d7dbd4be18755d4928f3b2f7f8 Message: Migrate tests for offset and limit about output and sort Modified files: test/unit/plugin/distributor/test_search_planner.rb Modified: test/unit/plugin/distributor/test_search_planner.rb (+169 -98) =================================================================== --- test/unit/plugin/distributor/test_search_planner.rb 2014-01-31 17:35:05 +0900 (2ac318b) +++ test/unit/plugin/distributor/test_search_planner.rb 2014-01-31 17:31:27 +0900 (eafc569) @@ -1043,116 +1043,187 @@ class DistributedSearchPlannerTest < Test::Unit::TestCase gather_message["body"]["users_reduced"]) end end - end - end + class InifinitSortLimitTest < self + def setup + @output = { + "elements" => ["records"], + "attributes" => ["_key"], + "offset" => 4, + "limit" => 8, + } + @sort_by = { + "keys" => ["_key"], + "offset" => 1, + "limit" => -1, + } + @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 -=begin - class SingleQueryTest < self - def test_have_sortBy_with_infinity_sort_limit - request = { - "type" => "search", - "dataset" => "Droonga", - "body" => { - "queries" => { - "have_records" => { - "source" => "User", - "sortBy" => { - "keys" => ["name"], - "offset" => 1, - "limit" => -1, - }, - "output" => { - "format" => "complex", - "elements" => ["records"], - "attributes" => ["_key", "name", "age"], - "offset" => 4, - "limit" => 8, + class InifinitBothLimitTest < self + def setup + @output = { + "elements" => ["records"], + "attributes" => ["_key"], + "offset" => 4, + "limit" => -1, + } + @sort_by = { + "keys" => ["_key"], + "offset" => 1, + "limit" => -1, + } + @request = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "users" => { + "source" => "User", + "sortBy" => @sort_by, + "output" => @output, + }, }, }, - }, - }, - } + } + end - limit = 1 + 4 + 8 - expected_plan = [] - expected_plan << reducer(request, { - "records" => { - "type" => "sort", - "operators" => [ - { "column" => 1, "operator" => "<" }, - ], - "limit" => limit, - }, - }) - expected_plan << gatherer(request, :elements => { - "records" => records_mapper( - :offset => 5, - :limit => 8, - :format => "complex", - :attributes => ["_key", "name", "age"], - ), - }) - expected_plan << searcher(request, :sort_offset => 0, - :sort_limit => limit, - :output_offset => 0, - :output_limit => limit) - assert_equal(expected_plan, plan(request)) - 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_have_sortBy_with_infinity_limit - request = { - "type" => "search", - "dataset" => "Droonga", - "body" => { - "queries" => { - "have_records" => { - "source" => "User", - "sortBy" => { - "keys" => ["name"], - "offset" => 1, - "limit" => -1, - }, - "output" => { - "format" => "complex", - "elements" => ["records"], - "attributes" => ["_key", "name", "age"], - "offset" => 4, - "limit" => -1, - }, - }, - }, - }, - } + def test_broadcast_body + changed_sort_by_parameters = { + "offset" => 0, + "limit" => min_limit, + } + changed_output_parameters = { + "offset" => 0, + "limit" => 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 - expected_plan = [] - expected_plan << reducer(request, { - "records" => { - "type" => "sort", - "operators" => [ - { "column" => 1, "operator" => "<" }, - ], - "limit" => -1, - }, - }) - expected_plan << gatherer(request, :elements => { - "records" => records_mapper( - :offset => 5, - :limit => -1, - :format => "complex", - :attributes => ["_key", "name", "age"], - ), - }) - expected_plan << searcher(request, :sort_offset => 0, - :sort_limit => -1, - :output_offset => 0, - :output_limit => -1) - assert_equal(expected_plan, plan(request)) + def test_reduce_body + assert_equal({ + "users_reduced" => { + "records" => { + "type" => "sort", + "operators" => [ + { "column" => 0, "operator" => "<" }, + ], + "limit" => 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 end + end + + + + +=begin + class SingleQueryTest < self def test_have_sortBy_with_multiple_sort_keys request = { "type" => "search", -------------- next part -------------- HTML����������������������������...Download