[Groonga-commit] groonga/fluent-plugin-droonga [master] Start to write a test for output droonga plugin

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Mar 28 16:17:36 JST 2013


Kouhei Sutou	2013-03-28 16:17:36 +0900 (Thu, 28 Mar 2013)

  New Revision: 55061dd8808a9b47907e62dfd0595adb209042b2
  https://github.com/groonga/fluent-plugin-droonga/commit/55061dd8808a9b47907e62dfd0595adb209042b2

  Message:
    Start to write a test for output droonga plugin
    
    It should compare response with expected result.

  Added files:
    test/test_output.rb
  Modified files:
    lib/fluent/plugin/out_droonga.rb

  Modified: lib/fluent/plugin/out_droonga.rb (+6 -1)
===================================================================
--- lib/fluent/plugin/out_droonga.rb    2013-03-28 14:35:54 +0900 (b6f6cf1)
+++ lib/fluent/plugin/out_droonga.rb    2013-03-28 16:17:36 +0900 (3fc0861)
@@ -28,7 +28,7 @@ module Fluent
     def start
       super
       # prefork @workers
-      @worker = Droonga::Worker.new(@database, @queue_name)
+      @worker = create_worker
       @outputs = {}
     end
 
@@ -106,5 +106,10 @@ module Fluent
         output.post("message", response)
       end
     end
+
+    private
+    def create_worker
+      Droonga::Worker.new(@database, @queue_name)
+    end
   end
 end

  Added: test/test_output.rb (+71 -0) 100644
===================================================================
--- /dev/null
+++ test/test_output.rb    2013-03-28 16:17:36 +0900 (1c89137)
@@ -0,0 +1,71 @@
+# 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 "fluent/plugin/out_droonga"
+
+module OutputStub
+  class Worker
+    def initialize(response)
+      @response = response
+    end
+
+    def process_message(record)
+      @response
+    end
+
+    def shutdown
+    end
+  end
+
+  class Output < Fluent::DroongaOutput
+    def initialize(response)
+      @response = response
+      super()
+    end
+
+    def create_worker
+      Worker.new(@response)
+    end
+  end
+end
+
+class OutputTest < Test::Unit::TestCase
+  setup
+  def setup_fluent
+    Fluent::Test.setup
+  end
+
+  def test_emit
+    response = {}
+    driver = create_driver("droonga.message", response)
+    time = Time.parse("2012-10-26T08:45:42Z").to_i
+    driver.run do
+      driver.emit({"replyTo" => "127.0.0.1:2929/droonga.message"}, time)
+    end
+  end
+
+  private
+  def create_driver(tag, response)
+    output = OutputStub::Output.new(response)
+    driver = Fluent::Test::OutputTestDriver.new(output, tag)
+    driver.configure(configuration)
+    driver
+  end
+
+  def configuration
+    <<-EOC
+EOC
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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