[Groonga-commit] droonga/fluent-plugin-droonga at 2396d51 [master] Add Slice

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Mar 21 16:12:46 JST 2014


Kouhei Sutou	2014-03-21 16:12:46 +0900 (Fri, 21 Mar 2014)

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

  Message:
    Add Slice

  Added files:
    lib/droonga/catalog/slice.rb
    test/unit/catalog/test_slice.rb

  Added: lib/droonga/catalog/slice.rb (+42 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/catalog/slice.rb    2014-03-21 16:12:46 +0900 (1fda8ca)
@@ -0,0 +1,42 @@
+# Copyright (C) 2014 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/catalog/volume"
+
+module Droonga
+  module Catalog
+    class Slice
+      def initialize(data)
+        @data = data
+      end
+
+      def weight
+        @data["weight"] || 1
+      end
+
+      def label
+        @data["label"]
+      end
+
+      def boundary
+        @data["boundary"]
+      end
+
+      def volume
+        @volume ||= Volume.create(@data["volume"])
+      end
+    end
+  end
+end

  Added: test/unit/catalog/test_slice.rb (+87 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/catalog/test_slice.rb    2014-03-21 16:12:46 +0900 (23aeaaf)
@@ -0,0 +1,87 @@
+# Copyright (C) 2014 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/catalog/slice"
+
+class CatalogSliceTest < Test::Unit::TestCase
+  private
+  def create_slice(data)
+    Droonga::Catalog::Slice.new(data)
+  end
+
+  class WeightTest < self
+    def test_default
+      data = {
+      }
+      slice = create_slice(data)
+      assert_equal(1, slice.weight)
+    end
+
+    def test_specified
+      data = {
+        "weight" => 29,
+      }
+      slice = create_slice(data)
+      assert_equal(29, slice.weight)
+    end
+  end
+
+  class LabelTest < self
+    def test_default
+      data = {
+      }
+      slice = create_slice(data)
+      assert_nil(slice.label)
+    end
+
+    def test_specified
+      data = {
+        "label" => "High",
+      }
+      slice = create_slice(data)
+      assert_equal("High", slice.label)
+    end
+  end
+
+  class BoundaryTest < self
+    def test_default
+      data = {
+      }
+      slice = create_slice(data)
+      assert_nil(slice.boundary)
+    end
+
+    def test_specified
+      data = {
+        "boundary" => "2014-03-21",
+      }
+      slice = create_slice(data)
+      assert_equal("2014-03-21", slice.boundary)
+    end
+  end
+
+  class VolumeTest < self
+    def test_single
+      data = {
+        "volume" => {
+          "address" => "127.0.0.1:10047/volume.000",
+        },
+      }
+      slice = create_slice(data)
+      assert_equal("127.0.0.1:10047/volume.000",
+                   slice.volume.address)
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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