[Groonga-commit] groonga/fluent-plugin-droonga at 182b438 [master] Add "add" command

Back to archive index

Kosuke Asami null+****@clear*****
Tue Jul 16 17:52:48 JST 2013


Kosuke Asami	2013-07-16 17:52:48 +0900 (Tue, 16 Jul 2013)

  New Revision: 182b438cf63ba86beb6a8b27ace70a72f2ae1106
  https://github.com/groonga/fluent-plugin-droonga/commit/182b438cf63ba86beb6a8b27ace70a72f2ae1106

  Message:
    Add "add" command
    
    The command name "add" is temporary ... under discussion.

  Added files:
    lib/droonga/plugin/handler_add.rb
    test/plugin/test_handler_add.rb

  Added: lib/droonga/plugin/handler_add.rb (+34 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/plugin/handler_add.rb    2013-07-16 17:52:48 +0900 (b500cc9)
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+#
+# 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 "groonga"
+
+require "droonga/handler"
+
+module Droonga
+  class AddHandler < Droonga::Handler
+    Droonga::HandlerPlugin.register("add", self)
+
+    command :add
+    def add(request)
+      table = @context[request["table"]]
+      table.add(request["key"], request["values"])
+      outputs = [true]
+      post(outputs)
+    end
+  end
+end

  Added: test/plugin/test_handler_add.rb (+84 -0) 100644
===================================================================
--- /dev/null
+++ test/plugin/test_handler_add.rb    2013-07-16 17:52:48 +0900 (4b02389)
@@ -0,0 +1,84 @@
+# 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_add"
+
+class Worker
+  attr_reader :context, :body
+
+  def initialize()
+    @context = Groonga::Context.default
+  end
+
+  def post(body, destination=nil)
+    @body = body
+  end
+end
+
+class AddHandlerTest < Test::Unit::TestCase
+  def setup
+    setup_database
+    setup_schema
+    setup_handler
+  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("Users",
+                          :type => :hash,
+                          :key_type => :short_text) do |table|
+      end
+    end
+  end
+
+  def teardown_database
+    @database.close
+    @database = nil
+    FileUtils.rm_rf(@database_path.dirname.to_s)
+  end
+
+  def setup_handler
+    @worker = Worker.new
+    @handler = Droonga::AddHandler.new(@worker)
+  end
+
+  def teardown_handler
+    @handler = nil
+  end
+
+  public
+  def test_add
+    request = {
+      "table"  => "Users",
+      "key"    => "mori",
+      "values" => {},
+    }
+    @handler.add(request)
+    table =****@worke*****["Users"]
+    assert_equal(["mori"], table.collect(&:key))
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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