[Groonga-commit] groonga/fluent-plugin-kotoumi [master] Create minimu test case for worker

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jan 31 14:07:48 JST 2013


Kouhei Sutou	2013-01-31 14:07:48 +0900 (Thu, 31 Jan 2013)

  New Revision: 3b95964f9ddd88cdc2ea5d5ddf4a78fb5eb4e059
  https://github.com/groonga/fluent-plugin-kotoumi/commit/3b95964f9ddd88cdc2ea5d5ddf4a78fb5eb4e059

  Log:
    Create minimu test case for worker

  Added files:
    test/fixtures/document.grn
    test/test_worker.rb
  Modified files:
    test/helper.rb

  Added: test/fixtures/document.grn (+21 -0) 100644
===================================================================
--- /dev/null
+++ test/fixtures/document.grn    2013-01-31 14:07:48 +0900 (499a1a2)
@@ -0,0 +1,21 @@
+table_create Bigram TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer NormalizerAuto
+
+
+table_create Sections TABLE_HASH_KEY ShortText
+column_create Sections title COLUMN_SCALAR ShortText
+column_create Sections content COLUMN_SCALAR Text
+
+load --table Sections
+[
+{"_key": "1.1", "title": "Groonga overview", "content": "Groonga is a fast and accurate full text search engine based on inverted index. One of the characteristics of groonga is that a newly registered document instantly appears in search results. Also, groonga allows updates without read locks. These characteristics result in superior performance on real-time applications."},
+{"_key": "1.2", "title": "Full text search and Instant update", "content": "In widely used DBMSs, updates are immediately processed, for example, a newly registered record appears in the result of the next query. In contrast, some full text search engines do not support instant updates, because it is difficult to dynamically update inverted indexes, the underlying data structure."},
+{"_key": "1.3", "title": "Column store and aggregate query", "content": "People can collect more than enough data in the Internet era. However, it is difficult to extract informative knowledge from a large database, and such a task requires a many-sided analysis through trial and error. For example, search refinement by date, time and location may reveal hidden patterns. Aggregate queries are useful to perform this kind of tasks."},
+{"_key": "1.4", "title": "Inverted index and tokenizer", "content": "An inverted index is a traditional data structure used for large-scale full text search. A search engine based on inverted index extracts index terms from a document when it is added. Then in retrieval, a query is divided into index terms to find documents containing those index terms. In this way, index terms play an important role in full text search and thus the way of extracting index terms is a key to a better search engine."},
+{"_key": "1.5", "title": "Sharable storage and read lock-free", "Multi-core processors are mainstream today and the number of cores per processor is increasing. In order to exploit multiple cores, executing multiple queries in parallel or dividing a query into sub-queries for parallel processing is becoming more important."},
+{"_key": "1.6", "title": "Geo-location (latitude and longitude) search", "content": "Location services are getting more convenient because of mobile devices with GPS. For example, if you are going to have lunch or dinner at a nearby restaurant, a local search service for restaurants may be very useful, and for such services, fast geo-location search is becoming more important."},
+{"_key": "1.7", "title": "Groonga library", "content": "The basic functions of groonga are provided in a C library and any application can use groonga as a full text search engine or a column-oriented database. Also, libraries for languages other than C/C++, such as Ruby, are provided in related projects. See related projects for details."},
+{"_key": "1.8", "title": "Groonga server", "contnet": "Groonga provides a built-in server command which supports HTTP, the memcached binary protocol and the groonga query transfer protocol (gqtp). Also, a groonga server supports query caching, which significantly reduces response time for repeated read queries. Using this command, groonga is available even on a server that does not allow you to install new libraries."},
+{"_key": "1.9", "title": "Groonga storage engine", "content": "Groonga works not only as an independent column-oriented DBMS but also as storage engines of well-known DBMSs. For example, mroonga is a MySQL pluggable storage engine using groonga. By using mroonga, you can use groonga for column-oriented storage and full text search. A combination of a built-in storage engine, MyISAM or InnoDB, and a groonga-based full text search engine is also available. All the combinations have good and bad points and the best one depends on the application. See related projects for details."}
+]

  Modified: test/helper.rb (+76 -1)
===================================================================
--- test/helper.rb    2013-01-30 17:55:01 +0900 (301d632)
+++ test/helper.rb    2013-01-31 14:07:48 +0900 (d733ef8)
@@ -13,6 +13,8 @@
 # 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 "pathname"
+
 require 'rubygems'
 require 'bundler'
 begin
@@ -39,7 +41,80 @@ unless ENV.has_key?('VERBOSE')
   $log = null_logger
 end
 
-require 'fluent/plugin/out_socket_io'
+module Sandbox
+  class << self
+    def included(base)
+      base.setup :setup_sandbox, :before => :prepend
+      base.teardown :teardown_sandbox, :after => :append
+    end
+  end
+
+  def setup_sandbox
+    setup_temporary_directory
+
+    setup_context
+
+    @database_path = @temporary_directory + "database"
+    @database = nil
+  end
+
+  def setup_temporary_directory
+    @base_temporary_directory = Pathname(File.dirname(__FILE__)) + "tmp"
+    memory_file_system = "/dev/shm"
+    if File.exist?(memory_file_system)
+      FileUtils.mkdir_p(@base_temporary_directory.parent.to_s)
+      FileUtils.rm_f(@base_temporary_directory.to_s)
+      FileUtils.ln_s(memory_file_system, @base_temporary_directory.to_s)
+    else
+      FileUtils.mkdir_p(@base_temporary_directory.to_s)
+    end
+
+    @temporary_directory = @base_temporary_directory + "fluent-plugin-kotoumi"
+    FileUtils.rm_rf(@temporary_directory.to_s)
+    FileUtils.mkdir_p(@temporary_directory.to_s)
+  end
+
+  def setup_context
+    Groonga::Context.default = nil
+    Groonga::Context.default_options = nil
+  end
+
+  def restore(dumped_command)
+    context = Groonga::Context.new
+    database = context.create_database(@database_path.to_s)
+    context.restore(dumped_command)
+    database.close
+    context.close
+  end
+
+  def teardown_sandbox
+    Groonga::Context.default.close
+    Groonga::Context.default = nil
+    GC.start
+    teardown_temporary_directory
+  end
+
+  def teardown_temporary_directory
+    FileUtils.rm_rf(@temporary_directory.to_s)
+    FileUtils.rm_rf(@base_temporary_directory.to_s)
+  end
+end
+
+module Fixture
+  def fixture_directory
+    File.join(File.dirname(__FILE__), "fixtures")
+  end
+
+  def fixture_path(*path_components)
+    File.join(fixture_directory, *path_components)
+  end
+
+  def fixture_data(*path_components)
+    File.read(fixture_path(*path_components))
+  end
+end
 
 class Test::Unit::TestCase
+  include Sandbox
+  include Fixture
 end

  Added: test/test_worker.rb (+71 -0) 100644
===================================================================
--- /dev/null
+++ test/test_worker.rb    2013-01-31 14:07:48 +0900 (c3d6335)
@@ -0,0 +1,71 @@
+# Copyright (C) 2013 Kotoumi 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 "helper"
+
+require "kotoumi/worker"
+
+class WorkerTest < Test::Unit::TestCase
+  def setup
+    setup_database
+    setup_worker
+  end
+
+  def teardown
+    teardown_worker
+  end
+
+  private
+  def setup_database
+    restore(fixture_data("document.grn"))
+  end
+
+  def setup_worker
+    @worker = Kotoumi::Worker.new(@database_path.to_s, "KotoumiQueue")
+  end
+
+  def teardown_worker
+    @worker.shutdown
+    @worker = nil
+  end
+
+  private
+  class SearchTest < self
+    def test_minimum
+      expected = {
+        "main-search-result" => {
+          :attributes => [
+            {
+              :name   => "name",
+              :type   => "ShortText",
+              :vector => false
+            },
+            {
+              :name   => "age",
+              :type   => "UInt32",
+              :vector => false
+            },
+          ],
+          :count => 123,
+          :elapsedTime => 123.456,
+          :records => [["a", 10], ["b", 20]],
+          :startTime => "2001-08-02T10:45:23.5+09:00",
+        }
+      }
+      assert_equal(expected,
+                   @worker.process_message({}))
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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