YUKI Hiroshi
null+****@clear*****
Thu Dec 11 17:01:25 JST 2014
YUKI Hiroshi 2014-12-11 17:01:25 +0900 (Thu, 11 Dec 2014) New Revision: 590849a2d2179a5de0c6c344d5e9389c3f30f717 https://github.com/droonga/droonga-engine/commit/590849a2d2179a5de0c6c344d5e9389c3f30f717 Merged e0f9f34: Merge pull request #30 from piroor/replicas-in-a-branch Message: Simplify API to generate replicas volume from catalog.json Modified files: lib/droonga/catalog/replicas_volume.rb test/unit/catalog/test_dataset.rb test/unit/catalog/test_replicas_volume.rb Modified: lib/droonga/catalog/replicas_volume.rb (+1 -1) =================================================================== --- lib/droonga/catalog/replicas_volume.rb 2014-12-11 16:32:37 +0900 (ea3433d) +++ lib/droonga/catalog/replicas_volume.rb 2014-12-11 17:01:25 +0900 (9a1da2f) @@ -49,7 +49,7 @@ module Droonga replicas = live_replicas(live_nodes) [replicas.sample] when :all - replicas + self.replicas else super end Modified: test/unit/catalog/test_dataset.rb (+4 -1) =================================================================== --- test/unit/catalog/test_dataset.rb 2014-12-11 16:32:37 +0900 (756a1cb) +++ test/unit/catalog/test_dataset.rb 2014-12-11 17:01:25 +0900 (9e51b8f) @@ -97,7 +97,10 @@ class CatalogDatasetTest < Test::Unit::TestCase "replicas" => [], } dataset = create_dataset(data) - assert_equal(Droonga::Catalog::ReplicasVolume.new(nil, []), + raw_dataset = { + "replicas" => [], + } + assert_equal(Droonga::Catalog::ReplicasVolume.new(raw_dataset, raw_dataset), dataset.replicas) end end Modified: test/unit/catalog/test_replicas_volume.rb (+30 -30) =================================================================== --- test/unit/catalog/test_replicas_volume.rb 2014-12-11 16:32:37 +0900 (a2db6e3) +++ test/unit/catalog/test_replicas_volume.rb 2014-12-11 17:01:25 +0900 (3782698) @@ -18,62 +18,62 @@ require "droonga/catalog/replicas_volume" class CatalogReplicasTest < Test::Unit::TestCase private - def create_replicas(data_or_replicas) - Droonga::Catalog::ReplicasVolume.new(nil, data_or_replicas) + def create_replicas(raw_volume) + Droonga::Catalog::ReplicasVolume.new(nil, raw_volume) end class SelectTest < self def setup - volumes = [ - "volume1", - "volume2", - "volume3", - ] - @collection = create_replicas(volumes) + volume = { + "replicas" => [ + { "address" => "volume1:10047/droonga.000" }, + { "address" => "volume2:10047/droonga.000" }, + { "address" => "volume3:10047/droonga.000" }, + ], + } + @collection = create_replicas(volume) end def test_top - assert_equal(["volume1"], @collection.select(:top)) + hosts =****@colle*****(:top).collect do |volume| + volume.address.host + end + assert_equal(["volume1"], + hosts) end def test_random random_volumes =****@colle*****(:random).collect do |volume| - volume.gsub(/\Avolume[123]\z/, "any volume") + volume.address.host.gsub(/\Avolume[123]\z/, "any volume") end assert_equal(["any volume"], random_volumes) end def test_all + hosts =****@colle*****(:all).collect do |volume| + volume.address.host + end assert_equal(["volume1", "volume2", "volume3"], - @collection.select(:all)) + hosts) end end class NodesTest < self - def create_replicas(raw_replicas) - replicas = raw_replicas.collect do |replica| - create_single_volume(replica) - end - super(replicas) - end - - def create_single_volume(data) - Droonga::Catalog::SingleVolume.new(data) - end - def setup - volumes = [ - { "address" => "volume1:10047/droonga.000" }, - { "address" => "volume1:10047/droonga.001" }, - { "address" => "volume2:10047/droonga.002" }, - { "address" => "volume2:10047/droonga.003" }, - ] - @collection = create_replicas(volumes) + volume = { + "replicas" => [ + { "address" => "volume1:10047/droonga.000" }, + { "address" => "volume1:10047/droonga.001" }, + { "address" => "volume2:10047/droonga.002" }, + { "address" => "volume2:10047/droonga.003" }, + ], + } + @replicas = create_replicas(volume) end def test_all_nodes assert_equal(["volume1:10047/droonga", "volume2:10047/droonga"], - @collection.all_nodes) + @replicas.all_nodes) end end end -------------- next part -------------- HTML����������������������������...Download