Respect timeout when doing get_file_data
[ruby-mogilefs-client.git] / test / test_mysql.rb
blob11cec4404b2990b00810b15cd9c18d08d2be363b
1 require 'test/setup'
2 require 'mogilefs/mysql'
4 class MogileFS::Mysql
5   public :refresh_device
6   public :refresh_domain
7 end
9 class TestMogileFS__Mysql < Test::Unit::TestCase
11   def setup
12     @my = FakeMysql.new
13     @mg = MogileFS::Mysql.new(:mysql => @my)
14     super
15   end
17   def test_refresh_device
18     expect = {
19      1=>
20       {:hostip=>"10.0.0.1",
21        :http_get_port=>7600,
22        :http_port=>7500,
23        :altip=>"192.168.0.1"},
24      2=>
25       {:hostip=>"10.0.0.2",
26        :http_get_port=>7600,
27        :http_port=>7500,
28        :altip=>"192.168.0.2"},
29      3=>
30       {:hostip=>"10.0.0.3",
31        :http_get_port=>7500,
32        :http_port=>7500,
33        :altip=>"10.0.0.3"},
34      4=>
35       {:hostip=>"10.0.0.4",
36        :http_get_port=>7500,
37        :http_port=>7500,
38        :altip=>"10.0.0.4"}
39     }
40     assert_equal expect, @mg.refresh_device
41   end
43   def test_refresh_domain
44     expect = { 'test' => 1, 'foo' => 2 }
45     assert_equal expect, @mg.refresh_domain
46   end
48   def test_get_paths
49     @my.expect << [ [ 12 ] ] # fid
50     @my.expect << [ [ 1 ], [ 3 ] ] # devids
51     expect = [ "http://10.0.0.1:7600/dev1/0/000/000/0000000012.fid",
52                "http://10.0.0.3:7500/dev3/0/000/000/0000000012.fid" ]
53     assert_equal expect, @mg._get_paths(:domain => 'test', :key => 'fookey')
54   end
56   def test_get_paths_alt
57     @my.expect <<  [ [ 12 ] ] # fid
58     @my.expect << [ [ 1 ], [ 3 ] ] # devids
59     expect = [ "http://192.168.0.1:7600/dev1/0/000/000/0000000012.fid",
60                "http://10.0.0.3:7500/dev3/0/000/000/0000000012.fid"]
61     params = { :domain => 'test', :key => 'fookey', :zone => 'alt' }
62     assert_equal expect, @mg._get_paths(params)
63   end
65   def test_list_keys
66     expect_full = [ [ 'foo', 123, 2 ], [ 'bar', 456, 1 ] ]
67     result_full = eval(expect_full.inspect)
68     result_full.each { |x| (1..2).each { |i| x[i] = x[i].to_s } }
69     expect_keys = [ [ 'foo', 'bar' ], 'bar' ]
70     @my.expect << result_full
71     full = []
72     keys = @mg._list_keys('test') do |dkey,length,devcount|
73       full << [ dkey, length, devcount ]
74     end
75     assert_equal expect_keys, keys
76     assert_equal expect_full, full
77   end
79   def test_list_keys_empty
80     @my.expect << []
81     assert_nil @mg._list_keys('test')
82   end
84   def test_size
85     @my.expect << [ [ '123' ] ]
86     assert_equal 123, @mg._size('test', 'foo')
88     @my.expect << [ [ '456' ] ]
89     assert_equal 456, @mg._size('test', 'foo')
90   end
92   def test_sleep
93     assert_nothing_raised { assert_equal({}, @mg.sleep(:duration => 1)) }
94   end
96 end