[Groonga-commit] groonga/fluent-plugin-droonga at ce6b839 [master] Add "handler_groonga"" plugin and "table_create" command

Back to archive index

Kosuke Asami null+****@clear*****
Tue Jul 9 15:37:34 JST 2013


Kosuke Asami	2013-07-09 15:37:34 +0900 (Tue, 09 Jul 2013)

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

  Message:
    Add "handler_groonga"" plugin and "table_create" command

  Added files:
    lib/droonga/plugin/handler_groonga.rb
    test/plugin/test_handler_groonga.rb

  Added: lib/droonga/plugin/handler_groonga.rb (+36 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/plugin/handler_groonga.rb    2013-07-09 15:37:34 +0900 (0ec44c1)
@@ -0,0 +1,36 @@
+# -*- 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 GroongaHandler < Droonga::Handler
+    Droonga::HandlerPlugin.register("groonga", self)
+
+    command :table_create
+    def table_create(request)
+      name = request["name"]
+      Groonga::Schema.define(:context => @context) do |schema|
+        schema.create_table(name)
+      end
+      outputs = [true]
+      post(outputs)
+    end
+  end
+end

  Added: test/plugin/test_handler_groonga.rb (+82 -0) 100644
===================================================================
--- /dev/null
+++ test/plugin/test_handler_groonga.rb    2013-07-09 15:37:34 +0900 (cd5a80e)
@@ -0,0 +1,82 @@
+# 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_groonga"
+
+class Worker
+  attr_reader :context, :body
+
+  def initialize()
+    @context = Groonga::Context.default
+  end
+
+  def post(body, destination=nil)
+    @body = body
+  end
+end
+
+class GroongaHandlerTest < Test::Unit::TestCase
+  def setup
+    setup_database
+    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 teardown_database
+    @database.close
+    @database = nil
+    FileUtils.rm_rf(@database_path.dirname.to_s)
+  end
+
+  def setup_handler
+    @worker = Worker.new
+    @handler = Droonga::GroongaHandler.new(@worker)
+  end
+
+  def teardown_handler
+    @handler = nil
+  end
+
+  private
+  def dump
+    database_dumper = Groonga::DatabaseDumper.new(:database => @database)
+    database_dumper.dump
+  end
+
+  class TableCreateTest < self
+    def test_success
+      @handler.table_create({"name" => "Books"})
+      assert_equal([true], @worker.body)
+    end
+
+    def test_name
+      @handler.table_create({"name" => "Books"})
+      assert_equal(<<-SCHEMA, dump)
+table_create Books TABLE_NO_KEY
+      SCHEMA
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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