list_keys: more accurate devcount file_info-less servers
[ruby-mogilefs-client.git] / test / test_admin.rb
bloba7b0963da98d3d013d7122723d6bacd4cde188f4
1 # -*- encoding: binary -*-
2 require './test/setup'
4 class TestMogileFS__Admin < TestMogileFS
6   def setup
7     @klass = MogileFS::Admin
8     super
9   end
11   def test_clean
12     res = {"host1_remoteroot"=>"/mnt/mogilefs/rur-1",
13            "host1_hostname"=>"rur-1",
14            "host1_hostid"=>"1",
15            "host1_http_get_port"=>"",
16            "host1_altip"=>"",
17            "hosts"=>"1",
18            "host1_hostip"=>"",
19            "host1_http_port"=>"",
20            "host1_status"=>"alive",
21            "host1_altmask"=>""}
22     actual = @client.clean 'hosts', 'host', res
24     expected = [{"status"=>"alive",
25                  "http_get_port"=>"",
26                  "http_port"=>"",
27                  "hostid"=>"1",
28                  "hostip"=>"",
29                  "hostname"=>"rur-1",
30                  "remoteroot"=>"/mnt/mogilefs/rur-1",
31                  "altip"=>"",
32                  "altmask"=>""}]
34     assert_equal expected, actual
35   end
37   def test_each_fid
38     @backend.stats = {
39       'fidmax' => '182',
40       'fidcount' => '2',
41     }
43     @backend.list_fids = {
44       'fid_count' => '1',
45       'fid_1_fid' => '99',
46       'fid_1_class' => 'normal',
47       'fid_1_devcount' => '2',
48       'fid_1_domain' => 'test',
49       'fid_1_key' => 'file_key',
50       'fid_1_length' => '4',
51     }
53     @backend.list_fids = {
54       'fid_count' => '1',
55       'fid_1_fid' => '182',
56       'fid_1_class' => 'normal',
57       'fid_1_devcount' => '2',
58       'fid_1_domain' => 'test',
59       'fid_1_key' => 'new_new_key',
60       'fid_1_length' => '9',
61     }
63     fids = []
64     @client.each_fid { |fid| fids << fid }
66     expected = [
67       { "fid"      => "99",
68         "class"    => "normal",
69         "domain"   => "test",
70         "devcount" => "2",
71         "length"   => "4",
72         "key"      => "file_key" },
73       { "fid"      => "182",
74         "class"    => "normal",
75         "devcount" => "2",
76         "domain"   => "test",
77         "length"   => "9",
78         "key"      => "new_new_key" },
79     ]
81     assert_equal expected, fids
82   end
84   def test_get_domains
85     @backend.get_domains = {
86       'domains' => 2,
87       'domain1' => 'test',
88       'domain2' => 'images',
89       'domain1classes' => '1',
90       'domain2classes' => '2',
91       'domain1class1name' => 'default',
92       'domain1class1mindevcount' => '2',
93       'domain2class1name' => 'default',
94       'domain2class1mindevcount' => '2',
95       'domain2class2name' => 'resize',
96       'domain2class2mindevcount' => '1',
97     }
99     expected = {
100       'test'   => { 'default' => 2, },
101       'images' => { 'default' => 2, 'resize' => 1 },
102     }
104     assert_equal expected, @client.get_domains
105   end
107   def test_get_stats_fids
108     @backend.stats = {
109       'fidmax' => 99,
110       'fidcount' => 2,
111     }
113     expected = {
114       'fids' => { 'max' => 99, 'count' => 2 },
115     }
117     assert_equal expected, @client.get_stats('all')
118   end
120   def test_list_fids
121     @backend.list_fids = {
122       'fid_count' => '2',
123       'fid_1_fid' => '99',
124       'fid_1_class' => 'normal',
125       'fid_1_devcount' => '2',
126       'fid_1_domain' => 'test',
127       'fid_1_key' => 'file_key',
128       'fid_1_length' => '4',
129       'fid_2_fid' => '82',
130       'fid_2_class' => 'normal',
131       'fid_2_devcount' => '2',
132       'fid_2_domain' => 'test',
133       'fid_2_key' => 'new_new_key',
134       'fid_2_length' => '9',
135     }
137     expected = [
138       { "fid"      => "99",
139         "class"    => "normal",
140         "domain"   => "test",
141         "devcount" => "2",
142         "length"   => "4",
143         "key"      => "file_key" },
144       { "fid"      => "82",
145         "class"    => "normal",
146         "devcount" => "2",
147         "domain"   => "test",
148         "length"   => "9",
149         "key"      => "new_new_key" },
150     ]
152     assert_equal expected, @client.list_fids(0, 100)
153   end