higgs 0.1.0 → 0.1.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.
@@ -11,7 +11,7 @@ module Higgs::Test
11
11
  include Higgs
12
12
 
13
13
  # for ident(1)
14
- CVS_ID = '$Id: test_utils_bman.rb 567 2007-09-29 06:44:00Z toki $'
14
+ CVS_ID = '$Id: test_utils_bman.rb 621 2007-10-08 13:10:08Z toki $'
15
15
 
16
16
  STORAGE_ITEMS = (ENV['STORAGE_ITEMS'] || '100').to_i
17
17
  WARM_START_ITEMS = (ENV['WARM_START_ITEMS'] || '1000').to_i
@@ -25,6 +25,7 @@ module Higgs::Test
25
25
  @from = File.join(@from_dir, @from_name)
26
26
  @to_dir = 'bman_to'
27
27
  @to_name = 'bar'
28
+ @to = File.join(@to_dir, @to_name)
28
29
  FileUtils.rm_rf(@from_dir) # for debug
29
30
  FileUtils.mkdir_p(@from_dir)
30
31
  FileUtils.rm_rf(@to_dir) # for debug
@@ -42,11 +43,12 @@ module Higgs::Test
42
43
  :to_dir => @to_dir,
43
44
  :to_name => @to_name,
44
45
  :jlog_rotate_service_uri => @jlog_rotate_service_uri,
45
- :verbose => $DEBUG ? 2 : 0)
46
+ :verbose => $DEBUG ? 2 : 0,
47
+ :out => $DEBUG ? STDERR : '')
46
48
  end
47
49
 
48
50
  def teardown
49
- @from_st.shutdown
51
+ @from_st.shutdown unless @from_st.shutdown?
50
52
  DRb.stop_service # Why cannot each service be stopped?
51
53
  FileUtils.rm_rf(@from_dir) unless $DEBUG
52
54
  FileUtils.rm_rf(@to_dir) unless $DEBUG
@@ -54,52 +56,52 @@ module Higgs::Test
54
56
 
55
57
  def test_backup_index
56
58
  @bman.backup_index
57
- assert((File.exist? File.join(@to_dir, @to_name + '.idx')))
59
+ assert((File.exist? "#{@to}.idx"))
58
60
  end
59
61
 
60
62
  def test_backup_data
61
63
  @bman.backup_data
62
- assert(FileUtils.cmp(@from + '.tar', File.join(@to_dir, @to_name + '.tar')))
64
+ assert(FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
63
65
  end
64
66
 
65
67
  def test_rotate_jlog_0
66
- assert_equal(0, Storage.rotate_entries(@from + '.jlog').length)
68
+ assert_equal(0, Storage.rotate_entries("#{@from}.jlog").length)
67
69
  end
68
70
 
69
71
  def test_rotate_jlog_1
70
72
  @bman.rotate_jlog
71
- assert_equal(1, Storage.rotate_entries(@from + '.jlog').length)
73
+ assert_equal(1, Storage.rotate_entries("#{@from}.jlog").length)
72
74
  end
73
75
 
74
76
  def test_rotate_jlog_2
75
77
  @bman.rotate_jlog
76
78
  @bman.rotate_jlog
77
- assert_equal(2, Storage.rotate_entries(@from + '.jlog').length)
79
+ assert_equal(2, Storage.rotate_entries("#{@from}.jlog").length)
78
80
  end
79
81
 
80
82
  def test_rotate_jlog_10
81
83
  10.times do
82
84
  @bman.rotate_jlog
83
85
  end
84
- assert_equal(10, Storage.rotate_entries(@from + '.jlog').length)
86
+ assert_equal(10, Storage.rotate_entries("#{@from}.jlog").length)
85
87
  end
86
88
 
87
89
  def test_backup_jlog_0
88
90
  @bman.backup_jlog
89
- assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
91
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
90
92
  end
91
93
 
92
94
  def test_backup_jlog_1
93
95
  @bman.rotate_jlog
94
96
  @bman.backup_jlog
95
- assert_equal(1, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
97
+ assert_equal(1, Storage.rotate_entries("#{@to}.jlog").length)
96
98
  end
97
99
 
98
100
  def test_backup_jlog_2
99
101
  @bman.rotate_jlog
100
102
  @bman.rotate_jlog
101
103
  @bman.backup_jlog
102
- assert_equal(2, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
104
+ assert_equal(2, Storage.rotate_entries("#{@to}.jlog").length)
103
105
  end
104
106
 
105
107
  def test_backup_jlog_10
@@ -107,7 +109,7 @@ module Higgs::Test
107
109
  @bman.rotate_jlog
108
110
  end
109
111
  @bman.backup_jlog
110
- assert_equal(10, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
112
+ assert_equal(10, Storage.rotate_entries("#{@to}.jlog").length)
111
113
  end
112
114
 
113
115
  def test_clean_jlog
@@ -116,12 +118,16 @@ module Higgs::Test
116
118
  @bman.rotate_jlog
117
119
  @bman.backup_jlog
118
120
 
119
- assert_equal(3, Storage.rotate_entries(@from + '.jlog').length)
120
- assert_equal(3, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
121
+ assert_equal(3, Storage.rotate_entries("#{@from}.jlog").length)
122
+ assert_equal(3, Storage.rotate_entries("#{@to}.jlog").length)
123
+
124
+ @bman.clean_jlog_from
125
+ assert_equal(0, Storage.rotate_entries("#{@from}.jlog").length)
126
+ assert_equal(3, Storage.rotate_entries("#{@to}.jlog").length)
121
127
 
122
- @bman.clean_jlog
123
- assert_equal(0, Storage.rotate_entries(@from + '.jlog').length)
124
- assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
128
+ @bman.clean_jlog_to
129
+ assert_equal(0, Storage.rotate_entries("#{@from}.jlog").length)
130
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
125
131
  end
126
132
 
127
133
  def test_clean_jlog_delete_backup
@@ -131,12 +137,16 @@ module Higgs::Test
131
137
  @bman.backup_jlog
132
138
  @bman.rotate_jlog
133
139
 
134
- assert_equal(4, Storage.rotate_entries(@from + '.jlog').length)
135
- assert_equal(3, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
140
+ assert_equal(4, Storage.rotate_entries("#{@from}.jlog").length)
141
+ assert_equal(3, Storage.rotate_entries("#{@to}.jlog").length)
142
+
143
+ @bman.clean_jlog_from
144
+ assert_equal(1, Storage.rotate_entries("#{@from}.jlog").length)
145
+ assert_equal(3, Storage.rotate_entries("#{@to}.jlog").length)
136
146
 
137
- @bman.clean_jlog
138
- assert_equal(1, Storage.rotate_entries(@from + '.jlog').length)
139
- assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
147
+ @bman.clean_jlog_to
148
+ assert_equal(1, Storage.rotate_entries("#{@from}.jlog").length)
149
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
140
150
  end
141
151
 
142
152
  def test_clean_jlog_no_backup_no_delete
@@ -144,12 +154,16 @@ module Higgs::Test
144
154
  @bman.rotate_jlog
145
155
  @bman.rotate_jlog
146
156
 
147
- assert_equal(3, Storage.rotate_entries(@from + '.jlog').length)
148
- assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
157
+ assert_equal(3, Storage.rotate_entries("#{@from}.jlog").length)
158
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
149
159
 
150
- @bman.clean_jlog
151
- assert_equal(3, Storage.rotate_entries(@from + '.jlog').length)
152
- assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
160
+ @bman.clean_jlog_from
161
+ assert_equal(3, Storage.rotate_entries("#{@from}.jlog").length)
162
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
163
+
164
+ @bman.clean_jlog_to
165
+ assert_equal(3, Storage.rotate_entries("#{@from}.jlog").length)
166
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
153
167
  end
154
168
 
155
169
  def update_storage(options)
@@ -159,7 +173,7 @@ module Higgs::Test
159
173
  options[:end_of_warm_up].start if (count == WARM_START_ITEMS)
160
174
 
161
175
  write_list = []
162
- ope = [ :write, :system_properties, :custom_properties, :delete ][rand(3)]
176
+ ope = [ :write, :system_properties, :custom_properties, :delete ][rand(4)]
163
177
  key = rand(STORAGE_ITEMS)
164
178
  case (ope)
165
179
  when :write
@@ -200,13 +214,14 @@ module Higgs::Test
200
214
  @bman.backup_jlog
201
215
  @bman.recover
202
216
  @bman.verify
203
- @bman.clean_jlog
204
-
205
- assert(FileUtils.cmp(@from + '.tar', File.join(@to_dir, @to_name + '.tar')))
206
- assert_equal(Index.new.load(@from + '.idx').to_h,
207
- Index.new.load(File.join(@to_dir, @to_name + '.idx')).to_h)
208
- assert_equal(0, Storage.rotate_entries(@from + '.jlog').length)
209
- assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
217
+ @bman.clean_jlog_from
218
+ @bman.clean_jlog_to
219
+
220
+ assert(FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
221
+ assert(Index.new.load("#{@from}.idx").to_h ==
222
+ Index.new.load("#{@to}.idx").to_h)
223
+ assert_equal(0, Storage.rotate_entries("#{@from}.jlog").length)
224
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
210
225
  end
211
226
 
212
227
  def test_online_backup
@@ -221,9 +236,212 @@ module Higgs::Test
221
236
  options[:spin_lock] = false
222
237
  t.join
223
238
 
224
- assert((File.file? File.join(@to_dir, @to_name + '.tar')))
225
- assert((File.file? File.join(@to_dir, @to_name + '.idx')))
226
- assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
239
+ assert((File.file? "#{@to}.tar"))
240
+ assert((File.file? "#{@to}.idx"))
241
+ assert_equal(0, Storage.rotate_entries("#{@to}.jlog").length)
242
+ end
243
+
244
+ def test_online_backup_with_latest_journal_log
245
+ options = {
246
+ :end_of_warm_up => Latch.new,
247
+ :spin_lock => true
248
+ }
249
+ t = Thread.new{ update_storage(options) }
250
+
251
+ options[:end_of_warm_up].wait
252
+ @bman.online_backup
253
+ options[:spin_lock] = false
254
+ t.join
255
+
256
+ @bman.backup_jlog
257
+ FileUtils.cp("#{@from}.jlog", "#{@to}.jlog", :preserve => true)
258
+ @bman.recover
259
+ @from_st.shutdown
260
+
261
+ assert(FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
262
+ assert(Index.new.load("#{@from}.idx").to_h ==
263
+ Index.new.load("#{@to}.idx").to_h)
264
+ assert(! FileUtils.cmp("#{@from}.jlog", "#{@to}.jlog"))
265
+
266
+ st = Storage.new(@to)
267
+ st.shutdown
268
+
269
+ assert(FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
270
+ assert(Index.new.load("#{@from}.idx").to_h ==
271
+ Index.new.load("#{@to}.idx").to_h)
272
+ assert(FileUtils.cmp("#{@from}.jlog", "#{@to}.jlog"))
273
+ end
274
+
275
+ def test_online_backup_with_incompleted_journal_log
276
+ options = {
277
+ :end_of_warm_up => Latch.new,
278
+ :spin_lock => true
279
+ }
280
+ t = Thread.new{ update_storage(options) }
281
+
282
+ options[:end_of_warm_up].wait
283
+ @bman.online_backup
284
+ options[:spin_lock] = false
285
+ t.join
286
+
287
+ @bman.backup_jlog
288
+ FileUtils.cp("#{@from}.jlog", "#{@to}.jlog", :preserve => true)
289
+ File.truncate("#{@to}.jlog", File.stat("#{@to}.jlog").size + 1) # like incompleted
290
+ @bman.recover
291
+ @from_st.shutdown
292
+
293
+ assert(FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
294
+ assert(Index.new.load("#{@from}.idx").to_h ==
295
+ Index.new.load("#{@to}.idx").to_h)
296
+ assert(! FileUtils.cmp("#{@from}.jlog", "#{@to}.jlog"))
297
+
298
+ st = Storage.new(@to)
299
+ st.shutdown
300
+
301
+ assert(FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
302
+ assert(Index.new.load("#{@from}.idx").to_h ==
303
+ Index.new.load("#{@to}.idx").to_h)
304
+ assert(FileUtils.cmp("#{@from}.jlog", "#{@to}.jlog"))
305
+ end
306
+
307
+ def test_restore_files
308
+ options = {
309
+ :end_of_warm_up => Latch.new,
310
+ :spin_lock => true
311
+ }
312
+ t = Thread.new{ update_storage(options) }
313
+
314
+ options[:end_of_warm_up].wait
315
+ @bman.online_backup
316
+ options[:spin_lock] = false
317
+ t.join
318
+
319
+ @from_st.shutdown
320
+
321
+ assert(! FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
322
+ assert(Index.new.load("#{@from}.idx").to_h !=
323
+ Index.new.load("#{@to}.idx").to_h)
324
+
325
+ @bman.restore_files
326
+
327
+ assert(FileUtils.cmp("#{@from}.tar", "#{@to}.tar"))
328
+ assert(Index.new.load("#{@from}.idx").to_h ==
329
+ Index.new.load("#{@to}.idx").to_h)
330
+ end
331
+
332
+ def test_restore_recover_and_verify
333
+ options = {
334
+ :end_of_warm_up => Latch.new,
335
+ :spin_lock => true
336
+ }
337
+ t = Thread.new{ update_storage(options) }
338
+
339
+ options[:end_of_warm_up].wait
340
+ @bman.online_backup
341
+ options[:spin_lock] = false
342
+ t.join
343
+
344
+ @from_st.shutdown
345
+ FileUtils.cp("#{@from}.tar", "#{@from}.tar.orig", :preserve => true)
346
+ FileUtils.cp("#{@from}.idx", "#{@from}.idx.orig", :preserve => true)
347
+
348
+ @bman.restore_files
349
+ @bman.restore_recover
350
+ @bman.restore_verify
351
+
352
+ assert(FileUtils.cmp("#{@from}.tar", "#{@from}.tar.orig"))
353
+ assert(Index.new.load("#{@from}.idx").to_h ==
354
+ Index.new.load("#{@from}.idx.orig").to_h)
355
+ end
356
+
357
+ def test_restore
358
+ options = {
359
+ :end_of_warm_up => Latch.new,
360
+ :spin_lock => true
361
+ }
362
+ t = Thread.new{ update_storage(options) }
363
+
364
+ options[:end_of_warm_up].wait
365
+ @bman.online_backup
366
+ options[:spin_lock] = false
367
+ t.join
368
+
369
+ @from_st.shutdown
370
+ FileUtils.cp("#{@from}.tar", "#{@from}.tar.orig", :preserve => true)
371
+ FileUtils.cp("#{@from}.idx", "#{@from}.idx.orig", :preserve => true)
372
+
373
+ @bman.restore
374
+
375
+ assert(FileUtils.cmp("#{@from}.tar", "#{@from}.tar.orig"))
376
+ assert(Index.new.load("#{@from}.idx").to_h ==
377
+ Index.new.load("#{@from}.idx.orig").to_h)
378
+ end
379
+
380
+ def test_incremental_backup_with_recovery_and_restore
381
+ options = {
382
+ :end_of_warm_up => Latch.new,
383
+ :spin_lock => true
384
+ }
385
+ t = Thread.new{ update_storage(options) }
386
+
387
+ options[:end_of_warm_up].wait
388
+
389
+ # first step: full backup
390
+ @bman.online_backup
391
+
392
+ @bman.rotate_jlog
393
+
394
+ # incremental backup with recovery
395
+ @bman.backup_jlog
396
+ @bman.recover
397
+ @bman.verify
398
+ @bman.clean_jlog_from
399
+ @bman.clean_jlog_to
400
+
401
+ options[:spin_lock] = false
402
+ t.join
403
+
404
+ @from_st.shutdown
405
+ FileUtils.cp("#{@from}.tar", "#{@from}.tar.orig", :preserve => true)
406
+ FileUtils.cp("#{@from}.idx", "#{@from}.idx.orig", :preserve => true)
407
+
408
+ @bman.restore
409
+
410
+ assert(FileUtils.cmp("#{@from}.tar", "#{@from}.tar.orig"))
411
+ assert(Index.new.load("#{@from}.idx").to_h ==
412
+ Index.new.load("#{@from}.idx.orig").to_h)
413
+ end
414
+
415
+ def test_incremental_backup_without_recovery_and_restore
416
+ options = {
417
+ :end_of_warm_up => Latch.new,
418
+ :spin_lock => true
419
+ }
420
+ t = Thread.new{ update_storage(options) }
421
+
422
+ options[:end_of_warm_up].wait
423
+
424
+ # first step: full backup
425
+ @bman.online_backup
426
+
427
+ @bman.rotate_jlog
428
+
429
+ # incremental backup without recovery
430
+ @bman.backup_jlog
431
+ @bman.clean_jlog_from
432
+
433
+ options[:spin_lock] = false
434
+ t.join
435
+
436
+ @from_st.shutdown
437
+ FileUtils.cp("#{@from}.tar", "#{@from}.tar.orig", :preserve => true)
438
+ FileUtils.cp("#{@from}.idx", "#{@from}.idx.orig", :preserve => true)
439
+
440
+ @bman.restore
441
+
442
+ assert(FileUtils.cmp("#{@from}.tar", "#{@from}.tar.orig"))
443
+ assert(Index.new.load("#{@from}.idx").to_h ==
444
+ Index.new.load("#{@from}.idx.orig").to_h)
227
445
  end
228
446
  end
229
447
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: higgs
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-09-29 00:00:00 +09:00
6
+ version: 0.1.1
7
+ date: 2007-10-08 00:00:00 +09:00
8
8
  summary: pure ruby transactional storage compatible with unix TAR format
9
9
  require_paths:
10
10
  - lib
@@ -71,6 +71,7 @@ files:
71
71
  - test/test_storage_init_opts.rb
72
72
  - test/test_tman.rb
73
73
  - test/test_block.rb
74
+ - test/test_dbm.rb
74
75
  - test/test_storage_conf.rb
75
76
  - test/test_tar.rb
76
77
  - test/run.rb