roma 0.8.2 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/CHANG +326 -0
  2. data/CHANGELOG +132 -0
  3. data/{README.rdoc → FETCH_HEAD} +0 -0
  4. data/{LICENSE.rdoc → LICENSE} +0 -1
  5. data/README +17 -0
  6. data/Rakefile +33 -18
  7. data/ruby/server/bin/chg_redundancy +10 -0
  8. data/ruby/server/bin/key_access +7 -0
  9. data/ruby/server/bin/key_list +7 -0
  10. data/ruby/server/bin/mkconfig +19 -0
  11. data/{bin → ruby/server/bin}/mkrecent +0 -1
  12. data/{bin → ruby/server/bin}/mkroute +0 -1
  13. data/ruby/server/bin/multi_commander +19 -0
  14. data/ruby/server/bin/recoverlost +10 -0
  15. data/ruby/server/bin/recoverlost_alist +10 -0
  16. data/ruby/server/bin/recoverlost_alist_all +10 -0
  17. data/ruby/server/bin/recoverlost_alist_keys +10 -0
  18. data/{bin/recoverlost → ruby/server/bin/roma_watcher} +1 -2
  19. data/ruby/server/bin/romad +36 -0
  20. data/{bin → ruby/server/bin}/sample_watcher +0 -1
  21. data/{bin → ruby/server/bin}/sample_watcher2 +0 -1
  22. data/{bin/simple_bench → ruby/server/bin/sample_watcher3} +1 -2
  23. data/ruby/server/bin/simple_bench +26 -0
  24. data/{bin → ruby/server/bin}/ssroute +0 -1
  25. data/ruby/server/bin/test-scenario +11 -0
  26. data/{bin → ruby/server/bin}/tribunus +0 -1
  27. data/{lib → ruby/server/lib}/roma/async_process.rb +67 -15
  28. data/{lib → ruby/server/lib}/roma/command/bg_command_receiver.rb +1 -1
  29. data/ruby/server/lib/roma/command/command_definition.rb +422 -0
  30. data/ruby/server/lib/roma/command/mh_command_receiver.rb +127 -0
  31. data/ruby/server/lib/roma/command/receiver.rb +64 -0
  32. data/{lib → ruby/server/lib}/roma/command/rt_command_receiver.rb +6 -1
  33. data/ruby/server/lib/roma/command/sys_command_receiver.rb +609 -0
  34. data/{lib → ruby/server/lib}/roma/command/util_command_receiver.rb +15 -5
  35. data/{lib → ruby/server/lib}/roma/command/vn_command_receiver.rb +12 -4
  36. data/{lib → ruby/server/lib}/roma/command_plugin.rb +0 -0
  37. data/ruby/server/lib/roma/config.rb +84 -0
  38. data/{lib → ruby/server/lib}/roma/event/con_pool.rb +12 -1
  39. data/ruby/server/lib/roma/event/handler.rb +256 -0
  40. data/ruby/server/lib/roma/live_patch-20120302-001.rb +107 -0
  41. data/ruby/server/lib/roma/logging/rlogger.rb +163 -0
  42. data/ruby/server/lib/roma/messaging/con_pool.rb +92 -0
  43. data/{lib → ruby/server/lib}/roma/plugin/plugin_alist.rb +118 -240
  44. data/ruby/server/lib/roma/plugin/plugin_debug.rb +31 -0
  45. data/ruby/server/lib/roma/plugin/plugin_map.rb +177 -0
  46. data/ruby/server/lib/roma/plugin/plugin_mapcount.rb +185 -0
  47. data/{lib/roma/command/st_command_receiver.rb → ruby/server/lib/roma/plugin/plugin_storage.rb} +170 -146
  48. data/ruby/server/lib/roma/plugin/plugin_stub.rb +283 -0
  49. data/{lib → ruby/server/lib}/roma/plugin/plugin_test.rb +0 -0
  50. data/{lib → ruby/server/lib}/roma/romad.rb +221 -94
  51. data/{lib → ruby/server/lib}/roma/routing/cb_rttable.rb +4 -6
  52. data/{lib → ruby/server/lib}/roma/routing/merkle_tree.rb +0 -0
  53. data/ruby/server/lib/roma/routing/routing_data.rb +307 -0
  54. data/{lib → ruby/server/lib}/roma/routing/rttable.rb +4 -0
  55. data/{lib → ruby/server/lib}/roma/stats.rb +19 -3
  56. data/{lib → ruby/server/lib}/roma/storage/basic_storage.rb +25 -26
  57. data/{lib → ruby/server/lib}/roma/storage/dbm_storage.rb +1 -23
  58. data/{lib → ruby/server/lib}/roma/storage/dummy_storage.rb +0 -0
  59. data/{lib → ruby/server/lib}/roma/storage/rh_storage.rb +0 -0
  60. data/{lib → ruby/server/lib}/roma/storage/sqlite3_storage.rb +0 -0
  61. data/{lib → ruby/server/lib}/roma/storage/tc_storage.rb +62 -2
  62. data/ruby/server/lib/roma/tools/chg_redundancy.rb +36 -0
  63. data/ruby/server/lib/roma/tools/key_access.rb +105 -0
  64. data/ruby/server/lib/roma/tools/key_list.rb +94 -0
  65. data/ruby/server/lib/roma/tools/mkconfig.rb +535 -0
  66. data/{lib → ruby/server/lib}/roma/tools/mkrecent.rb +0 -0
  67. data/{lib → ruby/server/lib}/roma/tools/mkroute.rb +0 -0
  68. data/ruby/server/lib/roma/tools/multi_commander.rb +45 -0
  69. data/{lib → ruby/server/lib}/roma/tools/recoverlost.rb +0 -0
  70. data/{lib → ruby/server/lib}/roma/tools/recoverlost_alist.rb +0 -0
  71. data/ruby/server/lib/roma/tools/recoverlost_alist_all.rb +8 -0
  72. data/ruby/server/lib/roma/tools/recoverlost_alist_keys.rb +16 -0
  73. data/ruby/server/lib/roma/tools/recoverlost_lib.rb +349 -0
  74. data/ruby/server/lib/roma/tools/roma_watcher.rb +150 -0
  75. data/ruby/server/lib/roma/tools/roma_watcher_config.yml.example +20 -0
  76. data/{lib → ruby/server/lib}/roma/tools/sample_watcher.rb +3 -1
  77. data/{lib → ruby/server/lib}/roma/tools/sample_watcher2.rb +3 -1
  78. data/ruby/server/lib/roma/tools/sample_watcher3.rb +49 -0
  79. data/{lib → ruby/server/lib}/roma/tools/simple_bench.rb +2 -0
  80. data/ruby/server/lib/roma/tools/simple_bench2.rb +78 -0
  81. data/{lib → ruby/server/lib}/roma/tools/ssroute.rb +0 -0
  82. data/ruby/server/lib/roma/tools/test-scenario.rb +327 -0
  83. data/{lib → ruby/server/lib}/roma/tools/tribunus.rb +0 -0
  84. data/ruby/server/lib/roma/version.rb +4 -0
  85. data/{lib → ruby/server/lib}/roma/write_behind.rb +1 -0
  86. data/ruby/server/test/config4mhash.rb +68 -0
  87. data/ruby/server/test/config4storage_error.rb +69 -0
  88. data/{lib/roma/config.rb → ruby/server/test/config4test.rb} +6 -3
  89. data/{test → ruby/server/test}/rcirb.rb +0 -1
  90. data/{test → ruby/server/test}/roma-test-utils.rb +21 -8
  91. data/{test → ruby/server/test}/run-test.rb +3 -2
  92. data/ruby/server/test/storage_error_storage.rb +37 -0
  93. data/ruby/server/test/t_command_definition.rb +326 -0
  94. data/{test → ruby/server/test}/t_cpdata.rb +9 -3
  95. data/{test → ruby/server/test}/t_listplugin.rb +48 -12
  96. data/ruby/server/test/t_mapcountplugin.rb +231 -0
  97. data/ruby/server/test/t_mapplugin.rb +131 -0
  98. data/ruby/server/test/t_mhash.rb +222 -0
  99. data/ruby/server/test/t_rclient.rb +199 -0
  100. data/{test → ruby/server/test}/t_routing_data.rb +56 -0
  101. data/{test → ruby/server/test}/t_storage.rb +107 -111
  102. data/ruby/server/test/t_storage_error.rb +61 -0
  103. data/ruby/server/test/t_writebehind.rb +374 -0
  104. metadata +150 -82
  105. data/bin/recoverlost_alist +0 -8
  106. data/bin/romad +0 -7
  107. data/lib/roma/command/mh_command_receiver.rb +0 -117
  108. data/lib/roma/command/receiver.rb +0 -287
  109. data/lib/roma/event/handler.rb +0 -159
  110. data/lib/roma/plugin/plugin_debug.rb +0 -19
  111. data/lib/roma/tools/recoverlost_lib.rb +0 -217
  112. data/lib/roma/version.rb +0 -4
  113. data/test/t_rclient.rb +0 -318
  114. data/test/t_writebehind.rb +0 -200
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
2
 
4
3
  require 'roma/storage/tc_storage'
5
4
  require 'roma/storage/dbm_storage'
@@ -35,26 +34,28 @@ class TCStorageTest < Test::Unit::TestCase
35
34
  rmtestdir('storage_test')
36
35
  end
37
36
 
38
- # 普通のset get
39
37
  def test_set_get
40
38
  assert_equal( 'abc_data',@st.set(0,'abc',0,0xffffffff,'abc_data')[4])
41
39
  assert_equal( 'abc_data', @st.get(0,'abc',0) )
42
40
  end
43
41
 
44
- # 普通のset delete
45
42
  def test_set_delete
46
43
  @st.set(0,'abc',0,0xffffffff,'abc_data')
47
- assert_equal( 'abc_data', @st.delete(0,'abc',0)[4]) # 存在するキーの削除は value が返る
44
+ # delete method returns a value
45
+ assert_equal( 'abc_data', @st.delete(0,'abc',0)[4])
48
46
  assert_nil( @st.get(0,'abc',0) )
49
- assert_equal(:deletemark, @st.delete(0,'abc',0)) # 削除済みはマークがあることを返す
47
+ # delete method returns :deletemark with deleted key
48
+ assert_equal(:deletemark, @st.delete(0,'abc',0))
50
49
  end
51
50
 
52
- # 有効期限
53
51
  def test_set_exptime
54
52
  @st.set(0,'abc',0,Time.now.to_i,'abc_data')
55
- assert_equal('abc_data', @st.get(0,'abc',0) ) # 期限内
56
- @st.set(0,'abc',0,Time.now.to_i-1,'abc_data') # 有効期限を1秒前に
57
- assert_nil( @st.get(0,'abc',0)) # 期限切れ
53
+ # returns a value within a fixed time limit
54
+ assert_equal('abc_data', @st.get(0,'abc',0) )
55
+ # expire time is a second ago
56
+ @st.set(0,'abc',0,Time.now.to_i-1,'abc_data')
57
+ # returns a nil when expired
58
+ assert_nil( @st.get(0,'abc',0))
58
59
  end
59
60
 
60
61
  def test_set_get_raw
@@ -70,35 +71,36 @@ class TCStorageTest < Test::Unit::TestCase
70
71
  }
71
72
  end
72
73
 
73
- # 期限切れデータの削除
74
74
  def test_exp_delete
75
75
  assert_nil( @st.delete(0,'abc',0)[4])
76
- assert_equal('abc_data' , @st.set(0,'abc',0,Time.now.to_i-1,'abc_data')[4]) # 有効期限を1秒前に
77
- assert_nil( @st.delete(0,'abc',0)[4]) # 期限切れ
76
+ # expire time is a second ago
77
+ assert_equal('abc_data' , @st.set(0,'abc',0,Time.now.to_i-1,'abc_data')[4])
78
+ # delete method returns a nil in expired
79
+ assert_nil( @st.delete(0,'abc',0)[4])
78
80
  end
79
81
 
80
82
  def test_rset
81
- # クロックがカウントアップされる
83
+ # increase a logical clock
82
84
  assert_equal(0, @st.set(0,'abc',0,Time.now.to_i,'abc_data')[2] )
83
85
  assert_equal(1, @st.set(0,'abc',0,Time.now.to_i,'abc_data')[2] )
84
86
  assert_equal(2, @st.set(0,'abc',0,Time.now.to_i,'abc_data')[2] )
85
- # 指定したクロックが挿入される
87
+ # rset method returns a inputed clock value
86
88
  assert_equal(4, @st.rset(0,'abc',0,4,Time.now.to_i,'new_data')[2] )
87
- # 古いクロックは拒否される
89
+ # but if input clock value is old then not store the data
88
90
  assert_nil( @st.rset(0,'abc',0,4,Time.now.to_i,'new_data') )
89
91
  assert_nil( @st.rset(0,'abc',0,3,Time.now.to_i,'new_data') )
90
92
  end
91
93
 
92
94
  def test_rdelete
93
- # 指定したクロックで削除マークされる
95
+ # save a clock value in the deletemark
94
96
  assert_equal(2, @st.rdelete(0,'abc',0,2)[2] )
95
- # 古いクロックの挿入は許されない
97
+ # reject a old clock value in rset method
96
98
  assert_nil( @st.rset(0,'abc',0,1,Time.now.to_i,'new_data'))
97
99
  assert_nil( @st.rset(0,'abc',0,2,Time.now.to_i,'new_data'))
98
- # 古いクロックの削除も拒否される
100
+ # also reject a old clock value in rdelete method
99
101
  assert_nil( @st.rdelete(0,'abc',0,1) )
100
102
  assert_nil( @st.rdelete(0,'abc',0,2) )
101
- # 新しいクロックの削除はマークされる
103
+ # but input the new clock to allow
102
104
  assert_equal( 3, @st.rdelete(0,'abc',0,3)[2] )
103
105
  end
104
106
 
@@ -108,7 +110,7 @@ class TCStorageTest < Test::Unit::TestCase
108
110
  assert( @st.out(0,'abc',0) )
109
111
  end
110
112
 
111
- # 論理クロックの境界をテスト
113
+ # on boundary of a clock
112
114
  def test_clock_count
113
115
  assert_equal( 0xfffffffe, @st.rset(0,'set',0,0xfffffffe,Time.now.to_i,'new_data')[2])
114
116
  assert_equal(0xffffffff, @st.set(0,'set',0,Time.now.to_i,'abc_data')[2])
@@ -135,9 +137,10 @@ class TCStorageTest < Test::Unit::TestCase
135
137
 
136
138
  def test_add
137
139
  assert_equal('abc_data',@st.add(0,'abc',0,Time.now.to_i+1,'abc_data')[4])
138
- assert_nil( @st.add(0,'abc',0,Time.now.to_i+1,'abc_data') ) # 上書きは失敗する
140
+ # deny a over write
141
+ assert_nil( @st.add(0,'abc',0,Time.now.to_i+1,'abc_data') )
139
142
  assert_equal( 'abc_data', @st.delete(0,'abc',0)[4])
140
- assert_equal('abc_data', @st.add(0,'abc',0,Time.now.to_i,'abc_data')[4]) # delete 後の add の成功を確認
143
+ assert_equal('abc_data', @st.add(0,'abc',0,Time.now.to_i,'abc_data')[4])
141
144
  end
142
145
 
143
146
  def test_replace
@@ -169,7 +172,7 @@ class TCStorageTest < Test::Unit::TestCase
169
172
  assert_equal('100', @st.incr(0,'abc',0,-6)[4]) # 106 + (-6) = 100
170
173
  assert_equal('0', @st.incr(0,'abc',0,-200)[4] ) # 100 + (-200) = 0
171
174
  assert_equal('0', @st.incr(0,'abc',0,-200)[4] ) # 0 + (-200) = 0
172
- # 最大値をセット
175
+ # set to max value
173
176
  assert_equal('18446744073709551615', @st.set(0,'abc',0,Time.now.to_i,
174
177
  '18446744073709551615')[4])
175
178
  assert_equal('1', @st.incr(0,'abc',0,2)[4] ) # max + 2 = 1
@@ -183,21 +186,20 @@ class TCStorageTest < Test::Unit::TestCase
183
186
  assert_equal('100', @st.decr(0,'abc',0,-6)[4] ) # 94 - (-6) = 100
184
187
  assert_equal('0', @st.decr(0,'abc',0,200)[4] ) # 100 - 200 = 0
185
188
  assert_equal('0', @st.decr(0,'abc',0,200)[4] ) # 0 - 200 = 0
186
- # 最大値をセット
189
+ # set to max value
187
190
  assert_equal('18446744073709551615', @st.set(0,'abc',0,Time.now.to_i,
188
191
  '18446744073709551615')[4])
189
192
  assert_equal('2', @st.decr(0,'abc',0,-3)[4]) # max - (-2) = 2
190
193
  end
191
194
 
192
195
  def test_dump
193
- assert_nil( @st.dump(0) ) # 最初は0件
196
+ assert_nil( @st.dump(0) )
194
197
  @st.set(0,'abc',0,0xffffffff,'abc_data')
195
198
  assert_equal(1, Marshal.load(@st.dump(0)).length )
196
199
  @st.set(0,'def',0,0xffffffff,'def_data')
197
200
  assert_equal(2, Marshal.load(@st.dump(0)).length )
198
- assert_nil( @st.dump(1) ) # 異なるvnodeは0件
201
+ assert_nil( @st.dump(1) ) # another vnode is empty
199
202
 
200
- # 10万件いれてみる
201
203
  n=@ndat
202
204
  n.times{|i|
203
205
  @st.set(2,i.to_s,0,0xffffffff,'abc_data')
@@ -205,7 +207,6 @@ class TCStorageTest < Test::Unit::TestCase
205
207
  assert_equal(n, Marshal.load(@st.dump(2)).length )
206
208
  end
207
209
 
208
- # 10万件程度
209
210
  def test_volume
210
211
  n=@ndat
211
212
  n.times{|i|
@@ -217,33 +218,10 @@ class TCStorageTest < Test::Unit::TestCase
217
218
  n.times{|i|
218
219
  assert_equal('abc_data', @st.delete(0,i.to_s,0)[4])
219
220
  }
220
- # 削除記録も含めた本当のレコード数
221
+ # true_length value is included in number of deletemark
221
222
  assert_equal(n, @st.true_length )
222
223
  end
223
224
 
224
- def test_clean_up
225
- @st.each_clean_up_sleep = 0
226
- n=@ndat
227
- n.times{|i|
228
- @st.set(0,i.to_s,0,0xffffffff,'abc_data')
229
- }
230
- # 指定時刻より以前 and 有効期限切れを削除
231
- # 全てのデータは現在よりも以前だが、有効期限内なので0件
232
- assert_equal(0, @st.clean_up(Time.now.to_i+100) )
233
- # 10件を削除(削除は有効期限を0する)
234
- 10.times{|i|
235
- assert_equal('abc_data', @st.delete(0,i.to_s,0)[4])
236
- }
237
- assert_nil( @st.get(0,'0',0) )
238
- assert_equal('abc_data', @st.get(0,'19',0) )
239
- # 削除時刻よりも以前を指定すると、0件
240
- assert_equal(0, @st.clean_up(Time.now.to_i-100) )
241
- # 削除時刻よりも進ませると、10件
242
- assert_equal(10, @st.clean_up(Time.now.to_i+100) )
243
- # 残は n-10
244
- assert_equal(n-10, Marshal.load(@st.dump(0)).length )
245
- end
246
-
247
225
  def test_each_clean_up
248
226
  n=10
249
227
 
@@ -256,21 +234,21 @@ class TCStorageTest < Test::Unit::TestCase
256
234
  }
257
235
  # ---------+------+---------------------
258
236
  # last < now+100
259
- # 全てのデータは現在よりも以前だが、有効期限内なので0件
237
+ # all data within a fixed time limit
260
238
  @st.each_clean_up_sleep = 0
261
239
  @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
262
240
  puts "k=#{k} vn=#{vn}"
263
241
  assert(false)
264
242
  }
265
243
 
266
- # vn=0 を10件削除
244
+ # delete data in vn=0
267
245
  n.times{|i| @st.delete(0,"key0-#{i}",0) }
268
- # 削除時刻よりも以前を指定すると、0件
246
+ # time is 100 second ago
269
247
  @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
270
248
  assert(false)
271
249
  }
272
250
 
273
- # 削除時刻よりも進ませると、10件
251
+ # time is 100 second later
274
252
  cnt=0
275
253
  @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
276
254
  assert_equal(0, vn)
@@ -279,17 +257,17 @@ class TCStorageTest < Test::Unit::TestCase
279
257
  }
280
258
  assert_equal(10,cnt )
281
259
 
282
- # vn=1 を10件削除
260
+ # delete data in vn=1
283
261
  n.times{|i| @st.delete(1,"key1-#{i}",0) }
284
- # vn=1 をセカンダリとする
262
+ # set to :secondary in vn=1
285
263
  vnhash[1]=:secondary
286
- # セカンダリは削除されないので、0件
264
+ # :secondary was not deleted
287
265
  @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
288
266
  assert(false)
289
267
  }
290
- # vn=1 をプライマリに戻す
268
+ # set to :primary in vn=1
291
269
  vnhash[1]=:primary
292
- # 10件になる
270
+ # in :primary data was deleted
293
271
  cnt=0
294
272
  @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
295
273
  assert_equal(1, vn)
@@ -298,18 +276,18 @@ class TCStorageTest < Test::Unit::TestCase
298
276
  }
299
277
  assert_equal(10,cnt)
300
278
 
301
- # 消すものが存在しないので、0件
279
+ # deletemark was empty
302
280
  @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
303
281
  assert(false)
304
282
  }
305
283
 
306
- # vn=2 を担当から外す
284
+ # vn=2 is not taken of charge
307
285
  vnhash.delete(2)
308
- # vn=2 のデータは存在する
286
+ # but still have a data in vn=2
309
287
  n.times{|i|
310
288
  assert_match(/val2-/,@st.get(2,"key2-#{i}",0) )
311
289
  }
312
- # vn=2 の10件が削除される
290
+ # data was deleted in vn=2
313
291
  cnt=0
314
292
  @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
315
293
  assert_equal(2, vn)
@@ -317,16 +295,16 @@ class TCStorageTest < Test::Unit::TestCase
317
295
  cnt += 1
318
296
  }
319
297
  assert_equal(10,cnt)
320
- # vn=2 のデータは消えているはず
298
+ # confirm it in vn=2
321
299
  n.times{|i|
322
300
  assert_nil( @st.get(2,"key2-#{i}",0) )
323
301
  }
324
302
 
325
- # vn=3 有効期限を 100秒前にする
303
+ # time is 100 second ago in vn=3
326
304
  n.times{|i|
327
305
  @st.set(3,"key3-#{i}",0,Time.now.to_i-100,"val3-#{i}")
328
306
  }
329
- # 期限切れは last に関係なく削除されるので、10件
307
+ # 10 kyes deleted
330
308
  cnt=0
331
309
  @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
332
310
  assert_equal(3, vn)
@@ -336,11 +314,10 @@ class TCStorageTest < Test::Unit::TestCase
336
314
  assert_equal(10,cnt)
337
315
  end
338
316
 
339
- # 途中で止めるテスト
340
317
  def test_each_clean_up2
341
318
  n=10
342
319
 
343
- # テストデータを100件登録する
320
+ # set and delete is repeated 100 times
344
321
  vnhash={}
345
322
  n.times{|i|
346
323
  n.times{|j|
@@ -350,7 +327,7 @@ class TCStorageTest < Test::Unit::TestCase
350
327
  vnhash[i]=:primary
351
328
  }
352
329
 
353
- # 10msec wait each する
330
+ # each waite is 10 msec
354
331
  cnt = 0
355
332
  th = Thread.new{
356
333
  @st.each_clean_up_sleep = 0.01
@@ -358,60 +335,66 @@ class TCStorageTest < Test::Unit::TestCase
358
335
  cnt += 1
359
336
  }
360
337
  }
361
- # 500msec 後に停止を指示
338
+ # in 500msec later will stop
362
339
  sleep 0.5
363
340
  @st.stop_clean_up
364
341
  th.join
365
- # 途中で停止したので cnt 100未満
342
+ # should cnt is less than 100
366
343
  assert_operator(100, :>, cnt)
367
- # 残りを削除
344
+ # delete a remain keys
368
345
  @st.each_clean_up_sleep = 0
369
346
  @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
370
347
  cnt += 1
371
348
  }
372
- # 全件消えるので cnt 100
349
+ # after all cnt is 100
373
350
  assert_equal(100, cnt)
374
351
  end
375
352
 
376
353
  def test_dump_and_load
377
354
  n=10
378
355
  n.times{|i|
356
+ # clock = 0
379
357
  @st.set(0,i.to_s,0,0xffffffff,'abc_data')
380
-
381
358
  }
382
- assert_equal(0, @st.load(@st.dump(0)) ) # 同じ論理クロックはコピー件数 0 件
359
+ # not loaded
360
+ assert_equal(0, @st.load(@st.dump(0)) )
383
361
 
384
- # 進んだ論理クロックのデータを n 件作成
385
362
  h={}
386
363
  n.times{|i|
364
+ # clock = 1
387
365
  h[i.to_s]=[0,Time.now.to_i,1,0xffffffff].pack('NNNN')+'new data'
388
366
  }
389
367
  dmp=Marshal.dump(h)
390
368
 
391
- assert_equal(n, @st.load(dmp) ) # 進んだ論理クロックの n 件のみコピーされる
369
+ # loaded
370
+ assert_equal(n, @st.load(dmp) )
392
371
  assert_equal('new data', @st.get(0,'0',0))
393
372
  end
394
373
 
395
374
  def test_dump_and_load2
396
375
  n=10
376
+ # create a deletemark
397
377
  n.times{|i|
398
- assert_nil( @st.delete(0,i.to_s,0)[4] ) # データが存在しなくても削除記録を残す
378
+ assert_nil( @st.delete(0,i.to_s,0)[4] )
399
379
  }
380
+ # dump a deletemark
400
381
  dmp=@st.dump(0)
401
- assert_equal(n, Marshal.load(dmp).length ) # 削除記録もダンプされる
402
- assert_equal(0, @st.load(@st.dump(0)) ) # 同じデータの場合はコピー件数 0 件
382
+ assert_equal(n, Marshal.load(dmp).length )
383
+ # not loaded, it's same data
384
+ assert_equal(0, @st.load(@st.dump(0)) )
403
385
 
404
- # 遅れた論理クロックのデータを作成
386
+ # create a old clock data
405
387
  h={}
406
388
  n.times{|i|
407
389
  h[i.to_s]=[0,Time.now.to_i,0xffffffff,0xffffffff].pack('NNNN')+'old data'
408
390
  }
409
391
  dmp=Marshal.dump(h)
410
- assert_equal(0, @st.load(dmp) ) # 進んだ論理クロックの削除記録があるのでデータは上書きされない
392
+ # not loaded
393
+ assert_equal(0, @st.load(dmp) )
411
394
  assert_nil( @st.get(0,'0',0) )
412
395
  end
413
396
 
414
- # closedb 後のアクセスは NoMethodError が発生することを確認する
397
+ # access after close
415
398
  def test_close
416
399
  @st.closedb
417
400
 
@@ -437,31 +420,19 @@ class TCStorageTest < Test::Unit::TestCase
437
420
  @st.load(dmp)
438
421
  end
439
422
 
440
- # この場合は 0 件
441
- assert_equal(0,@st.clean_up(Time.now.to_i+100) )
423
+ end
442
424
 
443
- # clean_up 中に closedb をするテスト
444
- #
445
- # わざわざユニットテストを行う理由 => レアケースなだけにバグも発見しにくい。
446
- #
447
- # バッチによる clean_up 処理中に deletehash を行ったときこの状態になる。
448
- # NoMethodError を判定した retry を保証するためテストを行う。
449
- #
450
- @st.opendb
425
+ def test_close_after_each_clean_up
451
426
  h={}
452
- 10.times{|i|
453
- h[i.to_s]=[0,Time.now.to_i,0,Time.now.to_i].pack('NNNN')+'old data'
427
+ 100.times{|i|
428
+ h[i.to_s]=[i%10,Time.now.to_i,0,Time.now.to_i].pack('NNNN')+'old data'
454
429
  }
455
430
  dmp=Marshal.dump(h)
456
431
  @st.load(dmp)
457
432
 
458
- # clean_up 中に closedb されると NoMethodError が発生する
459
- assert_raise NoMethodError do
460
- @st.clean_up(Time.now.to_i-10,true)
461
- end
462
-
463
- # 次のテストのために再度 open
464
- @st.opendb
433
+ @st.each_clean_up(Time.now.to_i-100, Hash.new(:primary) ){|k,vn|
434
+ @st.closedb
435
+ }
465
436
  end
466
437
 
467
438
  def test_dump_file
@@ -550,19 +521,31 @@ class DbmStorageTest < TCStorageTest
550
521
  def setup
551
522
  rmtestdir('storage_test')
552
523
  @st=Roma::Storage::DbmStorage.new
553
- @st.vn_list = [0]
524
+ @st.vn_list = [0,1,2,3,4,5,6,7,8,9]
554
525
  @st.storage_path = 'storage_test'
555
526
  @st.opendb
556
527
  end
557
528
 
558
- #undef test_each_clean_up
559
- #undef test_each_clean_up2
529
+ def test_close_after_each_clean_up
530
+ h={}
531
+ 1000.times{|i|
532
+ h[i.to_s]=[i%10,Time.now.to_i,0,Time.now.to_i].pack('NNNN')+'old data'
533
+ }
534
+ dmp=Marshal.dump(h)
535
+ @st.load(dmp)
536
+
537
+ assert_raise RuntimeError do
538
+ @st.each_clean_up(Time.now.to_i-100, Hash.new(:primary) ){|k,vn|
539
+ @st.closedb
540
+ }
541
+ end
542
+ end
560
543
  end
561
544
 
562
545
  class RubyHashStorageTest < TCStorageTest
563
546
  def setup
564
547
  @st=Roma::Storage::RubyHashStorage.new
565
- @st.vn_list = [0]
548
+ @st.vn_list = [0,1,2,3,4,5,6,7,8,9]
566
549
  @st.opendb
567
550
  end
568
551
 
@@ -625,19 +608,32 @@ class SQLite3StorageTest < TCStorageTest
625
608
  def setup
626
609
  rmtestdir('storage_test')
627
610
  @st=Roma::Storage::SQLite3Storage.new
628
- @st.vn_list = [0]
611
+ @st.vn_list = [0,1,2,3,4,5,6,7,8,9]
629
612
  @st.storage_path = 'storage_test'
630
613
  @st.opendb
631
614
  end
632
615
 
633
- #undef test_out
616
+ def test_close_after_each_clean_up
617
+ h={}
618
+ 1000.times{|i|
619
+ h[i.to_s]=[i%10,Time.now.to_i,0,Time.now.to_i].pack('NNNN')+'old data'
620
+ }
621
+ dmp=Marshal.dump(h)
622
+ @st.load(dmp)
623
+
624
+ assert_raise SQLite3::BusyException do
625
+ @st.each_clean_up(Time.now.to_i-100, Hash.new(:primary) ){|k,vn|
626
+ @st.closedb
627
+ }
628
+ end
629
+ end
634
630
  end
635
631
 
636
632
  class TCMemStorageTest < TCStorageTest
637
633
  def setup
638
634
  rmtestdir('storage_test')
639
635
  @st=Roma::Storage::TCMemStorage.new
640
- @st.vn_list = [0]
636
+ @st.vn_list = [0,1,2,3,4,5,6,7,8,9]
641
637
  @st.storage_path = 'storage_test'
642
638
  @st.opendb
643
639
  end