higgs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +208 -0
- data/LICENSE +26 -0
- data/README +2 -0
- data/Rakefile +75 -0
- data/bin/higgs_backup +67 -0
- data/bin/higgs_dump_index +43 -0
- data/bin/higgs_dump_jlog +42 -0
- data/bin/higgs_verify +37 -0
- data/lib/cgi/session/higgs.rb +72 -0
- data/lib/higgs/block.rb +192 -0
- data/lib/higgs/cache.rb +117 -0
- data/lib/higgs/dbm.rb +55 -0
- data/lib/higgs/exceptions.rb +31 -0
- data/lib/higgs/flock.rb +77 -0
- data/lib/higgs/index.rb +164 -0
- data/lib/higgs/jlog.rb +159 -0
- data/lib/higgs/lock.rb +189 -0
- data/lib/higgs/storage.rb +1086 -0
- data/lib/higgs/store.rb +228 -0
- data/lib/higgs/tar.rb +390 -0
- data/lib/higgs/thread.rb +370 -0
- data/lib/higgs/tman.rb +513 -0
- data/lib/higgs/utils/bman.rb +285 -0
- data/lib/higgs/utils.rb +22 -0
- data/lib/higgs/version.rb +21 -0
- data/lib/higgs.rb +59 -0
- data/misc/cache_bench/cache_bench.rb +43 -0
- data/misc/dbm_bench/.strc +8 -0
- data/misc/dbm_bench/Rakefile +78 -0
- data/misc/dbm_bench/dbm_multi_thread.rb +199 -0
- data/misc/dbm_bench/dbm_rnd_delete.rb +43 -0
- data/misc/dbm_bench/dbm_rnd_read.rb +44 -0
- data/misc/dbm_bench/dbm_rnd_update.rb +44 -0
- data/misc/dbm_bench/dbm_seq_read.rb +45 -0
- data/misc/dbm_bench/dbm_seq_write.rb +44 -0
- data/misc/dbm_bench/st_verify.rb +28 -0
- data/misc/io_bench/cksum_bench.rb +48 -0
- data/misc/io_bench/jlog_bench.rb +71 -0
- data/misc/io_bench/write_bench.rb +128 -0
- data/misc/thread_bench/lock_bench.rb +132 -0
- data/mkrdoc.rb +8 -0
- data/rdoc.yml +13 -0
- data/sample/count.rb +60 -0
- data/sample/dbmtest.rb +38 -0
- data/test/Rakefile +45 -0
- data/test/run.rb +32 -0
- data/test/test_block.rb +163 -0
- data/test/test_cache.rb +214 -0
- data/test/test_cgi_session.rb +142 -0
- data/test/test_flock.rb +162 -0
- data/test/test_index.rb +258 -0
- data/test/test_jlog.rb +180 -0
- data/test/test_lock.rb +320 -0
- data/test/test_online_backup.rb +169 -0
- data/test/test_storage.rb +439 -0
- data/test/test_storage_conf.rb +202 -0
- data/test/test_storage_init_opts.rb +89 -0
- data/test/test_store.rb +211 -0
- data/test/test_tar.rb +432 -0
- data/test/test_thread.rb +541 -0
- data/test/test_tman.rb +875 -0
- data/test/test_tman_init_opts.rb +56 -0
- data/test/test_utils_bman.rb +234 -0
- metadata +115 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'higgs/storage'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
module Higgs::Test
|
7
|
+
class StorageInitOptionsTest < Test::Unit::TestCase
|
8
|
+
# for ident(1)
|
9
|
+
CVS_ID = '$Id: test_storage_init_opts.rb 559 2007-09-25 15:20:20Z toki $'
|
10
|
+
|
11
|
+
include Higgs::Storage::InitOptions
|
12
|
+
|
13
|
+
def test_default
|
14
|
+
init_options({})
|
15
|
+
assert_equal(false, @read_only)
|
16
|
+
assert_equal(false, self.read_only)
|
17
|
+
assert_equal(2, @number_of_read_io)
|
18
|
+
assert_equal(2, self.number_of_read_io)
|
19
|
+
assert_instance_of(Higgs::LRUCache, @properties_cache) # auto: require 'higgs/cache'
|
20
|
+
assert_equal(false, @jlog_sync)
|
21
|
+
assert_equal(false, self.jlog_sync)
|
22
|
+
assert_equal(1024 * 256, @jlog_rotate_size)
|
23
|
+
assert_equal(1024 * 256, self.jlog_rotate_size)
|
24
|
+
assert_equal(1, @jlog_rotate_max)
|
25
|
+
assert_equal(1, self.jlog_rotate_max)
|
26
|
+
assert_equal(nil, @jlog_rotate_service_uri)
|
27
|
+
assert_equal(nil, self.jlog_rotate_service_uri)
|
28
|
+
assert_instance_of(Proc, @Logger)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_read_only_true
|
32
|
+
init_options(:read_only => true)
|
33
|
+
assert_equal(true, @read_only)
|
34
|
+
assert_equal(true, self.read_only)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_read_only_false
|
38
|
+
init_options(:read_only => false)
|
39
|
+
assert_equal(false, @read_only)
|
40
|
+
assert_equal(false, self.read_only)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_number_of_read_io
|
44
|
+
init_options(:number_of_read_io => 16)
|
45
|
+
assert_equal(16, @number_of_read_io)
|
46
|
+
assert_equal(16, self.number_of_read_io)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_properties_cache
|
50
|
+
init_options(:properties_cache => :dummy_cache)
|
51
|
+
assert_equal(:dummy_cache, @properties_cache)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_jlog_sync_true
|
55
|
+
init_options(:jlog_sync => true)
|
56
|
+
assert_equal(true, @jlog_sync)
|
57
|
+
assert_equal(true, self.jlog_sync)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_jlog_sync_false
|
61
|
+
init_options(:jlog_sync => false)
|
62
|
+
assert_equal(false, @jlog_sync)
|
63
|
+
assert_equal(false, self.jlog_sync)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_jlog_rotate_size
|
67
|
+
init_options(:jlog_rotate_size => 1024**2)
|
68
|
+
assert_equal(1024**2, @jlog_rotate_size)
|
69
|
+
assert_equal(1024**2, self.jlog_rotate_size)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_jlog_rotate_max
|
73
|
+
init_options(:jlog_rotate_max => 100)
|
74
|
+
assert_equal(100, @jlog_rotate_max)
|
75
|
+
assert_equal(100, self.jlog_rotate_max)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_jlog_rotate_service_uri
|
79
|
+
init_options(:jlog_rotate_service_uri => 'druby://localhost:14142')
|
80
|
+
assert_equal('druby://localhost:14142', @jlog_rotate_service_uri)
|
81
|
+
assert_equal('druby://localhost:14142', self.jlog_rotate_service_uri)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_logger
|
85
|
+
init_options(:logger => proc{|path| :dummy_logger })
|
86
|
+
assert_equal(:dummy_logger, @Logger.call('foo'))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/test/test_store.rb
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'higgs/store'
|
5
|
+
require 'logger'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
module Higgs::Test
|
9
|
+
class StoreTest < Test::Unit::TestCase
|
10
|
+
include Higgs
|
11
|
+
|
12
|
+
# for ident(1)
|
13
|
+
CVS_ID = '$Id: test_store.rb 559 2007-09-25 15:20:20Z toki $'
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@test_dir = 'store_test'
|
17
|
+
FileUtils.rm_rf(@test_dir) # for debug
|
18
|
+
FileUtils.mkdir_p(@test_dir)
|
19
|
+
@name = File.join(@test_dir, 'foo')
|
20
|
+
@st = Store.new(@name,
|
21
|
+
:logger => proc{|path|
|
22
|
+
logger = Logger.new(path, 1)
|
23
|
+
logger.level = Logger::DEBUG
|
24
|
+
logger
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
@st.shutdown unless @st.shutdown?
|
30
|
+
FileUtils.rm_rf(@test_dir) unless $DEBUG
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_fetch_and_store
|
34
|
+
@st.transaction{|tx|
|
35
|
+
assert_equal(nil, tx[:foo])
|
36
|
+
assert_equal(nil, tx['bar'])
|
37
|
+
assert_equal(nil, tx[0])
|
38
|
+
|
39
|
+
assert_equal(false, (tx.key? :foo))
|
40
|
+
assert_equal(false, (tx.key? 'bar'))
|
41
|
+
assert_equal(false, (tx.key? 0))
|
42
|
+
|
43
|
+
tx[:foo] = :HALO
|
44
|
+
tx['bar'] = "Hello world.\n"
|
45
|
+
tx[0] = nil
|
46
|
+
|
47
|
+
assert_equal(:HALO, tx[:foo])
|
48
|
+
assert_equal("Hello world.\n", tx['bar'])
|
49
|
+
assert_equal(nil, tx[0])
|
50
|
+
|
51
|
+
assert_equal(true, (tx.key? :foo))
|
52
|
+
assert_equal(true, (tx.key? 'bar'))
|
53
|
+
assert_equal(true, (tx.key? 0))
|
54
|
+
}
|
55
|
+
|
56
|
+
@st.transaction{|tx|
|
57
|
+
assert_equal(:HALO, tx[:foo])
|
58
|
+
assert_equal("Hello world.\n", tx['bar'])
|
59
|
+
assert_equal(nil, tx[0])
|
60
|
+
|
61
|
+
assert_equal(true, (tx.key? :foo))
|
62
|
+
assert_equal(true, (tx.key? 'bar'))
|
63
|
+
assert_equal(true, (tx.key? 0))
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_update
|
68
|
+
@st.transaction{|tx|
|
69
|
+
tx[:foo] = []
|
70
|
+
}
|
71
|
+
|
72
|
+
@st.transaction{|tx|
|
73
|
+
tx.update(:foo) {|a|
|
74
|
+
a << 'apple'
|
75
|
+
a << 'banana'
|
76
|
+
a << 'orange'
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
@st.transaction{|tx|
|
81
|
+
assert_equal(%w[ apple banana orange ], tx[:foo])
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_update_with_default_value
|
86
|
+
@st.transaction{|tx|
|
87
|
+
assert(! (tx.key? :foo))
|
88
|
+
tx.update(:foo, []) {|a|
|
89
|
+
a << 'apple'
|
90
|
+
a << 'banana'
|
91
|
+
a << 'orange'
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
@st.transaction{|tx|
|
96
|
+
assert_equal(%w[ apple banana orange ], tx[:foo])
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_update_IndexError
|
101
|
+
@st.transaction{|tx|
|
102
|
+
assert_raise(IndexError) {
|
103
|
+
tx.update(:foo) {|value|
|
104
|
+
flunk('not to reach.')
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_string_only
|
111
|
+
@st.transaction{|tx|
|
112
|
+
assert_equal(nil, tx.property(:foo, :string_only))
|
113
|
+
tx[:foo] = 0
|
114
|
+
}
|
115
|
+
|
116
|
+
@st.transaction{|tx|
|
117
|
+
assert_equal(false, tx.property(:foo, :string_only))
|
118
|
+
assert_equal(0, tx[:foo])
|
119
|
+
tx.set_property(:foo, :string_only, true)
|
120
|
+
assert_equal(0, tx[:foo])
|
121
|
+
}
|
122
|
+
|
123
|
+
@st.transaction{|tx|
|
124
|
+
assert_equal(true, tx.property(:foo, :string_only))
|
125
|
+
assert_equal(Marshal.dump(0), tx[:foo])
|
126
|
+
tx[:foo] = "Hello world.\n"
|
127
|
+
}
|
128
|
+
|
129
|
+
@st.transaction{|tx|
|
130
|
+
assert_equal(true, tx.property(:foo, :string_only))
|
131
|
+
assert_equal("Hello world.\n", tx[:foo])
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_string_only_TypeError_cant_convert_into_String
|
136
|
+
@st.transaction{|tx|
|
137
|
+
tx[:foo] = 0
|
138
|
+
tx.set_property(:foo, :string_only, true)
|
139
|
+
assert_raise(TypeError) { tx.commit }
|
140
|
+
tx.rollback
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_rollback
|
145
|
+
@st.transaction{|tx|
|
146
|
+
tx[:foo] = %w[ apple banana orange ]
|
147
|
+
}
|
148
|
+
|
149
|
+
@st.transaction{|tx|
|
150
|
+
fruits = tx[:foo]
|
151
|
+
assert_equal(%w[ apple banana orange ], fruits)
|
152
|
+
assert_equal('orange', fruits.pop)
|
153
|
+
assert_equal(%w[ apple banana ], fruits)
|
154
|
+
tx[:foo] = fruits
|
155
|
+
tx.rollback
|
156
|
+
assert_equal(%w[ apple banana orange ], tx[:foo])
|
157
|
+
}
|
158
|
+
|
159
|
+
@st.transaction{|tx|
|
160
|
+
assert_equal(%w[ apple banana orange ], tx[:foo])
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_replica_problem
|
165
|
+
@st.transaction{|tx|
|
166
|
+
tx[:foo] = 'a'
|
167
|
+
tx[:bar] = tx[:foo]
|
168
|
+
|
169
|
+
assert_equal('a', tx[:foo])
|
170
|
+
assert_equal('a', tx[:bar])
|
171
|
+
assert_same(tx[:foo], tx[:bar])
|
172
|
+
|
173
|
+
tx[:foo].succ!
|
174
|
+
assert_equal('b', tx[:foo])
|
175
|
+
assert_equal('b', tx[:bar])
|
176
|
+
assert_same(tx[:foo], tx[:bar])
|
177
|
+
}
|
178
|
+
|
179
|
+
@st.transaction{|tx|
|
180
|
+
assert_equal('b', tx[:foo])
|
181
|
+
assert_equal('b', tx[:bar])
|
182
|
+
assert_not_same(tx[:foo], tx[:bar])
|
183
|
+
|
184
|
+
tx[:foo].succ!
|
185
|
+
assert_equal('c', tx[:foo])
|
186
|
+
assert_equal('b', tx[:bar])
|
187
|
+
assert_not_same(tx[:foo], tx[:bar])
|
188
|
+
}
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_each_key
|
192
|
+
@st.transaction{|tx|
|
193
|
+
tx[:foo] = 'apple'
|
194
|
+
tx[:bar] = ''
|
195
|
+
tx[:baz] = nil
|
196
|
+
|
197
|
+
expected_keys = [ :foo, :bar, :baz ]
|
198
|
+
tx.each_key do |key|
|
199
|
+
assert((expected_keys.include? key), key)
|
200
|
+
expected_keys.delete(key)
|
201
|
+
end
|
202
|
+
assert_equal([], expected_keys)
|
203
|
+
}
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Local Variables:
|
209
|
+
# mode: Ruby
|
210
|
+
# indent-tabs-mode: nil
|
211
|
+
# End:
|