higgs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/ChangeLog +208 -0
  2. data/LICENSE +26 -0
  3. data/README +2 -0
  4. data/Rakefile +75 -0
  5. data/bin/higgs_backup +67 -0
  6. data/bin/higgs_dump_index +43 -0
  7. data/bin/higgs_dump_jlog +42 -0
  8. data/bin/higgs_verify +37 -0
  9. data/lib/cgi/session/higgs.rb +72 -0
  10. data/lib/higgs/block.rb +192 -0
  11. data/lib/higgs/cache.rb +117 -0
  12. data/lib/higgs/dbm.rb +55 -0
  13. data/lib/higgs/exceptions.rb +31 -0
  14. data/lib/higgs/flock.rb +77 -0
  15. data/lib/higgs/index.rb +164 -0
  16. data/lib/higgs/jlog.rb +159 -0
  17. data/lib/higgs/lock.rb +189 -0
  18. data/lib/higgs/storage.rb +1086 -0
  19. data/lib/higgs/store.rb +228 -0
  20. data/lib/higgs/tar.rb +390 -0
  21. data/lib/higgs/thread.rb +370 -0
  22. data/lib/higgs/tman.rb +513 -0
  23. data/lib/higgs/utils/bman.rb +285 -0
  24. data/lib/higgs/utils.rb +22 -0
  25. data/lib/higgs/version.rb +21 -0
  26. data/lib/higgs.rb +59 -0
  27. data/misc/cache_bench/cache_bench.rb +43 -0
  28. data/misc/dbm_bench/.strc +8 -0
  29. data/misc/dbm_bench/Rakefile +78 -0
  30. data/misc/dbm_bench/dbm_multi_thread.rb +199 -0
  31. data/misc/dbm_bench/dbm_rnd_delete.rb +43 -0
  32. data/misc/dbm_bench/dbm_rnd_read.rb +44 -0
  33. data/misc/dbm_bench/dbm_rnd_update.rb +44 -0
  34. data/misc/dbm_bench/dbm_seq_read.rb +45 -0
  35. data/misc/dbm_bench/dbm_seq_write.rb +44 -0
  36. data/misc/dbm_bench/st_verify.rb +28 -0
  37. data/misc/io_bench/cksum_bench.rb +48 -0
  38. data/misc/io_bench/jlog_bench.rb +71 -0
  39. data/misc/io_bench/write_bench.rb +128 -0
  40. data/misc/thread_bench/lock_bench.rb +132 -0
  41. data/mkrdoc.rb +8 -0
  42. data/rdoc.yml +13 -0
  43. data/sample/count.rb +60 -0
  44. data/sample/dbmtest.rb +38 -0
  45. data/test/Rakefile +45 -0
  46. data/test/run.rb +32 -0
  47. data/test/test_block.rb +163 -0
  48. data/test/test_cache.rb +214 -0
  49. data/test/test_cgi_session.rb +142 -0
  50. data/test/test_flock.rb +162 -0
  51. data/test/test_index.rb +258 -0
  52. data/test/test_jlog.rb +180 -0
  53. data/test/test_lock.rb +320 -0
  54. data/test/test_online_backup.rb +169 -0
  55. data/test/test_storage.rb +439 -0
  56. data/test/test_storage_conf.rb +202 -0
  57. data/test/test_storage_init_opts.rb +89 -0
  58. data/test/test_store.rb +211 -0
  59. data/test/test_tar.rb +432 -0
  60. data/test/test_thread.rb +541 -0
  61. data/test/test_tman.rb +875 -0
  62. data/test/test_tman_init_opts.rb +56 -0
  63. data/test/test_utils_bman.rb +234 -0
  64. metadata +115 -0
@@ -0,0 +1,439 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'fileutils'
4
+ require 'higgs/storage'
5
+ require 'logger'
6
+ require 'test/unit'
7
+
8
+ module Higgs::Test
9
+ class StorageTest < Test::Unit::TestCase
10
+ include Higgs
11
+
12
+ # for ident(1)
13
+ CVS_ID = '$Id: test_storage.rb 559 2007-09-25 15:20:20Z toki $'
14
+
15
+ def setup
16
+ srand(0) # preset for rand
17
+ @test_dir = 'st_test'
18
+ FileUtils.rm_rf(@test_dir) # for debug
19
+ FileUtils.mkdir_p(@test_dir)
20
+ @name = File.join(@test_dir, 'foo')
21
+ @logger = proc{|path|
22
+ logger = Logger.new(path, 1)
23
+ logger.level = Logger::DEBUG
24
+ logger
25
+ }
26
+ @st = Storage.new(@name, :data_cksum_type => :MD5, :logger => @logger)
27
+ end
28
+
29
+ def teardown
30
+ @st.shutdown unless @st.shutdown?
31
+ FileUtils.rm_rf(@test_dir) unless $DEBUG
32
+ end
33
+
34
+ def test_raw_write_and_commit
35
+ write_list = [
36
+ [ :write, :foo, :data, 'foo', 0xFF.chr * 1024 ],
37
+ [ :write, :foo, :data, 'foo', "Hello world.\n" ],
38
+ [ :write, :foo, :data, 'foo', "Hello world.\n" ],
39
+ [ :write, :foo, :data, 'foo', 0xFF.chr * 1024 ],
40
+ [ :write, :foo, :data, 'foo', "Hello world.\n" ],
41
+ [ :delete, :foo ],
42
+ [ :write, :foo, :data, 'foo', "Hello world.\n" ],
43
+ [ :write, :foo, :data, 'foo', 0xFF.chr * 1024 ]
44
+ ]
45
+ @st.raw_write_and_commit(write_list)
46
+ end
47
+
48
+ def test_recover
49
+ @st.shutdown
50
+ @st = Storage.new(@name,
51
+ :data_cksum_type => :MD5,
52
+ :jlog_rotate_max => 0, # unlimited rotation
53
+ :logger => @logger)
54
+
55
+ loop_count = 100
56
+ data_count = 10
57
+
58
+ loop_count.times do
59
+ write_list = []
60
+ ope = [ :write, :delete ][rand(2)]
61
+ key = rand(data_count)
62
+ case (ope)
63
+ when :write
64
+ type = [ :a, :b ][rand(2)]
65
+ value = rand(256).chr * rand(5120)
66
+ write_list << [ ope, key, type, key.to_s, value ]
67
+ when :delete
68
+ next unless (@st.key? key)
69
+ write_list << [ ope, key ]
70
+ else
71
+ raise "unknown operation: #{ope}"
72
+ end
73
+ @st.raw_write_and_commit(write_list)
74
+ end
75
+
76
+ 3.times do
77
+ @st.rotate_journal_log(false)
78
+ end
79
+ 3.times do
80
+ @st.rotate_journal_log(true)
81
+ end
82
+
83
+ @st.shutdown
84
+
85
+ other_name = File.join(@test_dir, 'bar')
86
+ for name in Storage.rotate_entries("#{@name}.jlog")
87
+ name =~ /\.jlog.*$/ or raise 'mismatch'
88
+ FileUtils.cp(name, other_name + $&)
89
+ end
90
+ Storage.recover(other_name)
91
+
92
+ assert(FileUtils.cmp("#{@name}.tar", "#{other_name}.tar"), 'tar')
93
+ assert(FileUtils.cmp("#{@name}.idx", "#{other_name}.idx"), 'idx')
94
+ end
95
+
96
+ def test_write_and_commit
97
+ write_list = [
98
+ [ :write, :foo, '' ],
99
+ [ :delete, :foo ],
100
+ [ :write, :foo, "Hello world.\n" ],
101
+ [ :system_properties, :foo, { 'string_only' => true } ],
102
+ [ :custom_properties, :foo, { 'TestDate' => '2007-04-29' } ]
103
+ ]
104
+ @st.write_and_commit(write_list)
105
+ end
106
+
107
+ def test_write_and_commit_fetch
108
+ assert_nil(@st.fetch('foo'))
109
+ assert_nil(@st.fetch_properties('foo'))
110
+
111
+ # add
112
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
113
+
114
+ assert_equal("Hello world.\n", @st.fetch('foo'))
115
+ properties = @st.fetch_properties('foo')
116
+ assert_equal(Digest::MD5.hexdigest("Hello world.\n"), properties['system_properties']['hash_value'])
117
+ assert_equal(false, properties['system_properties']['string_only'])
118
+ assert_equal({}, properties['custom_properties'])
119
+ assert_equal(false, @st.string_only('foo'))
120
+
121
+ # update properties
122
+ @st.write_and_commit([ [ :system_properties, 'foo', { 'string_only' => true } ] ])
123
+ @st.write_and_commit([ [ :custom_properties, 'foo', { :comment => 'test' } ] ])
124
+
125
+ assert_equal("Hello world.\n", @st.fetch('foo'))
126
+ properties = @st.fetch_properties('foo')
127
+ assert_equal(Digest::MD5.hexdigest("Hello world.\n"), properties['system_properties']['hash_value'])
128
+ assert_equal(true, properties['system_properties']['string_only'])
129
+ assert_equal({ :comment => 'test' }, properties['custom_properties'])
130
+ assert_equal(true, @st.string_only('foo'))
131
+
132
+ # update
133
+ @st.write_and_commit([ [ :write, 'foo', "Good bye.\n" ] ])
134
+
135
+ assert_equal("Good bye.\n", @st.fetch('foo'))
136
+ properties = @st.fetch_properties('foo')
137
+ assert_equal(Digest::MD5.hexdigest("Good bye.\n"), properties['system_properties']['hash_value'])
138
+ assert_equal(true, properties['system_properties']['string_only'])
139
+ assert_equal({ :comment => 'test' }, properties['custom_properties'])
140
+ assert_equal(true, @st.string_only('foo'))
141
+
142
+ # delete
143
+ @st.write_and_commit([ [ :delete, 'foo' ] ])
144
+
145
+ assert_nil(@st.fetch('foo'))
146
+ assert_nil(@st.fetch_properties('foo'))
147
+ end
148
+
149
+ def test_write_and_commit_fetch_zero_bytes
150
+ assert_nil(@st.fetch('foo'))
151
+ assert_nil(@st.fetch_properties('foo'))
152
+
153
+ @st.write_and_commit([ [ :write, 'foo', '' ] ])
154
+
155
+ assert_equal('', @st.fetch('foo'))
156
+ properties = @st.fetch_properties('foo')
157
+ assert_equal(Digest::MD5.hexdigest(''), properties['system_properties']['hash_value'])
158
+ assert_equal({}, properties['custom_properties'])
159
+ end
160
+
161
+ def test_write_and_commit_fetch_delete_no_data
162
+ assert_nil(@st.fetch('foo'))
163
+ assert_nil(@st.fetch_properties('foo'))
164
+
165
+ @st.write_and_commit([ [ :delete , 'foo'] ])
166
+
167
+ assert_nil(@st.fetch('foo'))
168
+ assert_nil(@st.fetch_properties('foo'))
169
+ end
170
+
171
+ def test_write_and_commit_read_only_NotWritableError
172
+ @st.shutdown
173
+ @st = nil
174
+ @st = Storage.new(@name, :read_only => true, :logger => @logger)
175
+ assert_raise(Storage::NotWritableError) {
176
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
177
+ }
178
+ end
179
+
180
+ def test_write_and_commit_IndexError_not_exist_properties
181
+ assert_raise(IndexError) {
182
+ @st.write_and_commit([ [ :system_properties, 'foo', {} ] ])
183
+ }
184
+ assert_nil(@st.fetch('foo'))
185
+ assert_nil(@st.fetch_properties('foo'))
186
+
187
+ assert_raise(IndexError) {
188
+ @st.write_and_commit([ [ :custom_properties, 'foo', {} ] ])
189
+ }
190
+ assert_nil(@st.fetch('foo'))
191
+ assert_nil(@st.fetch_properties('foo'))
192
+
193
+ assert_raise(IndexError) {
194
+ write_list = [
195
+ [ :write, 'foo', "Hello world.\n" ],
196
+ [ :delete, 'foo' ],
197
+ [ :system_properties, 'foo', {} ]
198
+ ]
199
+ @st.write_and_commit(write_list)
200
+ }
201
+ assert_nil(@st.fetch('foo'))
202
+ assert_nil(@st.fetch_properties('foo'))
203
+
204
+ assert_raise(IndexError) {
205
+ write_list = [
206
+ [ :write, 'foo', "Hello world.\n" ],
207
+ [ :delete, 'foo' ],
208
+ [ :custom_properties, 'foo', {} ]
209
+ ]
210
+ @st.write_and_commit(write_list)
211
+ }
212
+ assert_nil(@st.fetch('foo'))
213
+ assert_nil(@st.fetch_properties('foo'))
214
+ end
215
+
216
+ def test_write_and_commit_TypeError_value_not_string
217
+ assert_raise(TypeError) {
218
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n".to_sym ] ])
219
+ }
220
+ end
221
+
222
+ def test_write_and_commit_ArgumentError_operation_unknown
223
+ assert_raise(ArgumentError) {
224
+ @st.write_and_commit([ [ :unknown, 'foo', "Hello world.\n" ] ])
225
+ }
226
+ end
227
+
228
+ def test_system_properties
229
+ @st.write_and_commit([ [ :write, :foo, 'apple' ] ])
230
+
231
+ cre_time = @st.fetch_properties(:foo)['system_properties']['created_time']
232
+ chg_time = @st.fetch_properties(:foo)['system_properties']['changed_time']
233
+ mod_time = @st.fetch_properties(:foo)['system_properties']['modified_time']
234
+
235
+ sleep(0.001)
236
+ @st.write_and_commit([ [ :write, :foo, 'banana' ] ])
237
+
238
+ assert_equal(cre_time, @st.fetch_properties(:foo)['system_properties']['created_time'])
239
+ assert_equal(chg_time, @st.fetch_properties(:foo)['system_properties']['changed_time'])
240
+ assert(@st.fetch_properties(:foo)['system_properties']['modified_time'] > mod_time)
241
+
242
+ mod_time2 = @st.fetch_properties(:foo)['system_properties']['modified_time']
243
+ sleep(0.001)
244
+ @st.write_and_commit([ [ :custom_properties, :foo, { 'bar' => 'orange' } ] ])
245
+
246
+ assert_equal(cre_time, @st.fetch_properties(:foo)['system_properties']['created_time'])
247
+ assert(@st.fetch_properties(:foo)['system_properties']['changed_time'] > chg_time)
248
+ assert_equal(mod_time2, @st.fetch_properties(:foo)['system_properties']['modified_time'])
249
+
250
+ chg_time2 = @st.fetch_properties(:foo)['system_properties']['changed_time']
251
+ sleep(0.001)
252
+ @st.write_and_commit([ [ :system_properties, :foo, { 'string_only' => true } ] ])
253
+
254
+ assert_equal(cre_time, @st.fetch_properties(:foo)['system_properties']['created_time'])
255
+ assert(@st.fetch_properties(:foo)['system_properties']['changed_time'] > chg_time2)
256
+ assert_equal(mod_time2, @st.fetch_properties(:foo)['system_properties']['modified_time'])
257
+ end
258
+
259
+ def test_string_only_IndexError_not_exist_properties
260
+ assert_raise(IndexError) { @st.string_only('foo') }
261
+ end
262
+
263
+ def test_key
264
+ assert_equal(false, (@st.key? 'foo'))
265
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
266
+ assert_equal(true, (@st.key? 'foo'))
267
+ @st.write_and_commit([ [ :delete , 'foo' ] ])
268
+ assert_equal(false, (@st.key? 'foo'))
269
+ end
270
+
271
+ def test_key_read_only
272
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
273
+ @st.shutdown
274
+ @st = nil
275
+ @st = Storage.new(@name, :read_only => true, :logger => @logger)
276
+
277
+ assert_equal(true, (@st.key? 'foo'))
278
+ assert_equal(false, (@st.key? 'bar'))
279
+ end
280
+
281
+ def test_each_key
282
+ @st.each_key do |key|
283
+ flunk('not to reach')
284
+ end
285
+
286
+ @st.write_and_commit([ [ :write, 'foo', 'one' ],
287
+ [ :write, 'bar', 'two' ],
288
+ [ :write, 'baz', 'three' ]
289
+ ])
290
+
291
+ expected_keys = %w[ foo bar baz ]
292
+ @st.each_key do |key|
293
+ assert(expected_keys.delete(key), "each_key do |#{key}|")
294
+ end
295
+ assert(expected_keys.empty?)
296
+
297
+ @st.write_and_commit([ [ :delete, 'bar' ] ])
298
+
299
+ expected_keys = %w[ foo baz ]
300
+ @st.each_key do |key|
301
+ assert(expected_keys.delete(key), "each_key do |#{key}|")
302
+ end
303
+ assert(expected_keys.empty?)
304
+ end
305
+
306
+ def test_each_key_read_only
307
+ @st.write_and_commit([ [ :write, 'foo', 'one' ],
308
+ [ :write, 'bar', 'two' ],
309
+ [ :write, 'baz', 'three' ]
310
+ ])
311
+ @st.shutdown
312
+ @st = nil
313
+ @st = Storage.new(@name, :read_only => true, :logger => @logger)
314
+
315
+ expected_keys = %w[ foo bar baz ]
316
+ @st.each_key do |key|
317
+ assert(expected_keys.delete(key), "each_key do |#{key}|")
318
+ end
319
+ assert(expected_keys.empty?)
320
+ end
321
+
322
+ def test_verify
323
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
324
+ @st.verify
325
+ end
326
+
327
+ def test_verify_BrokenError_mismatch_content_hash
328
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
329
+ File.open(@name + '.tar', File::WRONLY) {|w|
330
+ size = w.stat.size
331
+
332
+ data_body_offset = size - Tar::Block::BLKSIZ * 5
333
+ # EOA -> 2 blocks
334
+ # properties body -> 1 block
335
+ # properties head -> 1 block
336
+ # data body -> 1 block
337
+ # total 5 blocks skip from the end of file
338
+
339
+ w.seek(data_body_offset)
340
+ w.write(0xFF.chr * Tar::Block::BLKSIZ)
341
+ }
342
+ assert_raise(Storage::PanicError) {
343
+ @st.verify
344
+ }
345
+ end
346
+
347
+ def test_verify_BrokenError_failed_to_read_data
348
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
349
+ File.open(@name + '.tar', File::WRONLY) {|w|
350
+ size = w.stat.size
351
+
352
+ data_head_offset = size - Tar::Block::BLKSIZ * 6
353
+ # EOA -> 2 blocks
354
+ # properties body -> 1 block
355
+ # properties head -> 1 block
356
+ # data body -> 1 block
357
+ # data head -> 1 block
358
+ # total 6 blocks skip from the end of file
359
+
360
+ w.truncate(data_head_offset)
361
+ t = Tar::ArchiveWriter.new(w)
362
+ t.write_EOA
363
+ t.close(false)
364
+ }
365
+ assert_raise(Storage::PanicError) {
366
+ @st.verify
367
+ }
368
+ end
369
+
370
+ def test_verify_BrokenError_failed_to_read_properties
371
+ @st.write_and_commit([ [ :write, 'foo', "Hello world.\n" ] ])
372
+ File.open(@name + '.tar', File::WRONLY) {|w|
373
+ size = w.stat.size
374
+
375
+ props_head_offset = size - Tar::Block::BLKSIZ * 4
376
+ # EOA -> 2 blocks
377
+ # properties body -> 1 block
378
+ # properties head -> 1 block
379
+ # total 4 blocks skip from the end of file
380
+
381
+ w.truncate(props_head_offset)
382
+ t = Tar::ArchiveWriter.new(w)
383
+ t.write_EOA
384
+ t.close(false)
385
+ }
386
+ assert_raise(Storage::PanicError) {
387
+ @st.verify
388
+ }
389
+ end
390
+
391
+ def test_shutdown
392
+ @st.shutdown
393
+ assert_raise(Storage::ShutdownException) { @st.shutdown }
394
+ assert_raise(Storage::ShutdownException) { @st.fetch('foo') }
395
+ assert_raise(Storage::ShutdownException) { @st.fetch_properties('foo') }
396
+ assert_raise(Storage::ShutdownException) { @st.key? 'foo' }
397
+ assert_raise(Storage::ShutdownException) {
398
+ @st.each_key do
399
+ flunk('not to reach')
400
+ end
401
+ }
402
+ assert_raise(Storage::ShutdownException) { @st.write_and_commit([]) }
403
+ assert_raise(Storage::ShutdownException) { @st.verify }
404
+ end
405
+ end
406
+
407
+ class ReadOnlyStorageFirstOpenTest < Test::Unit::TestCase
408
+ include Higgs
409
+
410
+ # for ident(1)
411
+ CVS_ID = '$Id: test_storage.rb 559 2007-09-25 15:20:20Z toki $'
412
+ def setup
413
+ @test_dir = 'st_test'
414
+ FileUtils.rm_rf(@test_dir) # for debug
415
+ FileUtils.mkdir_p(@test_dir)
416
+ @name = File.join(@test_dir, 'foo')
417
+ @logger = proc{|path|
418
+ logger = Logger.new(path, 1)
419
+ logger.level = Logger::DEBUG
420
+ logger
421
+ }
422
+ end
423
+
424
+ def teardown
425
+ FileUtils.rm_rf(@test_dir) unless $DEBUG
426
+ end
427
+
428
+ def test_read_only_first_open
429
+ assert_raise(Errno::ENOENT) {
430
+ Storage.new(@name, :read_only => true, :logger => @logger)
431
+ }
432
+ end
433
+ end
434
+ end
435
+
436
+ # Local Variables:
437
+ # mode: Ruby
438
+ # indent-tabs-mode: nil
439
+ # End:
@@ -0,0 +1,202 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'fileutils'
4
+ require 'higgs/storage'
5
+ require 'test/unit'
6
+
7
+ module Higgs::Test
8
+ class StorageConfTest < Test::Unit::TestCase
9
+ # for ident(1)
10
+ CVS_ID = '$Id: test_storage_conf.rb 559 2007-09-25 15:20:20Z toki $'
11
+
12
+ include Higgs
13
+
14
+ def setup
15
+ @conf_path = 'storage_conf.yml'
16
+ @log_path = 'dummy.log'
17
+ end
18
+
19
+ def teardown
20
+ FileUtils.rm_f(@conf_path)
21
+ FileUtils.rm_f(@log_path)
22
+ end
23
+
24
+ def test_read_only
25
+ File.open(@conf_path, 'w') {|w|
26
+ w << "read_only: true\n"
27
+ }
28
+ options = Storage.load_conf(@conf_path)
29
+ assert_equal(true, options[:read_only])
30
+
31
+ File.open(@conf_path, 'w') {|w|
32
+ w << "read_only: false\n"
33
+ }
34
+ options = Storage.load_conf(@conf_path)
35
+ assert_equal(false, options[:read_only])
36
+ end
37
+
38
+ def test_number_of_io
39
+ File.open(@conf_path, 'w') {|w|
40
+ w << "number_of_io: 4\n"
41
+ }
42
+ options = Storage.load_conf(@conf_path)
43
+ assert_equal(4, options[:number_of_io])
44
+ end
45
+
46
+ def test_data_hash_type
47
+ File.open(@conf_path, 'w') {|w|
48
+ w << "data_hash_type: SHA512\n"
49
+ }
50
+ options = Storage.load_conf(@conf_path)
51
+ assert_equal(:SHA512, options[:data_hash_type])
52
+ end
53
+
54
+ def test_jlog_sync
55
+ File.open(@conf_path, 'w') {|w|
56
+ w << "jlog_sync: true\n"
57
+ }
58
+ options = Storage.load_conf(@conf_path)
59
+ assert_equal(true, options[:jlog_sync])
60
+
61
+ File.open(@conf_path, 'w') {|w|
62
+ w << "jlog_sync: false\n"
63
+ }
64
+ options = Storage.load_conf(@conf_path)
65
+ assert_equal(false, options[:jlog_sync])
66
+ end
67
+
68
+ def test_jlog_hash_type
69
+ File.open(@conf_path, 'w') {|w|
70
+ w << "jlog_hash_type: SHA512\n"
71
+ }
72
+ options = Storage.load_conf(@conf_path)
73
+ assert_equal(:SHA512, options[:jlog_hash_type])
74
+ end
75
+
76
+ def test_jlog_rotate_size
77
+ File.open(@conf_path, 'w') {|w|
78
+ w << "jlog_rotate_size: 33554432\n"
79
+ }
80
+ options = Storage.load_conf(@conf_path)
81
+ assert_equal(33554432, options[:jlog_rotate_size])
82
+ end
83
+
84
+ def test_jlog_rotate_max
85
+ File.open(@conf_path, 'w') {|w|
86
+ w << "jlog_rotate_max: 0\n"
87
+ }
88
+ options = Storage.load_conf(@conf_path)
89
+ assert_equal(0, options[:jlog_rotate_max])
90
+ end
91
+
92
+ def test_jlog_rotate_service_uri
93
+ File.open(@conf_path, 'w') {|w|
94
+ w << "jlog_rotate_service_uri: druby://localhost:14142\n"
95
+ }
96
+ options = Storage.load_conf(@conf_path)
97
+ assert_equal('druby://localhost:14142', options[:jlog_rotate_service_uri])
98
+ end
99
+
100
+ def test_properties_cache_limit_size
101
+ File.open(@conf_path, 'w') {|w|
102
+ w << "properties_cache_limit_size: 256\n"
103
+ }
104
+ options = Storage.load_conf(@conf_path)
105
+ assert_instance_of(LRUCache, options[:properties_cache]) # autoload `higgs/cache'
106
+ assert_equal(256, options[:properties_cache].limit_size)
107
+ end
108
+
109
+ def test_master_cache_limit_size
110
+ File.open(@conf_path, 'w') {|w|
111
+ w << "master_cache_limit_size: 256\n"
112
+ }
113
+ options = Storage.load_conf(@conf_path)
114
+ assert_instance_of(LRUCache, options[:master_cache]) # autoload `higgs/cache'
115
+ assert_equal(256, options[:master_cache].limit_size)
116
+ end
117
+
118
+ def test_logging_level_debug
119
+ File.open(@conf_path, 'w') {|w|
120
+ w << "logging_level: debug\n"
121
+ }
122
+ options = Storage.load_conf(@conf_path)
123
+ logger = options[:logger].call(@log_path)
124
+ begin
125
+ assert_instance_of(Logger, logger) # autoload `logger'
126
+ assert_equal(Logger::DEBUG, logger.level)
127
+ ensure
128
+ logger.close
129
+ end
130
+ end
131
+
132
+ def test_logging_level_info
133
+ File.open(@conf_path, 'w') {|w|
134
+ w << "logging_level: info\n"
135
+ }
136
+ options = Storage.load_conf(@conf_path)
137
+ logger = options[:logger].call(@log_path)
138
+ begin
139
+ assert_instance_of(Logger, logger) # autoload `logger'
140
+ assert_equal(Logger::INFO, logger.level)
141
+ ensure
142
+ logger.close
143
+ end
144
+ end
145
+
146
+ def test_logging_level_warn
147
+ File.open(@conf_path, 'w') {|w|
148
+ w << "logging_level: warn\n"
149
+ }
150
+ options = Storage.load_conf(@conf_path)
151
+ logger = options[:logger].call(@log_path)
152
+ begin
153
+ assert_instance_of(Logger, logger) # autoload `logger'
154
+ assert_equal(Logger::WARN, logger.level)
155
+ ensure
156
+ logger.close
157
+ end
158
+ end
159
+
160
+ def test_logging_level_error
161
+ File.open(@conf_path, 'w') {|w|
162
+ w << "logging_level: error\n"
163
+ }
164
+ options = Storage.load_conf(@conf_path)
165
+ logger = options[:logger].call(@log_path)
166
+ begin
167
+ assert_instance_of(Logger, logger) # autoload `logger'
168
+ assert_equal(Logger::ERROR, logger.level)
169
+ ensure
170
+ logger.close
171
+ end
172
+ end
173
+
174
+ def test_logging_level_fatal
175
+ File.open(@conf_path, 'w') {|w|
176
+ w << "logging_level: fatal\n"
177
+ }
178
+ options = Storage.load_conf(@conf_path)
179
+ logger = options[:logger].call(@log_path)
180
+ begin
181
+ assert_instance_of(Logger, logger) # autoload `logger'
182
+ assert_equal(Logger::FATAL, logger.level)
183
+ ensure
184
+ logger.close
185
+ end
186
+ end
187
+
188
+ def test_logging_level_unknown
189
+ File.open(@conf_path, 'w') {|w|
190
+ w << "logging_level: foo\n"
191
+ }
192
+ assert_raise(RuntimeError) {
193
+ Storage.load_conf(@conf_path)
194
+ }
195
+ end
196
+ end
197
+ end
198
+
199
+ # Local Variables:
200
+ # mode: Ruby
201
+ # indent-tabs-mode: nil
202
+ # End: