mogilefs-client.git  about / heads / tags
MogileFS client library for Ruby
blob ba247230d9882f0d032187f484ad968cd5487368 3704 bytes (raw)
$ git show pu:test/test_admin.rb	# shows this blob on the CLI

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
 
# -*- encoding: binary -*-
require './test/setup'

class TestMogileFS__Admin < TestMogileFS

  def setup
    @klass = MogileFS::Admin
    super
  end

  def test_clean
    res = {"host1_remoteroot"=>"/mnt/mogilefs/rur-1",
           "host1_hostname"=>"rur-1",
           "host1_hostid"=>"1",
           "host1_http_get_port"=>"",
           "host1_altip"=>"",
           "hosts"=>"1",
           "host1_hostip"=>"",
           "host1_http_port"=>"",
           "host1_status"=>"alive",
           "host1_altmask"=>""}
    actual = @client.clean 'hosts', 'host', res

    expected = [{"status"=>"alive",
                 "http_get_port"=>"",
                 "http_port"=>"",
                 "hostid"=>"1",
                 "hostip"=>"",
                 "hostname"=>"rur-1",
                 "remoteroot"=>"/mnt/mogilefs/rur-1",
                 "altip"=>"",
                 "altmask"=>""}]

    assert_equal expected, actual
  end

  def test_each_fid
    @backend.list_fids = {
      'fid_count' => '1',
      'fid_1_fid' => '99',
      'fid_1_class' => 'normal',
      'fid_1_devcount' => '2',
      'fid_1_domain' => 'test',
      'fid_1_key' => 'file_key',
      'fid_1_length' => '4',
    }

    @backend.list_fids = {
      'fid_count' => '1',
      'fid_1_fid' => '182',
      'fid_1_class' => 'normal',
      'fid_1_devcount' => '2',
      'fid_1_domain' => 'test',
      'fid_1_key' => 'new_new_key',
      'fid_1_length' => '9',
    }
    @backend.list_fids = { 'fid_count' => 0 }

    fids = []
    @client.each_fid { |fid| fids << fid }

    expected = [
      { "fid"      => 99,
        "class"    => "normal",
        "domain"   => "test",
        "devcount" => 2,
        "length"   => 4,
        "key"      => "file_key" },
      { "fid"      => 182,
        "class"    => "normal",
        "devcount" => 2,
        "domain"   => "test",
        "length"   => 9,
        "key"      => "new_new_key" },
    ]

    assert_equal expected, fids
  end

  def test_get_domains
    @backend.get_domains = {
      'domains' => 2,
      'domain1' => 'test',
      'domain2' => 'images',
      'domain1classes' => '1',
      'domain2classes' => '2',
      'domain1class1name' => 'default',
      'domain1class1mindevcount' => '2',
      'domain2class1name' => 'default',
      'domain2class1mindevcount' => '2',
      'domain2class2name' => 'resize',
      'domain2class2mindevcount' => '1',
    }

    expected = {
      'test'   => { 'default' => 2, },
      'images' => { 'default' => 2, 'resize' => 1 },
    }

    assert_equal expected, @client.get_domains
  end

  def test_get_stats_fids
    @backend.stats = {
      'fidmax' => 99,
      'fidcount' => 2,
    }

    expected = {
      'fids' => { 'max' => 99, 'count' => 2 },
    }

    assert_equal expected, @client.get_stats('all')
  end

  def test_list_fids
    @backend.list_fids = {
      'fid_count' => '2',
      'fid_1_fid' => '99',
      'fid_1_class' => 'normal',
      'fid_1_devcount' => '2',
      'fid_1_domain' => 'test',
      'fid_1_key' => 'file_key',
      'fid_1_length' => '4',
      'fid_2_fid' => '82',
      'fid_2_class' => 'normal',
      'fid_2_devcount' => '2',
      'fid_2_domain' => 'test',
      'fid_2_key' => 'new_new_key',
      'fid_2_length' => '9',
    }

    expected = [
      { "fid"      => 99,
        "class"    => "normal",
        "domain"   => "test",
        "devcount" => 2,
        "length"   => 4,
        "key"      => "file_key" },
      { "fid"      => 82,
        "class"    => "normal",
        "devcount" => 2,
        "domain"   => "test",
        "length"   => 9,
        "key"      => "new_new_key" },
    ]

    assert_equal expected, @client.list_fids(0, 100)
  end

end


git clone https://yhbt.net/mogilefs-client.git