Kouhei Sutou
null+****@clear*****
Thu Jul 17 20:19:56 JST 2014
Kouhei Sutou 2014-07-17 20:19:56 +0900 (Thu, 17 Jul 2014) New Revision: 8fd41627443b1301da62daebc024dcff6c41d3f2 https://github.com/droonga/droonga-engine/commit/8fd41627443b1301da62daebc024dcff6c41d3f2 Message: single-volume: support parsing address Modified files: lib/droonga/catalog/single_volume.rb test/unit/catalog/test_single_volume.rb Modified: lib/droonga/catalog/single_volume.rb (+32 -3) =================================================================== --- lib/droonga/catalog/single_volume.rb 2014-07-17 19:42:23 +0900 (1710ecb) +++ lib/droonga/catalog/single_volume.rb 2014-07-17 20:19:56 +0900 (7ac4a78) @@ -18,21 +18,50 @@ module Droonga class SingleVolume def initialize(data) @data = data + parse_address end def address @data["address"] end + def host + @host + end + + def port + @port + end + + def tag + @tag + end + + def name + @name + end + def node - ip_address_and_port, path = address.split("/") - tag = path.split(".").first - "#{ip_address_and_port}/#{tag}" + "#{host}:#{port}/#{tag}" end def all_nodes @all_nodes ||= [node] end + + private + def parse_address + if /\A(.+):(\d+)\/([^.]+)\.(.+)\z/ =~ address + @host = $1 + @port = $2.to_i + @tag = $3 + @name = $4 + else + format = "${host_name}:${port_number}/${tag}.${name}" + message = "volume address must be <#{format}> format: <#{address}>" + raise ArgumentError, message + end + end end end end Modified: test/unit/catalog/test_single_volume.rb (+35 -18) =================================================================== --- test/unit/catalog/test_single_volume.rb 2014-07-17 19:42:23 +0900 (a4a0577) +++ test/unit/catalog/test_single_volume.rb 2014-07-17 20:19:56 +0900 (68f377b) @@ -16,25 +16,42 @@ require "droonga/catalog/single_volume" class CatalogSingleVolumeTest < Test::Unit::TestCase - def create_single_volume(data) - Droonga::Catalog::SingleVolume.new(data) - end + class AddressTest < self + def setup + data = { + "address" => "127.0.0.1:10047/tag.000", + } + @volume = Droonga::Catalog::SingleVolume.new(data) + end - def test_address - data = { - "address" => "127.0.0.1:10047/volume.000", - } - volume = create_single_volume(data) - assert_equal("127.0.0.1:10047/volume.000", - volume.address) - end + def test_address + assert_equal("127.0.0.1:10047/tag.000", + @volume.address) + end + + def test_host + assert_equal("127.0.0.1", @volume.host) + end + + def test_port + assert_equal(10047, @volume.port) + end + + def test_tag + assert_equal("tag", @volume.tag) + end + + def test_name + assert_equal("000", @volume.name) + end + + def test_node + assert_equal("127.0.0.1:10047/tag", @volume.node) + end - def test_all_nodes - data = { - "address" => "127.0.0.1:10047/volume.000", - } - volume = create_single_volume(data) - assert_equal(["127.0.0.1:10047/volume"], - volume.all_nodes) + def test_all_nodes + assert_equal(["127.0.0.1:10047/tag"], + @volume.all_nodes) + end end end -------------- next part -------------- HTML����������������������������...Download