Yoji Shidara
null+****@clear*****
Tue Oct 15 14:25:15 JST 2013
Yoji Shidara 2013-10-15 14:25:15 +0900 (Tue, 15 Oct 2013) New Revision: 1a4ae484ca674562fd6ea37a18ab77bcf8f5f69c https://github.com/droonga/fluent-plugin-droonga/commit/1a4ae484ca674562fd6ea37a18ab77bcf8f5f69c Message: Add a test case for watch.subscribe Added files: test/plugin/handler/test_handler_watch.rb Added: test/plugin/handler/test_handler_watch.rb (+96 -0) 100644 =================================================================== --- /dev/null +++ test/plugin/handler/test_handler_watch.rb 2013-10-15 14:25:15 +0900 (f3439f8) @@ -0,0 +1,96 @@ +# Copyright (C) 2013 droonga project +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +require "droonga/plugin/handler_watch" + +class WatchHandlerTest < Test::Unit::TestCase + def setup + setup_database + setup_handler + setup_schema + end + + def teardown + teardown_handler + teardown_database + end + + private + def setup_database + FileUtils.rm_rf(@database_path.dirname.to_s) + FileUtils.mkdir_p(@database_path.dirname.to_s) + @database = Groonga::Database.create(:path => @database_path.to_s) + end + + def setup_schema + Groonga::Schema.define do |schema| + schema.create_table("Route", + :type => :hash) do |table| + end + + schema.create_table("Keyword", + :type => :patricia_trie, + :normalizer => "NormalizerAuto") do |table| + end + + schema.create_table("Query", + :type => :hash) do |table| + table.column("keywords", "Keyword", :type => :vector) + end + + schema.create_table("Subscriber", + :type => :hash) do |table| + table.column("subscriptions", "Query", :type => :vector) + table.column("route", "Route") + end + + schema.change_table("Query") do |table| + table.index("Subscriber.subscriptions", :name => "subscribers") + end + + schema.change_table("Keyword") do |table| + table.index("Query.keywords", :name => "queries") + end + end + end + + def teardown_database + @database.close + @database = nil + FileUtils.rm_rf(@database_path.dirname.to_s) + end + + def setup_handler + @worker = StubWorker.new + @handler = Droonga::WatchHandler.new(@worker) + end + + def teardown_handler + @handler = nil + end + + public + class TestSubscribe < self + def test_subscribe + request = { + "route" => "localhost:23003/output", + "condition" => "たいやき", + "subscriber" => "localhost" + } + mock(@handler).emit([true]) + @handler.subscribe(request) + end + end +end -------------- next part -------------- HTML����������������������������... Download