Yoji Shidara
null+****@clear*****
Wed Oct 16 15:13:30 JST 2013
Yoji Shidara 2013-10-16 15:13:30 +0900 (Wed, 16 Oct 2013) New Revision: 57abcb793c6981aef2a5c80b9659b652a9afe193 https://github.com/droonga/fluent-plugin-droonga/commit/57abcb793c6981aef2a5c80b9659b652a9afe193 Message: Use "From" as default route for (un)subscribe Modified files: lib/droonga/plugin/handler_watch.rb test/plugin/handler/test_handler_watch.rb Modified: lib/droonga/plugin/handler_watch.rb (+1 -1) =================================================================== --- lib/droonga/plugin/handler_watch.rb 2013-10-16 13:41:56 +0900 (f205bab) +++ lib/droonga/plugin/handler_watch.rb 2013-10-16 15:13:30 +0900 (068af41) @@ -80,7 +80,7 @@ module Droonga def parse_request(request) subscriber = request["subscriber"] condition = request["condition"] - route = request["route"] + route = request["route"] || envelope["From"] raise "invalid request" if subscriber.nil? || subscriber.empty? || condition.nil? query = condition.to_json raise "too long query" if query.size > 4095 Modified: test/plugin/handler/test_handler_watch.rb (+45 -0) =================================================================== --- test/plugin/handler/test_handler_watch.rb 2013-10-16 13:41:56 +0900 (1a422cc) +++ test/plugin/handler/test_handler_watch.rb 2013-10-16 15:13:30 +0900 (55962e3) @@ -91,6 +91,51 @@ class WatchHandlerTest < Test::Unit::TestCase } mock(@handler).emit([true]) @handler.subscribe(request) + + assert_equal( + ["localhost:23003/output"], + actual_routes_for_query("たいやき") + ) + end + + def test_subscribe_route_omitted_from_specified + request = { + "condition" => "たいやき", + "subscriber" => "localhost" + } + @worker.envelope["From"] = "localhost:23004/output" + mock(@handler).emit([true]) + @handler.subscribe(request) + + assert_equal( + ["localhost:23004/output"], + actual_routes_for_query("たいやき") + ) + end + + def test_subscribe_both_route_and_from_specified + request = { + "condition" => "たいやき", + "subscriber" => "localhost", + "route" => "localhost:23003/output" + } + @worker.envelope["From"] = "localhost:23004/output" + mock(@handler).emit([true]) + @handler.subscribe(request) + + assert_equal( + ["localhost:23003/output"], + actual_routes_for_query("たいやき") + ) + end + + private + def actual_routes_for_query(query) + @worker.context["Subscriber"].select {|record| + record[:subscriptions] =~ query.to_json + }.map {|subscriber| + subscriber.route.key + } end end -------------- next part -------------- HTML����������������������������...Download