YUKI Hiroshi
null+****@clear*****
Thu Nov 28 10:20:39 JST 2013
YUKI Hiroshi 2013-11-28 10:20:39 +0900 (Thu, 28 Nov 2013) New Revision: 108b5e14b3a5419ebde89ccf4c29405e8dc3ace4 https://github.com/droonga/fluent-plugin-droonga/commit/108b5e14b3a5419ebde89ccf4c29405e8dc3ace4 Message: Split tests about search distributor plugin for each query Modified files: test/unit/plugin/distributor/test_search.rb Modified: test/unit/plugin/distributor/test_search.rb (+302 -0) =================================================================== --- test/unit/plugin/distributor/test_search.rb 2013-11-28 10:12:47 +0900 (d9acfc8) +++ test/unit/plugin/distributor/test_search.rb 2013-11-28 10:20:39 +0900 (2e4378b) @@ -189,6 +189,7 @@ class SearchDistributorTest < Test::Unit::TestCase "replica" => "random", } message << searcher + assert_equal(message, @posted.last.last) end @@ -367,4 +368,305 @@ class SearchDistributorTest < Test::Unit::TestCase message << searcher assert_equal(message, @posted.last.last) end + + + def test_no_output + envelope = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "no_output" => { + "source" => "User", + }, + }, + }, + } + + @plugin.process("search", envelope) + + message = [] + + gatherer = { + "type" => "gather", + "body" => { + }, + "inputs" => [ + ], + "post" => true, + } + message << gatherer + searcher = { + "type" => "broadcast", + "command" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "no_output" => { + "source" => "User", + }, + }, + }, + "outputs" => [ + ], + "replica" => "random", + } + message << searcher + assert_equal(message, @posted.last.last) + end + + + def test_no_records_element + envelope = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "no_records" => { + "source" => "User", + "output" => { + "elements" => ["count"], + }, + }, + }, + }, + } + + @plugin.process("search", envelope) + + message = [] + + reducer = { + "type" => "reduce", + "body" => { + "no_records" => { + "no_records_reduced" => { + "count" => { + "type" => "sum", + }, + }, + }, + }, + "inputs" => ["no_records"], + "outputs" => ["no_records_reduced"], + } + message << reducer + + gatherer = { + "type" => "gather", + "body" => { + "no_records_reduced" => "no_records", + }, + "inputs" => [ + "no_records_reduced", + ], + "post" => true, + } + message << gatherer + searcher = { + "type" => "broadcast", + "command" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "no_records" => { + "source" => "User", + "output" => { + "elements" => ["count"], + "limit" => 0, + }, + }, + }, + }, + "outputs" => [ + "no_records", + ], + "replica" => "random", + } + message << searcher + assert_equal(message, @posted.last.last) + end + + + def test_no_output_limit + envelope = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "no_limit" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + }, + }, + }, + }, + } + + @plugin.process("search", envelope) + + message = [] + + reducer = { + "type" => "reduce", + "body" => { + "no_limit" => { + "no_limit_reduced" => { + "count" => { + "type" => "sum", + }, + "records" => { + "type" => "sort", + "order" => ["<"], + "offset" => 0, + "limit" => 0, + }, + }, + }, + }, + "inputs" => ["no_limit"], + "outputs" => ["no_limit_reduced"], + } + message << reducer + + gatherer = { + "type" => "gather", + "body" => { + "no_limit_reduced" => "no_limit", + }, + "inputs" => [ + "no_limit_reduced", + ], + "post" => true, + } + message << gatherer + searcher = { + "type" => "broadcast", + "command" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "no_limit" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "offset" => 0, + "limit" => 0, + }, + }, + }, + }, + "outputs" => [ + "no_limit", + ], + "replica" => "random", + } + message << searcher + assert_equal(message, @posted.last.last) + end + + + def test_have_records + envelope = { + "type" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "have_records" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "attributes" => ["_key", "name", "age"], + "offset" => 1, + "limit" => 2, + }, + }, + }, + }, + } + + @plugin.process("search", envelope) + + message = [] + + reducer = { + "type" => "reduce", + "body" => { + "have_records" => { + "have_records_reduced" => { + "count" => { + "type" => "sum", + }, + "records" => { + "type" => "sort", + "order" => ["<"], + "offset" => 1, + "limit" => 2, + }, + }, + }, + }, + "inputs" => ["have_records"], + "outputs" => ["have_records_reduced"], + } + message << reducer + + gatherer = { + "type" => "gather", + "body" => { + "have_records_reduced" => "have_records", + }, + "inputs" => [ + "have_records_reduced", + ], + "post" => true, + } + message << gatherer + searcher = { + "type" => "broadcast", + "command" => "search", + "dataset" => "Droonga", + "body" => { + "queries" => { + "have_records" => { + "source" => "User", + "output" => { + "format" => "complex", + "elements" => ["count", "records"], + "attributes" => ["_key", "name", "age"], + "offset" => 0, + "limit" => 3, + }, + }, + }, + }, + "outputs" => [ + "have_records", + ], + "replica" => "random", + } + message << searcher + assert_equal(message, @posted.last.last) + end + + # XXX we should write cases for... + # - sortBy(simple) + # - sortBy(rich) + # - sortBy(rich) with offset + # - sortBy(rich) with limit + # - sortBy(rich) with offset and limit + # - sortBy(simple) + output(limit, offset) + # - sortBy(rich) + # + output(limit, offset) + # - sortBy(rich) with offset + # + output(limit, offset) + # - sortBy(rich) with limit + # + output(limit, offset) + # - sortBy(rich) with offset and limit + # + output(limit, offset) + # and, we have to write cases for both unlimited and limited cases... end -------------- next part -------------- HTML����������������������������... Download