1 # -*- encoding: binary -*-
3 require 'mogilefs/mysql'
10 class TestMogileFS__Mysql < Test::Unit::TestCase
14 @mg = MogileFS::Mysql.new(:mysql => @my)
18 def test_refresh_device
25 :altip=>"192.168.0.1"},
31 :altip=>"192.168.0.2"},
57 assert_equal expect, @mg.refresh_device
60 def test_refresh_domain
61 expect = { 'test' => 1, 'foo' => 2 }
62 assert_equal expect, @mg.refresh_domain
66 @my.expect << [ [ 12 ] ] # fid
67 @my.expect << [ [ 1 ], [ 3 ] ] # devids
68 expect = [ "http://10.0.0.1:7600/dev1/0/000/000/0000000012.fid",
69 "http://10.0.0.3:7500/dev3/0/000/000/0000000012.fid" ]
70 assert_equal expect, @mg._get_paths(:domain => 'test', :key => 'fookey')
73 def test_get_paths_bad_device
74 @my.expect << [ [ 12 ] ] # fid
75 @my.expect << [ [ 1 ], [ 6 ] ] # devids
76 expect = [ "http://10.0.0.1:7600/dev1/0/000/000/0000000012.fid" ]
77 assert_equal expect, @mg._get_paths(:domain => 'test', :key => 'fookey')
80 def test_get_paths_bad_host
81 @my.expect << [ [ 12 ] ] # fid
82 @my.expect << [ [ 1 ], [ 5 ] ] # devids
83 expect = [ "http://10.0.0.1:7600/dev1/0/000/000/0000000012.fid" ]
84 assert_equal expect, @mg._get_paths(:domain => 'test', :key => 'fookey')
87 def test_get_paths_alt
88 @my.expect << [ [ 12 ] ] # fid
89 @my.expect << [ [ 1 ], [ 3 ] ] # devids
90 expect = [ "http://192.168.0.1:7600/dev1/0/000/000/0000000012.fid",
91 "http://10.0.0.3:7500/dev3/0/000/000/0000000012.fid"]
92 params = { :domain => 'test', :key => 'fookey', :zone => 'alt' }
93 assert_equal expect, @mg._get_paths(params)
97 expect_full = [ [ 'foo', 123, 2 ], [ 'bar', 456, 1 ] ]
98 result_full = eval(expect_full.inspect)
99 result_full.each { |x| (1..2).each { |i| x[i] = x[i].to_s } }
100 expect_keys = [ [ 'foo', 'bar' ], 'bar' ]
101 @my.expect << result_full
103 keys = @mg._list_keys('test') do |dkey,length,devcount|
104 full << [ dkey, length, devcount ]
106 assert_equal expect_keys, keys
107 assert_equal expect_full, full
110 def test_list_keys_empty
112 assert_nil @mg._list_keys('test')
116 @my.expect << [ [ '123' ] ]
117 assert_equal 123, @mg._size('test', 'foo')
119 @my.expect << [ [ '456' ] ]
120 assert_equal 456, @mg._size('test', 'foo')
124 assert_nothing_raised { assert_equal({}, @mg.sleep(:duration => 1)) }