2 require 'mogilefs/mysql'
9 class TestMogileFS__Mysql < Test::Unit::TestCase
13 @mg = MogileFS::Mysql.new(:mysql => @my)
17 def test_refresh_device
23 :altip=>"192.168.0.1"},
28 :altip=>"192.168.0.2"},
40 assert_equal expect, @mg.refresh_device
43 def test_refresh_domain
44 expect = { 'test' => 1, 'foo' => 2 }
45 assert_equal expect, @mg.refresh_domain
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')
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)
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
72 keys = @mg._list_keys('test') do |dkey,length,devcount|
73 full << [ dkey, length, devcount ]
75 assert_equal expect_keys, keys
76 assert_equal expect_full, full
79 def test_list_keys_empty
81 assert_nil @mg._list_keys('test')
85 @my.expect << [ [ '123' ] ]
86 assert_equal 123, @mg._size('test', 'foo')
88 @my.expect << [ [ '456' ] ]
89 assert_equal 456, @mg._size('test', 'foo')
93 assert_nothing_raised { assert_equal({}, @mg.sleep(:duration => 1)) }