mogilefs-client 1.0.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +11 -0
- data/{LICENSE → LICENSE.txt} +1 -6
- data/Manifest.txt +3 -2
- data/README.txt +66 -0
- data/Rakefile +13 -51
- data/lib/mogilefs.rb +2 -0
- data/lib/mogilefs/admin.rb +29 -5
- data/lib/mogilefs/backend.rb +4 -1
- data/lib/mogilefs/client.rb +2 -1
- data/lib/mogilefs/mogilefs.rb +22 -3
- data/test/setup.rb +8 -9
- data/test/test_admin.rb +138 -1
- data/test/test_backend.rb +17 -5
- data/test/test_client.rb +7 -3
- data/test/test_mogilefs.rb +38 -1
- metadata +41 -18
- data/README +0 -9
data/History.txt
ADDED
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
All original code copyright 2005 Eric Hodel, The Robot Co-op. All rights
|
4
|
-
reserved.
|
1
|
+
Copyright 2005 Eric Hodel, The Robot Co-op. All rights reserved.
|
5
2
|
|
6
3
|
Redistribution and use in source and binary forms, with or without
|
7
4
|
modification, are permitted provided that the following conditions
|
@@ -15,8 +12,6 @@ are met:
|
|
15
12
|
3. Neither the names of the authors nor the names of their contributors
|
16
13
|
may be used to endorse or promote products derived from this software
|
17
14
|
without specific prior written permission.
|
18
|
-
4. Redistribution in Rails or any sub-projects of Rails is not allowed
|
19
|
-
until Rails runs without warnings with the ``-W2'' flag enabled.
|
20
15
|
|
21
16
|
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
22
17
|
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
data/Manifest.txt
CHANGED
data/README.txt
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= mogilefs-client
|
2
|
+
|
3
|
+
A Ruby MogileFS client
|
4
|
+
|
5
|
+
Rubyforge Project:
|
6
|
+
|
7
|
+
http://rubyforge.org/projects/seattlerb/
|
8
|
+
|
9
|
+
Documentation:
|
10
|
+
|
11
|
+
http://seattlerb.org/mogilefs-client
|
12
|
+
|
13
|
+
File bugs:
|
14
|
+
|
15
|
+
http://rubyforge.org/tracker/?func=add&group_id=1513&atid=5921
|
16
|
+
|
17
|
+
== About
|
18
|
+
|
19
|
+
A Ruby MogileFS client. MogileFS is a distributed filesystem written
|
20
|
+
by Danga Interactive. This client supports NFS and HTTP modes.
|
21
|
+
|
22
|
+
For information on MogileFS see:
|
23
|
+
|
24
|
+
http://danga.com/mogilefs/
|
25
|
+
|
26
|
+
== Installing mogilefs-client
|
27
|
+
|
28
|
+
First you need a MogileFS setup. You can find information on how to do that at the above URL.
|
29
|
+
|
30
|
+
Then install the gem:
|
31
|
+
|
32
|
+
$ sudo gem install mogilefs-client
|
33
|
+
|
34
|
+
== Using mogilefs-client
|
35
|
+
|
36
|
+
# Create a new instance that will communicate with these trackers:
|
37
|
+
hosts = %w[192.168.1.69:6001 192.168.1.70:6001]
|
38
|
+
mg = MogileFS::MogileFS.new(:domain => 'test', :hosts => hosts
|
39
|
+
:root => '/mnt/mogilefs')
|
40
|
+
|
41
|
+
# Stores "A bunch of text to store" into 'some_key' with a class of 'text'.
|
42
|
+
mg.store_content 'some_key', 'text', "A bunch of text to store"
|
43
|
+
|
44
|
+
# Retrieve data from 'some_key'
|
45
|
+
data = mg.get_file_data 'some_key'
|
46
|
+
|
47
|
+
# Store the contents of 'image.jpeg' into the key 'my_image' with a class of
|
48
|
+
# 'image'.
|
49
|
+
mg.store_file 'my_image', 'image', 'image.jpeg'
|
50
|
+
|
51
|
+
# Store the contents of 'image.jpeg' into the key 'my_image' with a class of
|
52
|
+
# 'image' using an open IO.
|
53
|
+
File.open 'image.jpeg' do |fp|
|
54
|
+
mg.store_file 'my_image', 'image', fp
|
55
|
+
end
|
56
|
+
|
57
|
+
# Remove the key 'my_image' and 'some_key'.
|
58
|
+
mg.delete 'my_image'
|
59
|
+
mg.delete 'some_key'
|
60
|
+
|
61
|
+
== WARNING!
|
62
|
+
|
63
|
+
This client is only known to work in NFS mode. HTTP mode is implemented but
|
64
|
+
only lightly tested in production environments. If you find a bug,
|
65
|
+
please report it on the Rubyforge project.
|
66
|
+
|
data/Rakefile
CHANGED
@@ -1,56 +1,18 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
require '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.email = 'eric@robotcoop.com'
|
16
|
-
|
17
|
-
s.has_rdoc = true
|
18
|
-
s.files = File.read('Manifest.txt').split($/)
|
19
|
-
s.require_path = 'lib'
|
20
|
-
end
|
21
|
-
|
22
|
-
desc 'Run tests'
|
23
|
-
task :default => [ :test ]
|
24
|
-
|
25
|
-
Rake::TestTask.new('test') do |t|
|
26
|
-
t.libs << 'test'
|
27
|
-
t.pattern = 'test/test_*.rb'
|
28
|
-
t.verbose = true
|
29
|
-
end
|
30
|
-
|
31
|
-
desc 'Update Manifest.txt'
|
32
|
-
task :update_manifest do
|
33
|
-
sh "find . -type f | sed -e 's%./%%' | egrep -v 'svn|swp|~' | egrep -v '^(doc|pkg)/' | sort > Manifest.txt"
|
34
|
-
end
|
35
|
-
|
36
|
-
desc 'Generate RDoc'
|
37
|
-
Rake::RDocTask.new :rdoc do |rd|
|
38
|
-
rd.rdoc_dir = 'doc'
|
39
|
-
rd.rdoc_files.add 'lib', 'README', 'LICENSE'
|
40
|
-
rd.main = 'README'
|
41
|
-
rd.options << '-d' if `which dot` =~ /\/dot/
|
2
|
+
require 'hoe'
|
3
|
+
|
4
|
+
$:.unshift 'lib'
|
5
|
+
require 'mogilefs'
|
6
|
+
|
7
|
+
Hoe.new 'mogilefs-client', MogileFS::VERSION do |p|
|
8
|
+
p.rubyforge_name = 'seattlerb'
|
9
|
+
p.author = 'Eric Hodel'
|
10
|
+
p.email = 'drbrain@segment7.net'
|
11
|
+
p.summary = p.paragraphs_of('README.txt', 1).first
|
12
|
+
p.description = p.paragraphs_of('README.txt', 9).first
|
13
|
+
p.url = p.paragraphs_of('README.txt', 5).first
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
42
15
|
end
|
43
16
|
|
44
|
-
desc 'Build Gem'
|
45
|
-
Rake::GemPackageTask.new spec do |pkg|
|
46
|
-
pkg.need_tar = true
|
47
|
-
end
|
48
|
-
|
49
|
-
desc 'Clean up'
|
50
|
-
task :clean => [ :clobber_rdoc, :clobber_package ]
|
51
|
-
|
52
|
-
desc 'Clean up'
|
53
|
-
task :clobber => [ :clean ]
|
54
|
-
|
55
17
|
# vim: syntax=Ruby
|
56
18
|
|
data/lib/mogilefs.rb
CHANGED
data/lib/mogilefs/admin.rb
CHANGED
@@ -5,6 +5,22 @@ require 'mogilefs/client'
|
|
5
5
|
|
6
6
|
class MogileFS::Admin < MogileFS::Client
|
7
7
|
|
8
|
+
##
|
9
|
+
# Enumerates fids using #list_fids.
|
10
|
+
|
11
|
+
def each_fid
|
12
|
+
low = 0
|
13
|
+
high = nil
|
14
|
+
|
15
|
+
max = get_stats('fids')['fids']['max']
|
16
|
+
|
17
|
+
0.step max, 100 do |high|
|
18
|
+
fids = list_fids low, high
|
19
|
+
fids.each { |fid| yield fid }
|
20
|
+
low = high + 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
8
24
|
##
|
9
25
|
# Returns an Array of host status Hashes. If +hostid+ is given only that
|
10
26
|
# host is returned.
|
@@ -95,14 +111,21 @@ class MogileFS::Admin < MogileFS::Client
|
|
95
111
|
res = @backend.stats type => 1
|
96
112
|
stats = {}
|
97
113
|
|
98
|
-
stats['replication'] = clean 'replicationcount', 'replication', res, false
|
99
|
-
stats['file'] = clean 'filescount', 'files', res, false
|
100
114
|
stats['device'] = clean 'devicescount', 'devices', res, false
|
115
|
+
stats['file'] = clean 'filescount', 'files', res, false
|
116
|
+
stats['replication'] = clean 'replicationcount', 'replication', res, false
|
101
117
|
|
102
118
|
if res['fidmax'] or res['fidcount'] then
|
103
|
-
stats['fids'] = {
|
119
|
+
stats['fids'] = {
|
120
|
+
'max' => res['fidmax'].to_i,
|
121
|
+
'count' => res['fidcount'].to_i
|
122
|
+
}
|
104
123
|
end
|
105
124
|
|
125
|
+
stats.delete 'device' if stats['device'].empty?
|
126
|
+
stats.delete 'file' if stats['file'].empty?
|
127
|
+
stats.delete 'replication' if stats['replication'].empty?
|
128
|
+
|
106
129
|
return stats
|
107
130
|
end
|
108
131
|
|
@@ -113,7 +136,7 @@ class MogileFS::Admin < MogileFS::Client
|
|
113
136
|
#
|
114
137
|
# Returns:
|
115
138
|
#
|
116
|
-
# {"test"=>{"normal"=>
|
139
|
+
# {"test"=>{"normal"=>3, "default"=>2}}
|
117
140
|
|
118
141
|
def get_domains
|
119
142
|
res = @backend.get_domains
|
@@ -121,7 +144,8 @@ class MogileFS::Admin < MogileFS::Client
|
|
121
144
|
domains = {}
|
122
145
|
(1..res['domains'].to_i).each do |i|
|
123
146
|
domain = clean "domain#{i}classes", "domain#{i}class", res, false
|
124
|
-
|
147
|
+
domain = domain.map { |d| [d.values.first, d.values.last.to_i] }
|
148
|
+
domains[res["domain#{i}"]] = Hash[*domain.flatten]
|
125
149
|
end
|
126
150
|
|
127
151
|
return domains
|
data/lib/mogilefs/backend.rb
CHANGED
@@ -153,7 +153,10 @@ class MogileFS::Backend
|
|
153
153
|
|
154
154
|
def readable?
|
155
155
|
found = select [socket], nil, nil, @timeout
|
156
|
-
|
156
|
+
if found.nil? or found.empty? then
|
157
|
+
peer = (@socket ? "#{@socket.peeraddr[3]}:#{@socket.peeraddr[1]} " : nil)
|
158
|
+
raise MogileFS::UnreadableSocketError, "#{peer}never became readable"
|
159
|
+
end
|
157
160
|
return true
|
158
161
|
end
|
159
162
|
|
data/lib/mogilefs/client.rb
CHANGED
@@ -24,6 +24,7 @@ class MogileFS::Client
|
|
24
24
|
def initialize(args)
|
25
25
|
@hosts = args[:hosts]
|
26
26
|
@readonly = args[:readonly] ? true : false
|
27
|
+
@timeout = args[:timeout]
|
27
28
|
|
28
29
|
reload
|
29
30
|
end
|
@@ -32,7 +33,7 @@ class MogileFS::Client
|
|
32
33
|
# Creates a new MogileFS::Backend.
|
33
34
|
|
34
35
|
def reload
|
35
|
-
@backend = MogileFS::Backend.new :hosts => @hosts
|
36
|
+
@backend = MogileFS::Backend.new :hosts => @hosts, :timeout => @timeout
|
36
37
|
end
|
37
38
|
|
38
39
|
##
|
data/lib/mogilefs/mogilefs.rb
CHANGED
@@ -38,19 +38,38 @@ class MogileFS::MogileFS < MogileFS::Client
|
|
38
38
|
super
|
39
39
|
end
|
40
40
|
|
41
|
+
##
|
42
|
+
# Enumerates keys starting with +key+.
|
43
|
+
|
44
|
+
def each_key(prefix)
|
45
|
+
after = nil
|
46
|
+
|
47
|
+
keys, after = list_keys prefix
|
48
|
+
|
49
|
+
until keys.empty? do
|
50
|
+
keys.each { |k| yield k }
|
51
|
+
keys, after = list_keys prefix, after
|
52
|
+
end
|
53
|
+
|
54
|
+
return nil
|
55
|
+
end
|
56
|
+
|
41
57
|
##
|
42
58
|
# Retrieves the contents of +key+.
|
43
59
|
|
44
60
|
def get_file_data(key)
|
45
|
-
get_paths
|
61
|
+
paths = get_paths key
|
62
|
+
|
63
|
+
return nil unless paths
|
64
|
+
|
65
|
+
paths.each do |path|
|
46
66
|
next unless path
|
47
67
|
case path
|
48
68
|
when /^http:\/\// then
|
49
69
|
begin
|
50
|
-
puts "path: #{path}"
|
51
70
|
path = URI.parse path
|
52
71
|
data = timeout(5, MogileFS::Timeout) { path.read }
|
53
|
-
|
72
|
+
return data
|
54
73
|
rescue MogileFS::Timeout
|
55
74
|
next
|
56
75
|
end
|
data/test/setup.rb
CHANGED
@@ -9,25 +9,24 @@ class FakeBackend
|
|
9
9
|
attr_reader :lasterr, :lasterrstr
|
10
10
|
|
11
11
|
def initialize
|
12
|
-
@responses = {}
|
12
|
+
@responses = Hash.new { |h,k| h[k] = [] }
|
13
13
|
@lasterr = nil
|
14
14
|
@lasterrstr = nil
|
15
15
|
end
|
16
16
|
|
17
|
-
def method_missing(
|
18
|
-
|
19
|
-
if
|
20
|
-
@responses[$1]
|
17
|
+
def method_missing(meth, *args)
|
18
|
+
meth = meth.to_s
|
19
|
+
if meth =~ /(.*)=$/ then
|
20
|
+
@responses[$1] << args.first
|
21
21
|
else
|
22
|
-
response = @responses[
|
22
|
+
response = @responses[meth].shift
|
23
23
|
case response
|
24
|
-
when Hash then
|
25
|
-
return response
|
26
24
|
when Array then
|
27
25
|
@lasterr = response.first
|
28
26
|
@lasterrstr = response.last
|
29
27
|
return nil
|
30
28
|
end
|
29
|
+
return response
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
@@ -42,7 +41,7 @@ class TestMogileFS < Test::Unit::TestCase
|
|
42
41
|
def setup
|
43
42
|
return if self.class == TestMogileFS
|
44
43
|
@root = '/mogilefs/test'
|
45
|
-
@client = @
|
44
|
+
@client = @klass.new :hosts => ['kaa:6001'], :domain => 'test',
|
46
45
|
:root => @root
|
47
46
|
@backend = FakeBackend.new
|
48
47
|
@client.instance_variable_set '@backend', @backend
|
data/test/test_admin.rb
CHANGED
@@ -3,7 +3,7 @@ require 'test/setup'
|
|
3
3
|
class TestMogileFS__Admin < TestMogileFS
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@
|
6
|
+
@klass = MogileFS::Admin
|
7
7
|
super
|
8
8
|
end
|
9
9
|
|
@@ -33,5 +33,142 @@ class TestMogileFS__Admin < TestMogileFS
|
|
33
33
|
assert_equal expected, actual
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_each_fid
|
37
|
+
@backend.stats = {
|
38
|
+
'fidmax' => '182',
|
39
|
+
'fidcount' => '2',
|
40
|
+
}
|
41
|
+
|
42
|
+
@backend.list_fids = {
|
43
|
+
'fid_count' => '1',
|
44
|
+
'fid_1_fid' => '99',
|
45
|
+
'fid_1_class' => 'normal',
|
46
|
+
'fid_1_devcount' => '2',
|
47
|
+
'fid_1_domain' => 'test',
|
48
|
+
'fid_1_key' => 'file_key',
|
49
|
+
'fid_1_length' => '4',
|
50
|
+
}
|
51
|
+
|
52
|
+
@backend.list_fids = {
|
53
|
+
'fid_count' => '1',
|
54
|
+
'fid_1_fid' => '182',
|
55
|
+
'fid_1_class' => 'normal',
|
56
|
+
'fid_1_devcount' => '2',
|
57
|
+
'fid_1_domain' => 'test',
|
58
|
+
'fid_1_key' => 'new_new_key',
|
59
|
+
'fid_1_length' => '9',
|
60
|
+
}
|
61
|
+
|
62
|
+
fids = []
|
63
|
+
@client.each_fid { |fid| fids << fid }
|
64
|
+
|
65
|
+
expected = [
|
66
|
+
{ "fid" => "99",
|
67
|
+
"class" => "normal",
|
68
|
+
"domain" => "test",
|
69
|
+
"devcount" => "2",
|
70
|
+
"length" => "4",
|
71
|
+
"key" => "file_key" },
|
72
|
+
{ "fid" => "182",
|
73
|
+
"class" => "normal",
|
74
|
+
"devcount" => "2",
|
75
|
+
"domain" => "test",
|
76
|
+
"length" => "9",
|
77
|
+
"key" => "new_new_key" },
|
78
|
+
]
|
79
|
+
|
80
|
+
assert_equal expected, fids
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_get_domains
|
84
|
+
@backend.get_domains = {
|
85
|
+
'domains' => 2,
|
86
|
+
'domain1' => 'test',
|
87
|
+
'domain2' => 'images',
|
88
|
+
'domain1classes' => '1',
|
89
|
+
'domain2classes' => '2',
|
90
|
+
'domain1class1name' => 'default',
|
91
|
+
'domain1class1mindevcount' => '2',
|
92
|
+
'domain2class1name' => 'default',
|
93
|
+
'domain2class1mindevcount' => '2',
|
94
|
+
'domain2class2name' => 'resize',
|
95
|
+
'domain2class2mindevcount' => '1',
|
96
|
+
}
|
97
|
+
|
98
|
+
expected = {
|
99
|
+
'test' => { 'default' => 2, },
|
100
|
+
'images' => { 'default' => 2, 'resize' => 1 },
|
101
|
+
}
|
102
|
+
|
103
|
+
assert_equal expected, @client.get_domains
|
104
|
+
end
|
105
|
+
|
106
|
+
def disabled_test_get_stats
|
107
|
+
@backend.stats = {}
|
108
|
+
|
109
|
+
expected = {
|
110
|
+
'fids' => { 'max' => '99', 'count' => '2' },
|
111
|
+
'device' => [
|
112
|
+
{ 'status' => 'alive', 'files' => '2', 'id' => '1', 'host' => 'rur-1' },
|
113
|
+
{ 'status' => 'alive', 'files' => '2', 'id' => '2', 'host' => 'rur-2' }
|
114
|
+
],
|
115
|
+
'replication' => [
|
116
|
+
{ 'files' => '2', 'class' => 'normal', 'devcount' => '2',
|
117
|
+
'domain' => 'test' }
|
118
|
+
],
|
119
|
+
'file' => [{ 'files' => '2', 'class' => 'normal', 'domain' => 'test' }]
|
120
|
+
}
|
121
|
+
|
122
|
+
assert_equal
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_get_stats_fids
|
126
|
+
@backend.stats = {
|
127
|
+
'fidmax' => 99,
|
128
|
+
'fidcount' => 2,
|
129
|
+
}
|
130
|
+
|
131
|
+
expected = {
|
132
|
+
'fids' => { 'max' => 99, 'count' => 2 },
|
133
|
+
}
|
134
|
+
|
135
|
+
assert_equal expected, @client.get_stats('all')
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_list_fids
|
139
|
+
@backend.list_fids = {
|
140
|
+
'fid_count' => '2',
|
141
|
+
'fid_1_fid' => '99',
|
142
|
+
'fid_1_class' => 'normal',
|
143
|
+
'fid_1_devcount' => '2',
|
144
|
+
'fid_1_domain' => 'test',
|
145
|
+
'fid_1_key' => 'file_key',
|
146
|
+
'fid_1_length' => '4',
|
147
|
+
'fid_2_fid' => '82',
|
148
|
+
'fid_2_class' => 'normal',
|
149
|
+
'fid_2_devcount' => '2',
|
150
|
+
'fid_2_domain' => 'test',
|
151
|
+
'fid_2_key' => 'new_new_key',
|
152
|
+
'fid_2_length' => '9',
|
153
|
+
}
|
154
|
+
|
155
|
+
expected = [
|
156
|
+
{ "fid" => "99",
|
157
|
+
"class" => "normal",
|
158
|
+
"domain" => "test",
|
159
|
+
"devcount" => "2",
|
160
|
+
"length" => "4",
|
161
|
+
"key" => "file_key" },
|
162
|
+
{ "fid" => "82",
|
163
|
+
"class" => "normal",
|
164
|
+
"devcount" => "2",
|
165
|
+
"domain" => "test",
|
166
|
+
"length" => "9",
|
167
|
+
"key" => "new_new_key" },
|
168
|
+
]
|
169
|
+
|
170
|
+
assert_equal expected, @client.list_fids(0, 100)
|
171
|
+
end
|
172
|
+
|
36
173
|
end
|
37
174
|
|
data/test/test_backend.rb
CHANGED
@@ -27,12 +27,16 @@ class FakeSocket
|
|
27
27
|
return nil
|
28
28
|
end
|
29
29
|
|
30
|
+
def peeraddr
|
31
|
+
['AF_INET', 6001, 'localhost', '127.0.0.1']
|
32
|
+
end
|
33
|
+
|
30
34
|
end
|
31
35
|
|
32
36
|
class TestBackend < Test::Unit::TestCase
|
33
37
|
|
34
38
|
def setup
|
35
|
-
@backend = MogileFS::Backend.new :hosts => ['localhost:
|
39
|
+
@backend = MogileFS::Backend.new :hosts => ['localhost:1']
|
36
40
|
end
|
37
41
|
|
38
42
|
def test_initialize
|
@@ -40,7 +44,7 @@ class TestBackend < Test::Unit::TestCase
|
|
40
44
|
assert_raises ArgumentError do MogileFS::Backend.new :hosts => [] end
|
41
45
|
assert_raises ArgumentError do MogileFS::Backend.new :hosts => [''] end
|
42
46
|
|
43
|
-
assert_equal ['localhost:
|
47
|
+
assert_equal ['localhost:1'], @backend.hosts
|
44
48
|
assert_equal 3, @backend.timeout
|
45
49
|
assert_equal nil, @backend.lasterr
|
46
50
|
assert_equal nil, @backend.lasterrstr
|
@@ -119,18 +123,26 @@ class TestBackend < Test::Unit::TestCase
|
|
119
123
|
end
|
120
124
|
|
121
125
|
def test_readable_eh_not_readable
|
122
|
-
socket =
|
126
|
+
socket = FakeSocket.new
|
123
127
|
def socket.closed?() false end
|
124
128
|
def @backend.select(*args) return [] end
|
125
129
|
@backend.instance_variable_set '@socket', socket
|
126
130
|
|
127
|
-
|
131
|
+
begin
|
132
|
+
@backend.readable?
|
133
|
+
rescue MogileFS::UnreadableSocketError => e
|
134
|
+
assert_equal '127.0.0.1:6001 never became readable', e.message
|
135
|
+
rescue Exception
|
136
|
+
flunk "MogileFS::UnreadableSocketError not raised"
|
137
|
+
else
|
138
|
+
flunk "MogileFS::UnreadableSocketError not raised"
|
139
|
+
end
|
128
140
|
end
|
129
141
|
|
130
142
|
def test_socket
|
131
143
|
assert_equal({}, @backend.dead)
|
132
144
|
assert_raises RuntimeError do @backend.socket end
|
133
|
-
assert_equal(['localhost:
|
145
|
+
assert_equal(['localhost:1'], @backend.dead.keys)
|
134
146
|
end
|
135
147
|
|
136
148
|
def test_socket_robust
|
data/test/test_client.rb
CHANGED
@@ -11,9 +11,13 @@ class TestClient < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_initialize
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
client = MogileFS::Client.new :hosts => ['kaa:6001']
|
15
|
+
assert_not_nil client
|
16
|
+
assert_instance_of MogileFS::Backend, client.backend
|
17
|
+
assert_equal ['kaa:6001'], client.hosts
|
18
|
+
|
19
|
+
client = MogileFS::Client.new :hosts => ['kaa:6001'], :timeout => 5
|
20
|
+
assert_equal 5, client.backend.timeout
|
17
21
|
end
|
18
22
|
|
19
23
|
def test_err
|
data/test/test_mogilefs.rb
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
require 'test/setup'
|
2
2
|
|
3
|
+
class URI::HTTP
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :read_data
|
7
|
+
end
|
8
|
+
|
9
|
+
def read
|
10
|
+
self.class.read_data.shift
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
3
15
|
class TestMogileFS__MogileFS < TestMogileFS
|
4
16
|
|
5
17
|
def setup
|
6
|
-
@
|
18
|
+
@klass = MogileFS::MogileFS
|
7
19
|
super
|
8
20
|
end
|
9
21
|
|
@@ -16,6 +28,17 @@ class TestMogileFS__MogileFS < TestMogileFS
|
|
16
28
|
end
|
17
29
|
end
|
18
30
|
|
31
|
+
def test_get_file_data_http
|
32
|
+
URI::HTTP.read_data = %w[data!]
|
33
|
+
|
34
|
+
path1 = 'http://rur-1/dev1/0/000/000/0000000062.fid'
|
35
|
+
path2 = 'http://rur-2/dev2/0/000/000/0000000062.fid'
|
36
|
+
|
37
|
+
@backend.get_paths = { 'paths' => 2, 'path1' => path1, 'path2' => path2 }
|
38
|
+
|
39
|
+
assert_equal 'data!', @client.get_file_data('key')
|
40
|
+
end
|
41
|
+
|
19
42
|
def test_get_paths
|
20
43
|
path1 = 'rur-1/dev1/0/000/000/0000000062.fid'
|
21
44
|
path2 = 'rur-2/dev2/0/000/000/0000000062.fid'
|
@@ -54,6 +77,20 @@ class TestMogileFS__MogileFS < TestMogileFS
|
|
54
77
|
end
|
55
78
|
end
|
56
79
|
|
80
|
+
def test_each_key
|
81
|
+
@backend.list_keys = { 'key_count' => 2, 'next_after' => 'new_key_2',
|
82
|
+
'key_1' => 'new_key_1', 'key_2' => 'new_key_2' }
|
83
|
+
@backend.list_keys = { 'key_count' => 2, 'next_after' => 'new_key_4',
|
84
|
+
'key_1' => 'new_key_3', 'key_2' => 'new_key_4' }
|
85
|
+
@backend.list_keys = { 'key_count' => 0, 'next_after' => 'new_key_4' }
|
86
|
+
keys = []
|
87
|
+
@client.each_key 'new' do |key|
|
88
|
+
keys << key
|
89
|
+
end
|
90
|
+
|
91
|
+
assert_equal %w[new_key_1 new_key_2 new_key_3 new_key_4], keys
|
92
|
+
end
|
93
|
+
|
57
94
|
def test_list_keys
|
58
95
|
@backend.list_keys = { 'key_count' => 2, 'next_after' => 'new_key_2',
|
59
96
|
'key_1' => 'new_key_1', 'key_2' => 'new_key_2' }
|
metadata
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.4.3
|
3
3
|
specification_version: 1
|
4
4
|
name: mogilefs-client
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date:
|
6
|
+
version: 1.2.1
|
7
|
+
date: 2007-07-31 00:00:00 -07:00
|
8
8
|
summary: A Ruby MogileFS client
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email:
|
12
|
-
homepage:
|
13
|
-
rubyforge_project:
|
14
|
-
description: A Ruby MogileFS client. MogileFS is a distributed filesystem written by Danga Interactive. This client supports NFS
|
11
|
+
email: drbrain@segment7.net
|
12
|
+
homepage: http://seattlerb.org/mogilefs-client
|
13
|
+
rubyforge_project: seattlerb
|
14
|
+
description: A Ruby MogileFS client. MogileFS is a distributed filesystem written by Danga Interactive. This client supports NFS and HTTP modes.
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::
|
19
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
20
26
|
requirements:
|
21
27
|
- - ">"
|
22
28
|
- !ruby/object:Gem::Version
|
@@ -29,9 +35,10 @@ post_install_message:
|
|
29
35
|
authors:
|
30
36
|
- Eric Hodel
|
31
37
|
files:
|
32
|
-
-
|
38
|
+
- History.txt
|
39
|
+
- LICENSE.txt
|
33
40
|
- Manifest.txt
|
34
|
-
- README
|
41
|
+
- README.txt
|
35
42
|
- Rakefile
|
36
43
|
- lib/mogilefs.rb
|
37
44
|
- lib/mogilefs/admin.rb
|
@@ -47,17 +54,33 @@ files:
|
|
47
54
|
- test/test_client.rb
|
48
55
|
- test/test_mogilefs.rb
|
49
56
|
- test/test_pool.rb
|
50
|
-
test_files:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
test_files:
|
58
|
+
- test/test_admin.rb
|
59
|
+
- test/test_backend.rb
|
60
|
+
- test/test_client.rb
|
61
|
+
- test/test_mogilefs.rb
|
62
|
+
- test/test_pool.rb
|
63
|
+
rdoc_options:
|
64
|
+
- --main
|
65
|
+
- README.txt
|
66
|
+
extra_rdoc_files:
|
67
|
+
- History.txt
|
68
|
+
- LICENSE.txt
|
69
|
+
- Manifest.txt
|
70
|
+
- README.txt
|
56
71
|
executables: []
|
57
72
|
|
58
73
|
extensions: []
|
59
74
|
|
60
75
|
requirements: []
|
61
76
|
|
62
|
-
dependencies:
|
63
|
-
|
77
|
+
dependencies:
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: hoe
|
80
|
+
version_requirement:
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.2.2
|
86
|
+
version:
|
data/README
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
This is a client for Danga's MogileFS file store. For information on MogileFS
|
2
|
-
see:
|
3
|
-
|
4
|
-
http://danga.com/mogilefs/
|
5
|
-
|
6
|
-
This client is only known to work in NFS mode. HTTP mode is implemented but completely untested. If you find a bug, please report it in an email to:
|
7
|
-
|
8
|
-
eric@robotcoop.com.
|
9
|
-
|