Kouhei Sutou
null+****@clear*****
Mon Jan 27 15:41:43 JST 2014
Kouhei Sutou 2014-01-27 15:41:43 +0900 (Mon, 27 Jan 2014) New Revision: 1ab5dfe6c8b9fe89e1c348c8b2d2aae92cefa0cd https://github.com/droonga/fluent-plugin-droonga/commit/1ab5dfe6c8b9fe89e1c348c8b2d2aae92cefa0cd Message: Support three or more zones Modified files: lib/droonga/catalog/base.rb test/unit/catalog/test_version1.rb Modified: lib/droonga/catalog/base.rb (+8 -3) =================================================================== --- lib/droonga/catalog/base.rb 2014-01-27 12:59:15 +0900 (f633df2) +++ lib/droonga/catalog/base.rb 2014-01-27 15:41:43 +0900 (74c0326) @@ -34,9 +34,7 @@ module Droonga @data["datasets"].each do |name, dataset| number_of_partitions = dataset["number_of_partitions"] next if number_of_partitions < 2 - total_weight = dataset["ring"].reduce do |a, b| - a[1]["weight"] + b[1]["weight"] - end + total_weight = compute_total_weight(dataset) continuum = [] dataset["ring"].each do |key, value| points = number_of_partitions * 160 * value["weight"] / total_weight @@ -135,6 +133,13 @@ module Droonga end end end + + private + def compute_total_weight(dataset) + dataset["ring"].reduce(0) do |result, zone| + result + zone[1]["weight"] + end + end end end end Modified: test/unit/catalog/test_version1.rb (+34 -0) =================================================================== --- test/unit/catalog/test_version1.rb 2014-01-27 12:59:15 +0900 (ecd0c21) +++ test/unit/catalog/test_version1.rb 2014-01-27 15:41:43 +0900 (30fcf20) @@ -64,4 +64,38 @@ class CatalogTest < Test::Unit::TestCase def base_path File.dirname(catalog_path) end + + class DataSetTest < self + class RingTest < self + class TotalWeightTest < self + def setup + end + + def test_three_zones + dataset = { + "ring" => { + "zone1" => { + "weight" => 10, + }, + "zone2" => { + "weight" => 20, + }, + "zone3" => { + "weight" => 30, + }, + } + } + assert_equal(10 + 20 + 30, + total_weight(dataset)) + end + + private + def total_weight(dataset) + catalog = Droonga::Catalog::Version1.new({"datasets" => []}, + "base-path") + catalog.send(:compute_total_weight, dataset) + end + end + end + end end -------------- next part -------------- HTML����������������������������... 下載