[Groonga-commit] droonga/fluent-plugin-droonga at d93fdea [master] Follow handler API change

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Dec 19 17:30:28 JST 2013


Kouhei Sutou	2013-12-19 17:30:28 +0900 (Thu, 19 Dec 2013)

  New Revision: d93fdea4ae93655232a018e2c64405e7e5bc21ec
  https://github.com/droonga/fluent-plugin-droonga/commit/d93fdea4ae93655232a018e2c64405e7e5bc21ec

  Message:
    Follow handler API change

  Copied files:
    lib/droonga/test/stub_handler.rb
      (from lib/droonga/test.rb)
  Modified files:
    lib/droonga/test.rb
    test/unit/plugin/handler/test_watch.rb

  Modified: lib/droonga/test.rb (+1 -0)
===================================================================
--- lib/droonga/test.rb    2013-12-19 17:17:38 +0900 (d1f4fc7)
+++ lib/droonga/test.rb    2013-12-19 17:30:28 +0900 (9fc4ac7)
@@ -16,3 +16,4 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 require "droonga/test/stub_distributor"
+require "droonga/test/stub_handler"

  Copied: lib/droonga/test/stub_handler.rb (+20 -1) 64%
===================================================================
--- lib/droonga/test.rb    2013-12-19 17:17:38 +0900 (d1f4fc7)
+++ lib/droonga/test/stub_handler.rb    2013-12-19 17:30:28 +0900 (51ca6b8)
@@ -15,4 +15,23 @@
 # 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/test/stub_distributor"
+module Droonga
+  module Test
+    class StubHandler
+      attr_reader :context, :envelope, :messages
+      def initialize
+        @context = Groonga::Context.default
+        @envelope = {}
+        @messages = []
+      end
+
+      def emit(message)
+        @messages << message
+      end
+
+      def forward(message, destination)
+        @messages << [message, destination]
+      end
+    end
+  end
+end

  Modified: test/unit/plugin/handler/test_watch.rb (+35 -27)
===================================================================
--- test/unit/plugin/handler/test_watch.rb    2013-12-19 17:17:38 +0900 (bda2201)
+++ test/unit/plugin/handler/test_watch.rb    2013-12-19 17:30:28 +0900 (1bc462e)
@@ -23,22 +23,22 @@ class WatchHandlerTest < Test::Unit::TestCase
   def setup
     setup_database
     setup_schema
-    setup_handler
+    setup_plugin
   end
 
   def teardown
-    teardown_handler
+    teardown_plugin
     teardown_database
   end
 
   private
-  def setup_handler
-    @worker = StubWorker.new
-    @handler = Droonga::WatchHandler.new(@worker)
+  def setup_plugin
+    @handler = Droonga::Test::StubHandler.new
+    @plugin = Droonga::WatchHandler.new(@handler)
   end
 
-  def teardown_handler
-    @handler = nil
+  def teardown_plugin
+    @plugin = nil
   end
 
   public
@@ -49,8 +49,8 @@ class WatchHandlerTest < Test::Unit::TestCase
         "condition" => "たいやき",
         "subscriber" => "localhost"
       }
-      mock(@handler).emit([true])
-      @handler.subscribe(request)
+      mock(@plugin).emit([true])
+      @plugin.subscribe(request)
 
       assert_equal(
         ["localhost:23003/output"],
@@ -63,9 +63,9 @@ class WatchHandlerTest < Test::Unit::TestCase
         "condition" => "たいやき",
         "subscriber" => "localhost"
       }
-      @worker.envelope["from"] = "localhost:23004/output"
-      mock(@handler).emit([true])
-      @handler.subscribe(request)
+      @handler.envelope["from"] = "localhost:23004/output"
+      mock(@plugin).emit([true])
+      @plugin.subscribe(request)
 
       assert_equal(
         ["localhost:23004/output"],
@@ -79,9 +79,9 @@ class WatchHandlerTest < Test::Unit::TestCase
         "subscriber" => "localhost",
         "route" => "localhost:23003/output"
       }
-      @worker.envelope["from"] = "localhost:23004/output"
-      mock(@handler).emit([true])
-      @handler.subscribe(request)
+      @handler.envelope["from"] = "localhost:23004/output"
+      mock(@plugin).emit([true])
+      @plugin.subscribe(request)
 
       assert_equal(
         ["localhost:23003/output"],
@@ -91,7 +91,7 @@ class WatchHandlerTest < Test::Unit::TestCase
 
     private
     def actual_routes_for_query(query)
-      @worker.context["Subscriber"].select {|record|
+      @handler.context["Subscriber"].select {|record|
         record[:subscriptions] =~ query.to_json
       }.map {|subscriber|
         subscriber.route.key
@@ -111,8 +111,8 @@ class WatchHandlerTest < Test::Unit::TestCase
         "condition" => "たいやき",
         "subscriber" => "localhost"
       }
-      mock(@handler).emit([true])
-      @handler.unsubscribe(request)
+      mock(@plugin).emit([true])
+      @plugin.unsubscribe(request)
     end
 
     private
@@ -122,8 +122,8 @@ class WatchHandlerTest < Test::Unit::TestCase
         "condition" => "たいやき",
         "subscriber" => "localhost"
       }
-      stub(@handler).emit([true])
-      @handler.subscribe(request)
+      stub(@plugin).emit([true])
+      @plugin.subscribe(request)
     end
   end
 
@@ -139,9 +139,17 @@ class WatchHandlerTest < Test::Unit::TestCase
           "text" => "たいやきおいしいです"
         }
       }
-      @handler.feed(request)
-      assert_equal(request, @worker.body)
-      assert_equal({"to" => ["localhost"]}, @worker.envelope)
+      @plugin.feed(request)
+      assert_equal([
+                     [request,
+                       {
+                         "to"   => "localhost:23003/output",
+                         "type" => "watch.notification",
+                       },
+                     ],
+                   ],
+                   @handler.messages)
+      assert_equal({ "to" => ["localhost"] }, @handler.envelope)
     end
 
     def test_feed_not_match
@@ -150,8 +158,8 @@ class WatchHandlerTest < Test::Unit::TestCase
           "text" => "たこやきおいしいです"
         }
       }
-      @handler.feed(request)
-      assert_nil(@worker.body)
+      @plugin.feed(request)
+      assert_equal([], @handler.messages)
     end
 
     private
@@ -161,8 +169,8 @@ class WatchHandlerTest < Test::Unit::TestCase
         "condition" => "たいやき",
         "subscriber" => "localhost"
       }
-      stub(@handler).emit([true])
-      @handler.subscribe(request)
+      stub(@plugin).emit([true])
+      @plugin.subscribe(request)
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index