Skip to content

Commit

Permalink
Migrate tests offset and limit around sortBy and output
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 31, 2014
1 parent 2a4cb70 commit deaddbe
Showing 1 changed file with 186 additions and 0 deletions.
186 changes: 186 additions & 0 deletions test/unit/plugin/distributor/test_search_planner.rb
Expand Up @@ -858,6 +858,192 @@ def test_gather_records
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


Expand Down

0 comments on commit deaddbe

Please sign in to comment.