pager-mogilefs-client 1.2.1.20080519
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.txt +27 -0
- data/Manifest.txt +19 -0
- data/README.txt +66 -0
- data/Rakefile +18 -0
- data/lib/mogilefs.rb +26 -0
- data/lib/mogilefs/admin.rb +298 -0
- data/lib/mogilefs/backend.rb +222 -0
- data/lib/mogilefs/client.rb +65 -0
- data/lib/mogilefs/httpfile.rb +118 -0
- data/lib/mogilefs/mogilefs.rb +237 -0
- data/lib/mogilefs/nfsfile.rb +81 -0
- data/lib/mogilefs/pool.rb +50 -0
- data/test/setup.rb +54 -0
- data/test/test_admin.rb +174 -0
- data/test/test_backend.rb +220 -0
- data/test/test_client.rb +53 -0
- data/test/test_mogilefs.rb +160 -0
- data/test/test_pool.rb +98 -0
- metadata +96 -0
data/test/test_client.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$TESTING = true
|
4
|
+
|
5
|
+
require 'mogilefs'
|
6
|
+
|
7
|
+
class TestClient < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@client = MogileFS::Client.new :hosts => ['kaa:6001']
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize
|
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
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_err
|
24
|
+
@client.backend.lasterr = 'you'
|
25
|
+
assert_equal 'you', @client.err
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_errstr
|
29
|
+
@client.backend.lasterrstr = 'totally suck'
|
30
|
+
assert_equal 'totally suck', @client.errstr
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_reload
|
34
|
+
orig_backend = @client.backend
|
35
|
+
|
36
|
+
@client.hosts = ['ziz:6001']
|
37
|
+
@client.reload
|
38
|
+
|
39
|
+
assert_not_same @client.backend, orig_backend
|
40
|
+
assert_equal ['ziz:6001'], @client.backend.hosts
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_readonly_eh_readonly
|
44
|
+
client = MogileFS::Client.new :hosts => ['kaa:6001'], :readonly => true
|
45
|
+
assert_equal true, client.readonly?
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_readonly_eh_readwrite
|
49
|
+
assert_equal false, @client.readonly?
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'test/setup'
|
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
|
+
|
15
|
+
class TestMogileFS__MogileFS < TestMogileFS
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@klass = MogileFS::MogileFS
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initialize
|
23
|
+
assert_equal 'test', @client.domain
|
24
|
+
assert_equal '/mogilefs/test', @client.root
|
25
|
+
|
26
|
+
assert_raises ArgumentError do
|
27
|
+
MogileFS::MogileFS.new :hosts => ['kaa:6001'], :root => '/mogilefs/test'
|
28
|
+
end
|
29
|
+
end
|
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
|
+
|
42
|
+
def test_get_paths
|
43
|
+
path1 = 'rur-1/dev1/0/000/000/0000000062.fid'
|
44
|
+
path2 = 'rur-2/dev2/0/000/000/0000000062.fid'
|
45
|
+
|
46
|
+
@backend.get_paths = { 'paths' => 2, 'path1' => path1, 'path2' => path2 }
|
47
|
+
|
48
|
+
expected = ["#{@root}/#{path1}", "#{@root}/#{path2}"]
|
49
|
+
|
50
|
+
assert_equal expected, @client.get_paths('key').sort
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_get_paths_unknown_key
|
54
|
+
@backend.get_paths = ['unknown_key', '']
|
55
|
+
|
56
|
+
assert_equal nil, @client.get_paths('key')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_delete_existing
|
60
|
+
@backend.delete = { }
|
61
|
+
assert_nothing_raised do
|
62
|
+
@client.delete 'no_such_key'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_delete_nonexisting
|
67
|
+
@backend.delete = 'unknown_key', ''
|
68
|
+
assert_nothing_raised do
|
69
|
+
assert_equal nil, @client.delete('no_such_key')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_delete_readonly
|
74
|
+
@client.readonly = true
|
75
|
+
assert_raises RuntimeError do
|
76
|
+
@client.delete 'no_such_key'
|
77
|
+
end
|
78
|
+
end
|
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
|
+
|
94
|
+
def test_list_keys
|
95
|
+
@backend.list_keys = { 'key_count' => 2, 'next_after' => 'new_key_2',
|
96
|
+
'key_1' => 'new_key_1', 'key_2' => 'new_key_2' }
|
97
|
+
|
98
|
+
keys, next_after = @client.list_keys 'new'
|
99
|
+
assert_equal ['new_key_1', 'new_key_2'], keys.sort
|
100
|
+
assert_equal 'new_key_2', next_after
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_new_file_http
|
104
|
+
@client.readonly = true
|
105
|
+
assert_raises RuntimeError do
|
106
|
+
@client.new_file 'new_key', 'test'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_new_file_readonly
|
111
|
+
@client.readonly = true
|
112
|
+
assert_raises RuntimeError do
|
113
|
+
@client.new_file 'new_key', 'test'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_store_content_readonly
|
118
|
+
@client.readonly = true
|
119
|
+
assert_raises RuntimeError do
|
120
|
+
@client.store_content 'new_key', 'test', nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_store_file_readonly
|
125
|
+
@client.readonly = true
|
126
|
+
assert_raises RuntimeError do
|
127
|
+
@client.store_file 'new_key', 'test', nil
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_rename_existing
|
132
|
+
@backend.rename = {}
|
133
|
+
assert_nothing_raised do
|
134
|
+
assert_equal(nil, @client.rename('from_key', 'to_key'))
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_rename_nonexisting
|
139
|
+
@backend.rename = 'unknown_key', ''
|
140
|
+
assert_nothing_raised do
|
141
|
+
assert_equal(nil, @client.rename('from_key', 'to_key'))
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_rename_readonly
|
146
|
+
@client.readonly = true
|
147
|
+
assert_raises RuntimeError do
|
148
|
+
@client.rename 'new_key', 'test'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_sleep
|
153
|
+
@backend.sleep = {}
|
154
|
+
assert_nothing_raised do
|
155
|
+
assert_equal({}, @client.sleep(2))
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
data/test/test_pool.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$TESTING = true
|
4
|
+
|
5
|
+
require 'mogilefs/pool'
|
6
|
+
|
7
|
+
class MogileFS::Pool
|
8
|
+
|
9
|
+
attr_reader :objects, :queue
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class Resource; end
|
14
|
+
|
15
|
+
class ResourceWithArgs
|
16
|
+
|
17
|
+
def initialize(args)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class TestPool < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@pool = MogileFS::Pool.new Resource
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_get
|
29
|
+
o1 = @pool.get
|
30
|
+
o2 = @pool.get
|
31
|
+
assert_kind_of Resource, o1
|
32
|
+
assert_kind_of Resource, o2
|
33
|
+
assert_not_equal o1, o2
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_with_args
|
37
|
+
@pool = MogileFS::Pool.new ResourceWithArgs, 'my arg'
|
38
|
+
o = @pool.get
|
39
|
+
assert_kind_of ResourceWithArgs, o
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_put
|
43
|
+
o = @pool.get
|
44
|
+
@pool.put o
|
45
|
+
|
46
|
+
assert_raises(MogileFS::Pool::BadObjectError) { @pool.put nil }
|
47
|
+
assert_raises(MogileFS::Pool::BadObjectError) { @pool.put Resource.new }
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_put_destroy
|
51
|
+
objs = (0...7).map { @pool.get } # pool full
|
52
|
+
|
53
|
+
assert_equal 7, @pool.objects.length
|
54
|
+
assert_equal 0, @pool.queue.length
|
55
|
+
|
56
|
+
4.times { @pool.put objs.shift }
|
57
|
+
|
58
|
+
assert_equal 7, @pool.objects.length
|
59
|
+
assert_equal 4, @pool.queue.length
|
60
|
+
|
61
|
+
@pool.put objs.shift # trip threshold
|
62
|
+
|
63
|
+
assert_equal 4, @pool.objects.length
|
64
|
+
assert_equal 2, @pool.queue.length
|
65
|
+
|
66
|
+
@pool.put objs.shift # don't need to remove any more
|
67
|
+
|
68
|
+
assert_equal 4, @pool.objects.length
|
69
|
+
assert_equal 3, @pool.queue.length
|
70
|
+
|
71
|
+
@pool.put objs.shift until objs.empty?
|
72
|
+
|
73
|
+
assert_equal 4, @pool.objects.length
|
74
|
+
assert_equal 4, @pool.queue.length
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_use
|
78
|
+
val = @pool.use { |o| assert_kind_of Resource, o }
|
79
|
+
assert_equal nil, val, "Don't return object from pool"
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_use_with_exception
|
83
|
+
@pool.use { |o| raise } rescue nil
|
84
|
+
assert_equal 1, @pool.queue.length, "Resource not returned to pool"
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_use_reuse
|
88
|
+
o1 = nil
|
89
|
+
o2 = nil
|
90
|
+
|
91
|
+
@pool.use { |o| o1 = o }
|
92
|
+
@pool.use { |o| o2 = o }
|
93
|
+
|
94
|
+
assert_equal o1, o2, "Objects must be reused"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pager-mogilefs-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.1.20080519
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Hodel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rfuzz
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0.9"
|
32
|
+
version:
|
33
|
+
description: A Ruby MogileFS client. MogileFS is a distributed filesystem written by Danga Interactive. This client supports NFS and HTTP modes. This is experimental fork using RFuzz HTTP client.
|
34
|
+
email: drbrain@segment7.net
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- History.txt
|
41
|
+
- LICENSE.txt
|
42
|
+
- Manifest.txt
|
43
|
+
- README.txt
|
44
|
+
files:
|
45
|
+
- History.txt
|
46
|
+
- LICENSE.txt
|
47
|
+
- Manifest.txt
|
48
|
+
- README.txt
|
49
|
+
- Rakefile
|
50
|
+
- lib/mogilefs.rb
|
51
|
+
- lib/mogilefs/admin.rb
|
52
|
+
- lib/mogilefs/backend.rb
|
53
|
+
- lib/mogilefs/client.rb
|
54
|
+
- lib/mogilefs/httpfile.rb
|
55
|
+
- lib/mogilefs/mogilefs.rb
|
56
|
+
- lib/mogilefs/nfsfile.rb
|
57
|
+
- lib/mogilefs/pool.rb
|
58
|
+
- test/setup.rb
|
59
|
+
- test/test_admin.rb
|
60
|
+
- test/test_backend.rb
|
61
|
+
- test/test_client.rb
|
62
|
+
- test/test_mogilefs.rb
|
63
|
+
- test/test_pool.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://seattlerb.org/mogilefs-client
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --main
|
69
|
+
- README.txt
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: seattlerb
|
87
|
+
rubygems_version: 1.0.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 2
|
90
|
+
summary: A Ruby MogileFS client
|
91
|
+
test_files:
|
92
|
+
- test/test_admin.rb
|
93
|
+
- test/test_backend.rb
|
94
|
+
- test/test_client.rb
|
95
|
+
- test/test_mogilefs.rb
|
96
|
+
- test/test_pool.rb
|