roma 1.2.0 → 1.3.0

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +44 -1
  3. data/Gemfile.lock +18 -15
  4. data/README.md +15 -1
  5. data/bin/consistency_test +10 -0
  6. data/bin/data_accumulation +11 -0
  7. data/lib/roma/async_process.rb +39 -2
  8. data/lib/roma/command/sys_command_receiver.rb +80 -0
  9. data/lib/roma/command/vn_command_receiver.rb +1 -1
  10. data/lib/roma/config.rb +1 -1
  11. data/lib/roma/plugin/plugin_storage.rb +105 -1
  12. data/lib/roma/romad.rb +13 -1
  13. data/lib/roma/routing/cb_rttable.rb +1 -1
  14. data/lib/roma/tools/consistency_test.rb +77 -0
  15. data/lib/roma/tools/data_accumulation.rb +64 -0
  16. data/lib/roma/version.rb +1 -1
  17. data/lib/roma/write_behind.rb +138 -1
  18. data/test/config4mhash.rb +1 -1
  19. data/test/config4storage_error.rb +1 -1
  20. data/test/config4test.rb +1 -1
  21. data/test/cpdbtest/config4cpdb_base.rb +1 -1
  22. data/test/optional_test/t_mkroute_rich.rb +44 -0
  23. data/test/optional_test/t_other_cpdb.rb +45 -0
  24. data/test/optional_test/t_other_database.rb +59 -0
  25. data/test/{t_routing_logic.rb → optional_test/t_routing_logic.rb} +1 -0
  26. data/test/roma-test-storage.rb +685 -0
  27. data/test/roma-test-utils.rb +24 -0
  28. data/test/run-test.rb +9 -0
  29. data/test/t_command_definition.rb +2 -0
  30. data/test/t_cpdata.rb +1 -0
  31. data/test/t_cpdb.rb +22 -34
  32. data/test/t_eventmachine.rb +1 -0
  33. data/test/t_listplugin.rb +2 -0
  34. data/test/t_logshift.rb +2 -4
  35. data/test/t_mapcountplugin.rb +48 -37
  36. data/test/t_mapplugin.rb +2 -0
  37. data/test/t_mhash.rb +2 -1
  38. data/test/t_new_func.rb +386 -0
  39. data/test/t_protocol.rb +66 -1
  40. data/test/t_rclient.rb +2 -0
  41. data/test/t_replication.rb +299 -0
  42. data/test/t_routing_data.rb +6 -5
  43. data/test/t_storage.rb +5 -740
  44. data/test/t_storage_error.rb +1 -0
  45. data/test/t_writebehind.rb +11 -2
  46. metadata +31 -19
@@ -181,10 +181,12 @@ module RClientTests
181
181
  end
182
182
 
183
183
  class RClientTest < Test::Unit::TestCase
184
+ self.test_order = :defined
184
185
  include RClientTests
185
186
  end
186
187
 
187
188
  class RClientTestForceForward < Test::Unit::TestCase
189
+ self.test_order = :defined
188
190
  include RClientTests
189
191
 
190
192
  def setup
@@ -0,0 +1,299 @@
1
+ #!/usr/bin/env ruby
2
+ require 'logger'
3
+ require 'roma/write_behind'
4
+ require 'roma/client/rclient'
5
+ require 'roma/messaging/con_pool'
6
+
7
+ module StreamWriterTests
8
+ def setup
9
+ start_roma
10
+ @rc = Roma::Client::RomaClient.new(%w(localhost_11211 localhost_11212))
11
+
12
+ start_roma_replica
13
+ @rc_replica = Roma::Client::RomaClient.new(%w(localhost_21211 localhost_21212))
14
+ end
15
+
16
+ def teardown
17
+ stop_roma
18
+ stop_roma_replica
19
+ Roma::Messaging::ConPool.instance.close_all
20
+ rescue => e
21
+ puts "#{e} #{$ERROR_POSITION}"
22
+ end
23
+
24
+ def send_cmd(host, cmd)
25
+ con = Roma::Messaging::ConPool.instance.get_connection(host)
26
+ con.write("#{cmd}\r\n")
27
+ ret = con.gets
28
+ con.close
29
+ ret
30
+ end
31
+ end # end of StreamWriterTests module
32
+
33
+
34
+ class StreamWriterTest < Test::Unit::TestCase
35
+ self.test_order = :defined
36
+ include StreamWriterTests
37
+ include RomaTestUtils
38
+
39
+ def test_sw_get_routing_data
40
+ sw = Roma::WriteBehind::StreamWriter.new(Logger.new(nil))
41
+
42
+ sw.update_mklhash('localhost_21211')
43
+ pre_mklhash = sw.replica_mklhash
44
+ assert_match(/[\d\w]{40}/, pre_mklhash)
45
+
46
+ sw.update_nodelist('localhost_21211')
47
+ pre_nodelist = sw.replica_nodelist
48
+ assert_equal(['localhost_21211', 'localhost_21212'], pre_nodelist)
49
+
50
+ sw.update_rttable('localhost_21211')
51
+ pre_rttable = sw.replica_rttable
52
+ assert_kind_of(Roma::Routing::RoutingData, pre_rttable)
53
+ end
54
+
55
+ def test_sw_change_mkl_hash?
56
+ sw = Roma::WriteBehind::StreamWriter.new(Logger.new(nil))
57
+ sw.replica_mklhash = 'dummy'
58
+ assert_equal(true, sw.change_mklhash?)
59
+ end
60
+
61
+
62
+ end # end of StreamWriterTest class
63
+
64
+ class ClusterReplicationTest < Test::Unit::TestCase
65
+ self.test_order = :defined
66
+ include StreamWriterTests
67
+ include RomaTestUtils
68
+
69
+ def test_rc_status
70
+ ret = send_cmd('localhost_11211', 'stat run_replication')
71
+ assert_equal("write-behind.run_replication false\r\n", ret)
72
+
73
+ ret = send_cmd('localhost_11211', 'stat replica_mklhash')
74
+ assert_equal("write-behind.replica_mklhash \r\n", ret)
75
+
76
+ ret = send_cmd('localhost_11211', 'stat replica_nodelist')
77
+ assert_equal("write-behind.replica_nodelist []\r\n", ret)
78
+ end
79
+
80
+ def test_rc_switch_replication_default
81
+ # default activate
82
+ ret = send_cmd('localhost_11211', 'switch_replication true localhost_21211')
83
+ assert_equal("{\"localhost_11212\"=>\"ACTIVATED\", \"localhost_11211\"=>\"ACTIVATED\"}\r\n", ret)
84
+ # run_replication status
85
+ ret = send_cmd('localhost_11211', 'stat run_replication')
86
+ assert_equal("write-behind.run_replication true\r\n", ret)
87
+ # replica_mklhash
88
+ pre_mklhash = send_cmd('localhost_11211', 'stat replica_mklhash')
89
+ assert_match(/write-behind\.replica_mklhash [\d\w]{40}\r\n/, pre_mklhash)
90
+ # replica_nodelist
91
+ pre_mklhash = send_cmd('localhost_11211', 'stat replica_mklhash')
92
+ ret = send_cmd('localhost_11211', 'stat replica_nodelist')
93
+ assert_equal("write-behind.replica_nodelist [\"localhost_21211\", \"localhost_21212\"]\r\n", ret)
94
+
95
+ # default deactivate
96
+ ret = send_cmd('localhost_11211', 'switch_replication false')
97
+ assert_equal("{\"localhost_11212\"=>\"DEACTIVATED\", \"localhost_11211\"=>\"DEACTIVATED\"}\r\n", ret)
98
+ # run_replication status
99
+ ret = send_cmd('localhost_11211', 'stat run_replication')
100
+ assert_equal("write-behind.run_replication false\r\n", ret)
101
+ # replica_mklhash
102
+ post_mklhash = send_cmd('localhost_11211', 'stat replica_mklhash')
103
+ assert_match("write-behind\.replica_mklhash \r\n", post_mklhash)
104
+ assert_not_equal(pre_mklhash, post_mklhash)
105
+ # replica_nodelist
106
+ ret = send_cmd('localhost_11211', 'stat replica_nodelist')
107
+ assert_equal("write-behind.replica_nodelist []\r\n", ret)
108
+
109
+ # activate with all data option
110
+ ret = send_cmd('localhost_11211', 'switch_replication true localhost_21211 all')
111
+ assert_equal("{\"localhost_11212\"=>\"ACTIVATED\", \"localhost_11211\"=>\"ACTIVATED\"}\r\n", ret)
112
+ # run_existing_data_replication status
113
+ ret = send_cmd('localhost_11211', 'stat run_existing_data_replication')
114
+ assert_equal("write-behind.run_existing_data_replication true\r\n", ret)
115
+
116
+ sleep 1 # wait finish existing data copy
117
+ # run_existing_data_replication status
118
+ ret = send_cmd('localhost_11211', 'stat run_existing_data_replication')
119
+ assert_equal("write-behind.run_existing_data_replication false\r\n", ret)
120
+ # run_replication status
121
+ ret = send_cmd('localhost_11211', 'stat run_replication')
122
+ assert_equal("write-behind.run_replication true\r\n", ret)
123
+ # replica_mklhash
124
+ pre_mklhash = send_cmd('localhost_11211', 'stat replica_mklhash')
125
+ assert_match(/write-behind\.replica_mklhash [\d\w]{40}\r\n/, pre_mklhash)
126
+ # replica_nodelist
127
+ pre_mklhash = send_cmd('localhost_11211', 'stat replica_mklhash')
128
+ ret = send_cmd('localhost_11211', 'stat replica_nodelist')
129
+ assert_equal("write-behind.replica_nodelist [\"localhost_21211\", \"localhost_21212\"]\r\n", ret)
130
+ end
131
+
132
+ def test_rc_switch_replication_error
133
+ ret = send_cmd('localhost_11211', 'switch_replication true localhost_21211 hoge fuga')
134
+ assert_equal("CLIENT_ERROR number of arguments\r\n", ret)
135
+
136
+ ret = send_cmd('localhost_11211', 'switch_replication true localhost_21211 false')
137
+ assert_equal("CLIENT_ERROR [copy target] must be all or nil\r\n", ret)
138
+
139
+ ret = send_cmd('localhost_11211', 'stat run_replication')
140
+ assert_equal("write-behind.run_replication false\r\n", ret)
141
+
142
+ ret = send_cmd('localhost_11211', 'switch_replication on localhost_21211')
143
+ assert_equal("CLIENT_ERROR value must be true or false\r\n", ret)
144
+
145
+ ret = send_cmd('localhost_11211', 'stat run_replication')
146
+ assert_equal("write-behind.run_replication false\r\n", ret)
147
+ end
148
+
149
+ def test_rc_store_cmd # get/set/add/replace/append/prepend
150
+ send_cmd('localhost_11211', 'switch_replication true localhost_21211')
151
+
152
+ # set/get
153
+ @rc.set('key1', 'val1')
154
+ sleep 0.1
155
+ assert_equal('val1', @rc_replica.get('key1'))
156
+
157
+ # add
158
+ @rc.add('key2', 'val2')
159
+ sleep 0.1
160
+ assert_equal('val2', @rc_replica.get('key2'))
161
+ @rc.add("key2", "val3")
162
+ sleep 0.1
163
+ assert_equal('val2', @rc_replica.get('key2'))
164
+
165
+ # replace
166
+ @rc.set('key3', 'val3')
167
+ sleep 0.1
168
+ @rc.replace('key3', 'val4')
169
+ sleep 0.1
170
+ assert_equal('val4', @rc_replica.get('key3'))
171
+ @rc.replace('key4', 'val4')
172
+ sleep 0.1
173
+ assert_nil( @rc_replica.get('key4'))
174
+
175
+ # append
176
+ @rc.set('key5','value5', 0, true)
177
+ sleep 0.1
178
+ assert_equal('value5', @rc_replica.get('key5', true))
179
+ @rc.append("key5","_end")
180
+ sleep 0.1
181
+ assert_equal("value5_end", @rc_replica.get('key5',true))
182
+
183
+ # prepend
184
+ @rc.set('key6','value6', 0, true)
185
+ sleep 0.1
186
+ assert_equal('value6', @rc_replica.get('key6', true))
187
+ @rc.prepend("key6","start_")
188
+ sleep 0.1
189
+ assert_equal("start_value6", @rc_replica.get('key6',true))
190
+ end
191
+
192
+ def test_rc_other_store_cmd # delete/incr/decr/set_expt/cas
193
+ send_cmd('localhost_11211', 'switch_replication true localhost_21211')
194
+
195
+ # delete
196
+ @rc.set('key1', 'val1')
197
+ sleep 0.1
198
+ assert_equal('val1', @rc_replica.get('key1'))
199
+ @rc.delete('key1')
200
+ sleep 0.1
201
+ assert_nil(@rc_replica.get('key1'))
202
+
203
+ # incr
204
+ @rc.set('key2','100',0,true)
205
+ sleep 0.1
206
+ assert_equal('100', @rc_replica.get('key2', true))
207
+ @rc.incr('key2')
208
+ sleep 0.1
209
+ assert_equal('101', @rc_replica.get('key2', true))
210
+ @rc.incr('key2', 10)
211
+ sleep 0.1
212
+ assert_equal('111', @rc_replica.get('key2', true))
213
+
214
+ # decr
215
+ @rc.set('key3','100', 0, true)
216
+ sleep 0.1
217
+ assert_equal('100', @rc_replica.get('key3', true))
218
+
219
+ @rc.decr('key3')
220
+ sleep 0.1
221
+ assert_equal('99', @rc_replica.get('key3', true))
222
+
223
+ @rc.decr('key3', 10)
224
+ sleep 0.1
225
+ assert_equal('89', @rc_replica.get('key3', true))
226
+
227
+ # expt
228
+ @rc.set('key4', 'val4', 1)
229
+ sleep 0.1
230
+ assert_equal('val4', @rc_replica.get('key4'))
231
+ sleep 2
232
+ assert_nil( @rc_replica.get('key4') )
233
+
234
+ # set_expt
235
+ @rc.set('key5', 'val5')
236
+ sleep 0.1
237
+ assert_equal('val5', @rc_replica.get('key5'))
238
+ send_cmd('localhost_11211', 'set_expt key5 1')
239
+ sleep 5
240
+ assert_nil( @rc_replica.get('key5') )
241
+
242
+ # cas
243
+ @rc.set("cnt", 1)
244
+ res = @rc.cas("cnt"){|v|
245
+ assert_equal(1, v)
246
+ v += 1
247
+ }
248
+ sleep 0.1
249
+ assert_equal(2, @rc_replica.get("cnt"))
250
+
251
+ res = @rc.cas("cnt"){|v|
252
+ res2 = @rc.cas("cnt"){|v2|
253
+ v += 2
254
+ }
255
+ assert_equal("STORED", res2)
256
+ v += 1
257
+ }
258
+ assert_equal("EXISTS", res)
259
+ assert_equal(4, @rc_replica.get("cnt"))
260
+ end
261
+
262
+ def test_rc_background_copy_activate
263
+ @rc.set('key1', 'val1')
264
+ @rc.set('key2', 'val2')
265
+ @rc.set('key3', 'val3')
266
+
267
+ send_cmd('localhost_11211', 'switch_replication true localhost_21211 all')
268
+ sleep 1
269
+
270
+ assert_equal('val1', @rc_replica.get('key1'))
271
+ assert_equal('val2', @rc_replica.get('key2'))
272
+ assert_equal('val3', @rc_replica.get('key3'))
273
+ end
274
+
275
+ def test_rc_background_copy_unactivate
276
+ @rc.set('key1', 'val1')
277
+ @rc.set('key2', 'val2')
278
+ @rc.set('key3', 'val3')
279
+
280
+ send_cmd('localhost_11211', 'switch_replication true localhost_21211')
281
+ sleep 1
282
+
283
+ assert_nil(@rc_replica.get('key1'))
284
+ assert_nil(@rc_replica.get('key2'))
285
+ assert_nil(@rc_replica.get('key3'))
286
+ end
287
+
288
+ def test_rc_background_copy_not_overwrite
289
+ @rc.set('key1', 'val1') #clk = 0
290
+ @rc_replica.set('key1', 'replica1')
291
+ @rc_replica.set('key1', 'replica1') # clk = 1
292
+
293
+ send_cmd('localhost_11211', 'switch_replication true localhost_21211 all')
294
+ sleep 1
295
+
296
+ assert_equal('replica1', @rc_replica.get('key1'))
297
+ end
298
+
299
+ end # end of ClusterReplicationTest class
@@ -4,6 +4,7 @@ require 'roma/routing/routing_data'
4
4
  require 'yaml'
5
5
 
6
6
  class RoutingDataTest < Test::Unit::TestCase
7
+ self.test_order = :defined
7
8
  def setup
8
9
  end
9
10
 
@@ -77,16 +78,16 @@ class RoutingDataTest < Test::Unit::TestCase
77
78
  assert( rd.rn==1 )
78
79
 
79
80
  # digest bit count 32
80
- # vn bit count 16
81
+ # vn bit count 9
81
82
  # redundancy 2
82
83
  # array of node ID ['roma0_3300','roma1_3300','roma2_3300']
83
- rd=Roma::Routing::RoutingData.create(32,16,2,['roma0_3300','roma1_3300','roma2_3300'])
84
+ rd=Roma::Routing::RoutingData.create(32,9,2,['roma0_3300','roma1_3300','roma2_3300'])
84
85
 
85
- assert( rd.v_idx.length==65536 )
86
+ assert( rd.v_idx.length==512 )
86
87
  assert( rd.nodes.length==3 )
87
- assert( rd.search_mask==0xffff0000 )
88
+ assert( rd.search_mask==4286578688 )
88
89
  assert( rd.dgst_bits==32 )
89
- assert( rd.div_bits==16 )
90
+ assert( rd.div_bits==9 )
90
91
  assert( rd.rn==2 )
91
92
 
92
93
  c0=c1=c2=0
@@ -1,723 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require_relative './roma-test-storage'
3
4
  require 'roma/storage/tc_storage'
4
- require 'roma/storage/dbm_storage'
5
5
  require 'roma/storage/rh_storage'
6
- require 'roma/storage/sqlite3_storage'
7
6
  require 'roma/storage/groonga_storage'
8
7
 
9
- module StorageTests
10
- def ndat
11
- 1000
12
- end
13
-
14
- def rmtestdir(dirname)
15
- if File::directory?(dirname)
16
- File.delete(*Dir["#{dirname}/*"])
17
- Dir.rmdir(dirname)
18
- end
19
- end
20
-
21
- def test_set_get
22
- assert_equal( 'abc_data',@st.set(0,'abc',0,0xffffffff,'abc_data')[4])
23
- assert_equal( 'abc_data', @st.get(0,'abc',0) )
24
- end
25
-
26
- def test_set_delete
27
- @st.set(0,'abc',0,0xffffffff,'abc_data')
28
- # delete method returns a value
29
- assert_equal( 'abc_data', @st.delete(0,'abc',0)[4])
30
- assert_nil( @st.get(0,'abc',0) )
31
- # delete method returns :deletemark with deleted key
32
- assert_equal(:deletemark, @st.delete(0,'abc',0))
33
- end
34
-
35
- def test_set_exptime
36
- @st.set(0,'abc',0,Time.now.to_i,'abc_data')
37
- # returns a value within a fixed time limit
38
- assert_equal('abc_data', @st.get(0,'abc',0) )
39
- # expire time is a second ago
40
- @st.set(0,'abc',0,Time.now.to_i-1,'abc_data')
41
- # returns a nil when expired
42
- assert_nil( @st.get(0,'abc',0))
43
- end
44
-
45
- def test_set_get_raw
46
- n = 100
47
- n.times{|i|
48
- assert_equal('abc_data',@st.set(0,'abc',0,0xffffffff,'abc_data')[4])
49
- vn, t, clk, expt, val = @st.get_raw(0,'abc',0)
50
- assert_equal(vn,0)
51
- assert(Time.now.to_i - t <= 1)
52
- assert_equal(clk,i)
53
- assert_equal(expt,0xffffffff)
54
- assert_equal(val,'abc_data')
55
- }
56
- end
57
-
58
- def test_exp_delete
59
- assert_nil( @st.delete(0,'abc',0)[4])
60
- # expire time is a second ago
61
- assert_equal('abc_data' , @st.set(0,'abc',0,Time.now.to_i-1,'abc_data')[4])
62
- # delete method returns a nil in expired
63
- assert_nil( @st.delete(0,'abc',0)[4])
64
- end
65
-
66
- def test_rset
67
- # increase a logical clock
68
- assert_equal(0, @st.set(0,'abc',0,Time.now.to_i,'abc_data')[2] )
69
- assert_equal(1, @st.set(0,'abc',0,Time.now.to_i,'abc_data')[2] )
70
- assert_equal(2, @st.set(0,'abc',0,Time.now.to_i,'abc_data')[2] )
71
- # rset method returns a inputed clock value
72
- assert_equal(4, @st.rset(0,'abc',0,4,Time.now.to_i,'new_data')[2] )
73
- # but if input clock value is old then not store the data
74
- assert_nil( @st.rset(0,'abc',0,4,Time.now.to_i,'new_data') )
75
- assert_nil( @st.rset(0,'abc',0,3,Time.now.to_i,'new_data') )
76
- end
77
-
78
- def test_rdelete
79
- # save a clock value in the deletemark
80
- assert_equal(2, @st.rdelete(0,'abc',0,2)[2] )
81
- # reject a old clock value in rset method
82
- assert_nil( @st.rset(0,'abc',0,1,Time.now.to_i,'new_data'))
83
- assert_nil( @st.rset(0,'abc',0,2,Time.now.to_i,'new_data'))
84
- # also reject a old clock value in rdelete method
85
- assert_nil( @st.rdelete(0,'abc',0,1) )
86
- assert_nil( @st.rdelete(0,'abc',0,2) )
87
- # but input the new clock to allow
88
- assert_equal( 3, @st.rdelete(0,'abc',0,3)[2] )
89
- end
90
-
91
- def test_out
92
- assert( !@st.out(0,'abc',0) )
93
- @st.set(0,'abc',0,Time.now.to_i,'abc_data')
94
- assert( @st.out(0,'abc',0) )
95
- end
96
-
97
- # on boundary of a clock
98
- def test_clock_count
99
- assert_equal( 0xfffffffe, @st.rset(0,'set',0,0xfffffffe,Time.now.to_i,'new_data')[2])
100
- assert_equal(0xffffffff, @st.set(0,'set',0,Time.now.to_i,'abc_data')[2])
101
- assert_equal(0, @st.set(0,'set',0,Time.now.to_i,'abc_data')[2] )
102
-
103
- assert_equal(0xffffffff,@st.rdelete(0,'add',0,0xffffffff)[2])
104
- assert_equal(0, @st.add(0,'add',0,Time.now.to_i,'abc_data')[2] )
105
-
106
- assert_equal(0xffffffff, @st.rset(0,'replace',0,0xffffffff,Time.now.to_i,'abc_data')[2])
107
- assert_equal(0, @st.replace(0,'replace',0,Time.now.to_i,'abc_data')[2] )
108
-
109
- assert_equal(0xffffffff, @st.rset(0,'append',0,0xffffffff,Time.now.to_i,'abc_data')[2])
110
- assert_equal(0, @st.append(0,'append',0,Time.now.to_i,'abc_data')[2] )
111
-
112
- assert_equal(0xffffffff, @st.rset(0,'prepend',0,0xffffffff,Time.now.to_i,'abc_data')[2])
113
- assert_equal(0, @st.prepend(0,'prepend',0,Time.now.to_i,'abc_data')[2] )
114
-
115
- assert_equal(0xffffffff, @st.rset(0,'incr',0,0xffffffff,Time.now.to_i,'10')[2])
116
- assert_equal(0, @st.incr(0,'incr',0,10)[2] )
117
-
118
- assert_equal(0xffffffff, @st.rset(0,'decr',0,0xffffffff,Time.now.to_i,'10')[2])
119
- assert_equal(0, @st.decr(0,'decr',0,10)[2] )
120
- end
121
-
122
- def test_add
123
- assert_equal('abc_data',@st.add(0,'abc',0,Time.now.to_i+1,'abc_data')[4])
124
- # deny a over write
125
- assert_nil( @st.add(0,'abc',0,Time.now.to_i+1,'abc_data') )
126
- assert_equal( 'abc_data', @st.delete(0,'abc',0)[4])
127
- assert_equal('abc_data', @st.add(0,'abc',0,Time.now.to_i,'abc_data')[4])
128
- end
129
-
130
- def test_replace
131
- assert_nil( @st.replace(0,'abc',0,Time.now.to_i,'abc_data') )
132
- assert_equal('abc_data', @st.add(0,'abc',0,Time.now.to_i,'abc_data')[4])
133
- assert_equal('new_data', @st.replace(0,'abc',0,Time.now.to_i,'new_data')[4] )
134
-
135
- end
136
-
137
- def test_append
138
- assert_nil( @st.append(0,'abc',0,Time.now.to_i,'abc_data') )
139
- assert_equal('abc_data', @st.set(0,'abc',0,Time.now.to_i,'abc_data')[4])
140
- assert_equal( 'abc_data123',@st.append(0,'abc',0,Time.now.to_i,'123')[4] )
141
- assert_equal('abc_data123', @st.get(0,'abc',0) )
142
- end
143
-
144
- def test_prepend
145
- assert_nil( @st.prepend(0,'abc',0,Time.now.to_i,'abc_data') )
146
- assert_equal('abc_data', @st.set(0,'abc',0,Time.now.to_i,'abc_data')[4])
147
- assert_equal('123abc_data', @st.prepend(0,'abc',0,Time.now.to_i,'123')[4])
148
- assert_equal('123abc_data', @st.get(0,'abc',0))
149
- end
150
-
151
- def test_incr
152
- assert_nil( @st.incr(0,'abc',0,1) )
153
- assert_equal('100', @st.set(0,'abc',0,Time.now.to_i,'100')[4] )
154
- assert_equal('101', @st.incr(0,'abc',0,1)[4])
155
- assert_equal('106', @st.incr(0,'abc',0,5)[4])
156
- assert_equal('100', @st.incr(0,'abc',0,-6)[4]) # 106 + (-6) = 100
157
- assert_equal('0', @st.incr(0,'abc',0,-200)[4] ) # 100 + (-200) = 0
158
- assert_equal('0', @st.incr(0,'abc',0,-200)[4] ) # 0 + (-200) = 0
159
- # set to max value
160
- assert_equal('18446744073709551615', @st.set(0,'abc',0,Time.now.to_i,
161
- '18446744073709551615')[4])
162
- assert_equal('1', @st.incr(0,'abc',0,2)[4] ) # max + 2 = 1
163
- end
164
-
165
- def test_decr
166
- assert_nil( @st.decr(0,'abc',0,1) )
167
- assert_equal('100', @st.set(0,'abc',0,Time.now.to_i,'100')[4] )
168
- assert_equal('99', @st.decr(0,'abc',0,1)[4])
169
- assert_equal('94', @st.decr(0,'abc',0,5)[4])
170
- assert_equal('100', @st.decr(0,'abc',0,-6)[4] ) # 94 - (-6) = 100
171
- assert_equal('0', @st.decr(0,'abc',0,200)[4] ) # 100 - 200 = 0
172
- assert_equal('0', @st.decr(0,'abc',0,200)[4] ) # 0 - 200 = 0
173
- # set to max value
174
- assert_equal('18446744073709551615', @st.set(0,'abc',0,Time.now.to_i,
175
- '18446744073709551615')[4])
176
- assert_equal('2', @st.decr(0,'abc',0,-3)[4]) # max - (-2) = 2
177
- end
178
-
179
- def test_dump
180
- assert_nil( @st.dump(0) )
181
- @st.set(0,'abc',0,0xffffffff,'abc_data')
182
- assert_equal(1, Marshal.load(@st.dump(0)).length )
183
- @st.set(0,'def',0,0xffffffff,'def_data')
184
- assert_equal(2, Marshal.load(@st.dump(0)).length )
185
- assert_nil( @st.dump(1) ) # another vnode is empty
186
-
187
- n=ndat
188
- n.times{|i|
189
- @st.set(2,i.to_s,0,0xffffffff,'abc_data')
190
- }
191
- assert_equal(n, Marshal.load(@st.dump(2)).length )
192
- end
193
-
194
- def test_volume
195
- n=ndat
196
- n.times{|i|
197
- @st.set(0,i.to_s,0,0xffffffff,'abc_data')
198
- }
199
- n.times{|i|
200
- assert_equal('abc_data', @st.get(0,i.to_s,0))
201
- }
202
- n.times{|i|
203
- assert_equal('abc_data', @st.delete(0,i.to_s,0)[4])
204
- }
205
- # true_length value is included in number of deletemark
206
- assert_equal(n, @st.true_length )
207
- end
208
-
209
- def test_each_clean_up
210
- n=10
211
-
212
- vnhash={}
213
- n.times{|i|
214
- n.times{|j|
215
- @st.set(i,"key#{i}-#{j}",0,0xffffffff,"val#{i}-#{j}")
216
- }
217
- vnhash[i]=:primary
218
- }
219
- # ---------+------+---------------------
220
- # last < now+100
221
- # all data within a fixed time limit
222
- @st.each_clean_up_sleep = 0
223
- @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
224
- puts "k=#{k} vn=#{vn}"
225
- assert(false)
226
- }
227
-
228
- # delete data in vn=0
229
- n.times{|i| @st.delete(0,"key0-#{i}",0) }
230
- # time is 100 second ago
231
- @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
232
- assert(false)
233
- }
234
-
235
- # time is 100 second later
236
- cnt=0
237
- @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
238
- assert_equal(0, vn)
239
- assert_match(/key0-/, k )
240
- cnt += 1
241
- }
242
- assert_equal(10,cnt )
243
-
244
- # delete data in vn=1
245
- n.times{|i| @st.delete(1,"key1-#{i}",0) }
246
- # set to :secondary in vn=1
247
- vnhash[1]=:secondary
248
- # :secondary was not deleted
249
- @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
250
- assert(false)
251
- }
252
- # set to :primary in vn=1
253
- vnhash[1]=:primary
254
- # in :primary data was deleted
255
- cnt=0
256
- @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
257
- assert_equal(1, vn)
258
- assert_match(/key1-/, k )
259
- cnt += 1
260
- }
261
- assert_equal(10,cnt)
262
-
263
- # deletemark was empty
264
- @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
265
- assert(false)
266
- }
267
-
268
- # vn=2 is not taken of charge
269
- vnhash.delete(2)
270
- # but still have a data in vn=2
271
- n.times{|i|
272
- assert_match(/val2-/,@st.get(2,"key2-#{i}",0) )
273
- }
274
- # data was deleted in vn=2
275
- cnt=0
276
- @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
277
- assert_equal(2, vn)
278
- assert_match(/key2-/, k )
279
- cnt += 1
280
- }
281
- assert_equal(10,cnt)
282
- # confirm it in vn=2
283
- n.times{|i|
284
- assert_nil( @st.get(2,"key2-#{i}",0) )
285
- }
286
-
287
- # time is 100 second ago in vn=3
288
- n.times{|i|
289
- @st.set(3,"key3-#{i}",0,Time.now.to_i-100,"val3-#{i}")
290
- }
291
- # 10 keys deleted
292
- cnt=0
293
- @st.each_clean_up(Time.now.to_i-100,vnhash){|k,vn|
294
- assert_equal(3, vn)
295
- assert_match(/key3-/, k )
296
- cnt += 1
297
- }
298
- assert_equal(10,cnt)
299
- end
300
-
301
- def test_each_clean_up2
302
- n=10
303
-
304
- # set and delete is repeated 100 times
305
- vnhash={}
306
- n.times{|i|
307
- n.times{|j|
308
- @st.set(i,"key#{i}-#{j}",0,0xffffffff,"val#{i}-#{j}")
309
- @st.delete(i,"key#{i}-#{j}",0)
310
- }
311
- vnhash[i]=:primary
312
- }
313
-
314
- # each waite is 10 msec
315
- cnt = 0
316
- th = Thread.new{
317
- @st.each_clean_up_sleep = 0.01
318
- @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
319
- cnt += 1
320
- }
321
- }
322
- # in 500msec later will stop
323
- sleep 0.5
324
- @st.stop_clean_up
325
- th.join
326
- # should cnt is less than 100
327
- assert_operator(100, :>, cnt)
328
- # delete a remain keys
329
- @st.each_clean_up_sleep = 0
330
- @st.each_clean_up(Time.now.to_i+100,vnhash){|k,vn|
331
- cnt += 1
332
- }
333
- # after all cnt is 100
334
- assert_equal(100, cnt)
335
- end
336
-
337
- def test_dump_and_load
338
- n=10
339
- n.times{|i|
340
- # clock = 0
341
- @st.set(0,i.to_s,0,0xffffffff,'abc_data')
342
- }
343
- # not loaded
344
- assert_equal(0, @st.load(@st.dump(0)) )
345
-
346
- h={}
347
- n.times{|i|
348
- # clock = 1
349
- h[i.to_s]=[0,Time.now.to_i,1,0xffffffff].pack('NNNN')+'new data'
350
- }
351
- dmp=Marshal.dump(h)
352
-
353
- # loaded
354
- assert_equal(n, @st.load(dmp) )
355
- assert_equal('new data', @st.get(0,'0',0))
356
- end
357
-
358
- def test_dump_and_load2
359
- n=10
360
- # create a deletemark
361
- n.times{|i|
362
- assert_nil( @st.delete(0,i.to_s,0)[4] )
363
- }
364
- # dump a deletemark
365
- dmp=@st.dump(0)
366
- assert_equal(n, Marshal.load(dmp).length )
367
- # not loaded, it's same data
368
- assert_equal(0, @st.load(@st.dump(0)) )
369
-
370
- # create a old clock data
371
- h={}
372
- n.times{|i|
373
- h[i.to_s]=[0,Time.now.to_i,0xffffffff,0xffffffff].pack('NNNN')+'old data'
374
- }
375
- dmp=Marshal.dump(h)
376
- # not loaded
377
- assert_equal(0, @st.load(dmp) )
378
- assert_nil( @st.get(0,'0',0) )
379
- end
380
-
381
- # access after close
382
- def test_close
383
- @st.closedb
384
-
385
- assert_raise NoMethodError do
386
- @st.get(0,'abc',0)
387
- end
388
-
389
- assert_raise NoMethodError do
390
- @st.set(0,'abc',0,0xffffffff,'abc_data')
391
- end
392
-
393
- assert_raise NoMethodError do
394
- @st.dump(0)
395
- end
396
-
397
- h={}
398
- 100.times{|i|
399
- h[i.to_s]=[0,Time.now.to_i,0xffffffff,0xffffffff].pack('NNNN')+'old data'
400
- }
401
- dmp=Marshal.dump(h)
402
-
403
- assert_raise NoMethodError do
404
- @st.load(dmp)
405
- end
406
-
407
- end
408
-
409
- def test_close_after_each_clean_up
410
- h={}
411
- 100.times{|i|
412
- h[i.to_s]=[i%10,Time.now.to_i,0,Time.now.to_i].pack('NNNN')+'old data'
413
- }
414
- dmp=Marshal.dump(h)
415
- @st.load(dmp)
416
-
417
- @st.each_clean_up(Time.now.to_i-100, Hash.new(:primary) ){|k,vn|
418
- @st.closedb
419
- }
420
- end
421
-
422
- def test_each_vn_dump_in_normal
423
- n=100
424
- n.times{|i|
425
- @st.set(0,"key#{i}",0,0x7fffffff,"val#{i}")
426
- }
427
- (90..99).each{|i|
428
- @st.delete(0, "key#{i}", 0)
429
- }
430
- count = 0
431
- res = @st.each_vn_dump(0){|data|
432
- vn, last, clk, expt, klen = data.slice!(0..19).unpack('NNNNN')
433
- k = data.slice!(0..(klen-1))
434
- vlen, = data.slice!(0..3).unpack('N')
435
- v = data
436
- count += 1
437
- # puts "#{vn} #{last} #{clk} #{expt} #{klen} #{k} #{vlen} #{v}"
438
- assert_equal('key',k[0..2])
439
- assert_equal('val',v[0..2]) if k[3..-1].to_i < 90
440
-
441
- assert_nil( @st.load_stream_dump(vn, last, clk, expt, k, v) )
442
- @st.load_stream_dump(2, last, clk, expt, k, v)
443
- }
444
- assert(res)
445
- assert_equal(100,count)
446
-
447
- count = 0
448
- @st.each_vn_dump(1){|data| count += 1 }
449
- assert_equal(0,count )
450
-
451
- count = 0
452
- @st.each_vn_dump(2){|data| count += 1 }
453
- assert_equal(100,count )
454
- end
455
-
456
- def test_each_vn_dump_not_normal
457
- dn = @st.instance_eval{ @hdiv[0] }
458
-
459
- n=100
460
- n.times{|i|
461
- @st.set(0,"key#{i}",0,0x7fffffff,"val#{i}")
462
- }
463
-
464
- # :normal -> :safecopy_flushing
465
- assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
466
- # :safecopy_flushing -> :safecopy_flushed
467
- assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
468
-
469
- (80..99).each{|i|
470
- @st.set(0,"key#{i}",0,0x7fffffff,"val#{i + 1}")
471
- }
472
-
473
- # :safecopy_flushed -> :cachecleaning
474
- assert_equal(:cachecleaning, @st.set_db_stat(dn, :cachecleaning))
475
-
476
- (90..99).each{|i|
477
- @st.delete(0, "key#{i}", 0)
478
- }
479
-
480
- count = 0
481
- res = @st.each_vn_dump(0){|data|
482
- vn, last, clk, expt, klen = data.slice!(0..19).unpack('NNNNN')
483
- k = data.slice!(0..(klen-1))
484
- vlen, = data.slice!(0..3).unpack('N')
485
- v = data
486
- count += 1
487
- # puts "#{vn} #{last} #{clk} #{expt} #{klen} #{k} #{vlen} #{v}"
488
- }
489
- assert_equal(false, res)
490
- assert_equal(0, count)
491
- end
492
-
493
- def test_db_stat_with_each_vn_dump
494
- n = 100 # number of data
495
- m = 10 # number of vnode
496
- # set data
497
- n.times do |i|
498
- m.times do|vn|
499
- @st.set(vn,"key#{vn}_#{i}",0,0x7fffffff,"val#{i}")
500
- end
501
- end
502
-
503
- m.times do |vn|
504
- dn = @st.instance_eval{ @hdiv[vn] }
505
- count = 0
506
- res = @st.each_vn_dump(vn) do
507
- assert_equal(false, @st.each_vn_dump(vn){})
508
- assert_equal(:normal, @st.dbs[dn])
509
- assert_equal(false, @st.set_db_stat(dn, :safecopy_flushing))
510
- count += 1
511
- end
512
- assert_equal(n, count)
513
- assert(res)
514
- end
515
- end
516
-
517
- def test_db_stat
518
- assert_nil(@st.instance_eval{ @hdbc[0] })
519
- # :normal -> error case
520
- assert_equal(false, @st.set_db_stat(0, :safecopy_flushed))
521
- assert_equal(false, @st.set_db_stat(0, :cachecleaning))
522
- assert_equal(false, @st.set_db_stat(0, :normal))
523
- # :normal -> :safecopy_flushing
524
- assert_equal(:safecopy_flushing, @st.set_db_stat(0, :safecopy_flushing))
525
- assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[0] })
526
- assert(@st.instance_eval{ @hdbc[0] })
527
-
528
- # :safecopy_flushing -> error case
529
- assert_equal(false, @st.set_db_stat(0, :safecopy_flushing))
530
- assert_equal(false, @st.set_db_stat(0, :cachecleaning))
531
- assert_equal(false, @st.set_db_stat(0, :normal))
532
- # :safecopy_flushing -> :safecopy_flushed
533
- assert_equal(:safecopy_flushed, @st.set_db_stat(0, :safecopy_flushed))
534
- assert_equal(:safecopy_flushed, @st.instance_eval{ @dbs[0] })
535
- assert(@st.instance_eval{ @hdbc[0] })
536
-
537
- # :safecopy_flushed -> error case
538
- assert_equal(false, @st.set_db_stat(0, :safecopy_flushing))
539
- assert_equal(false, @st.set_db_stat(0, :safecopy_flushed))
540
- assert_equal(false, @st.set_db_stat(0, :normal))
541
- # :safecopy_flushed -> :cachecleaning
542
- assert_equal(:cachecleaning, @st.set_db_stat(0, :cachecleaning))
543
- assert_equal(:cachecleaning, @st.instance_eval{ @dbs[0] })
544
- assert(@st.instance_eval{ @hdbc[0] })
545
-
546
- # :cachecleaning -> error case
547
- assert_equal(false, @st.set_db_stat(0, :safecopy_flushed))
548
- assert_equal(false, @st.set_db_stat(0, :cachecleaning))
549
- # :cachecleaning -> :safecopy_flushing
550
- assert_equal(:safecopy_flushing, @st.set_db_stat(0, :safecopy_flushing))
551
- assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[0] })
552
- assert_equal(:safecopy_flushed, @st.set_db_stat(0, :safecopy_flushed))
553
- assert_equal(:cachecleaning, @st.set_db_stat(0, :cachecleaning))
554
- assert(@st.instance_eval{ @hdbc[0] })
555
- # :cachecleaning -> :normal
556
- assert_equal(:normal, @st.set_db_stat(0, :normal))
557
- assert_equal(:normal, @st.instance_eval{ @dbs[0] })
558
- assert_nil(@st.instance_eval{ @hdbc[0] })
559
- end
560
-
561
- def test_clock_along_status
562
- vn = 0
563
- dn = @st.instance_eval{ @hdiv[vn] }
564
- assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
565
- assert( @st.get_context(vn, 'abc', 0)[2] == 0 )
566
- # :normal -> :safecopy_flushing
567
- assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
568
- assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
569
- assert( @st.get_context(vn, 'abc', 0)[2] == 1 )
570
- # :safecopy_flushing -> :safecopy_flushed
571
- assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
572
- assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
573
- assert( @st.get_context(vn, 'abc', 0)[2] == 2 )
574
- # :safecopy_flushed -> :cachecleaning
575
- assert_equal(:cachecleaning, @st.set_db_stat(dn, :cachecleaning))
576
- assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
577
- assert( @st.get_context(vn, 'abc', 0)[2] == 3 )
578
- # :cachecleaning -> :normal
579
- assert_equal(:normal, @st.set_db_stat(dn, :normal))
580
- assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
581
- assert( @st.get_context(vn, 'abc', 0)[2] == 4 )
582
- end
583
-
584
- def test_set_get_in_safecopy
585
- vn = 0
586
- dn = @st.instance_eval{ @hdiv[vn] }
587
- # :normal -> :safecopy_flushing
588
- assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
589
- assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[dn] })
590
- assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
591
- assert_equal('abc_data', @st.get(vn,'abc',0) )
592
- # not stored
593
- assert_nil(@st.instance_eval{ @hdb[dn].get('abc') })
594
- # stored
595
- assert(@st.instance_eval{ @hdbc[dn].get('abc') })
596
-
597
- # :safecopy_flushing -> :safecopy_flushed
598
- assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
599
- assert_equal(:safecopy_flushed, @st.instance_eval{ @dbs[dn] })
600
- assert_equal('def_data', @st.set(vn,'def',0,0xffffffff,'def_data')[4])
601
- assert_equal('def_data', @st.get(vn,'def',0) )
602
- # not stored
603
- assert_nil(@st.instance_eval{ @hdb[dn].get('def') })
604
- # stored
605
- assert(@st.instance_eval{ @hdbc[dn].get('def') })
606
- end
607
-
608
- def test_set_get_in_cachecleaning
609
- vn = 0
610
- dn = @st.instance_eval{ @hdiv[vn] }
611
- assert_equal( 'abc_data',@st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
612
- assert_equal( 'abc_data', @st.get(vn,'abc',0) ) # database
613
- # :normal -> :safecopy_flushing
614
- assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
615
- # :safecopy_flushing -> :safecopy_flushed
616
- assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
617
- assert_equal( 'abc_data1',@st.set(vn,'abc',0,0xffffffff,'abc_data1')[4])
618
- assert_equal( 'abc_data1', @st.get(vn,'abc',0) ) # cache
619
- # :safecopy_flushed -> :cachecleaning
620
- assert_equal(:cachecleaning, @st.set_db_stat(dn, :cachecleaning))
621
- assert_equal( 'abc_data1', @st.get(vn,'abc',0) ) # cache
622
- assert_equal( 'abc_data2',@st.set(vn,'abc',0,0xffffffff,'abc_data2')[4])
623
- assert_equal( 'abc_data2', @st.get(vn,'abc',0) ) # database
624
- end
625
-
626
- def test_out_cache
627
- vn = 0
628
- dn = @st.instance_eval{ @hdiv[vn] }
629
- # :normal -> :safecopy_flushing
630
- assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
631
- assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[dn] })
632
- assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
633
- assert_equal('abc_data', @st.get(vn,'abc',0) )
634
- # not stored
635
- assert_nil(@st.instance_eval{ @hdb[dn].get('abc') })
636
- # stored
637
- assert(@st.instance_eval{ @hdbc[dn].get('abc') })
638
- # out
639
- @st.out_cache(dn, 'abc')
640
- # not stored
641
- assert_nil(@st.instance_eval{ @hdb[dn].get('abc') })
642
- # not stored
643
- assert_nil(@st.instance_eval{ @hdbc[dn].get('abc') })
644
- end
645
-
646
- def test_each_cache_dump_pack
647
- vn = 0
648
- dn = @st.instance_eval{ @hdiv[vn] }
649
- # :normal -> :safecopy_flushing
650
- assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
651
- keys = []
652
- 10.times do |i|
653
- k = "key#{i}"
654
- v = "val#{i}"
655
- assert_equal(v, @st.set(vn,k,0,0xffffffff,v)[4])
656
- keys << k
657
- end
658
- @st.each_cache_dump_pack(dn, keys) do |data|
659
- vn, last, clk, expt, klen = data.slice!(0..19).unpack('NNNNN')
660
- k = data.slice!(0..(klen-1))
661
- vlen, = data.slice!(0..3).unpack('N')
662
- v = data
663
- # puts "#{vn} #{last} #{clk} #{expt} #{klen} #{k} #{vlen} #{v}"
664
- assert_match(/key\d/, k)
665
- assert_match("val#{k[3..-1]}", v)
666
- end
667
- end
668
-
669
- def test_get_keys_in_cache
670
- vn = 0
671
- dn = @st.instance_eval{ @hdiv[vn] }
672
- # :normal -> :safecopy_flushing
673
- assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
674
- keys = []
675
- 100.times do |i|
676
- k = "key#{i}"
677
- v = "val#{i}"
678
- assert_equal(v, @st.set(vn,k,0,0xffffffff,v)[4])
679
- end
680
-
681
- assert(@st.instance_eval{ @hdbc[dn].rnum } == 100)
682
- 10.times do
683
- keys = @st.get_keys_in_cache(dn, 10)
684
- assert(keys.length == 10)
685
- keys.each do |k|
686
- @st.out_cache(dn, k)
687
- end
688
- end
689
- assert(@st.instance_eval{ @hdbc[dn].rnum } == 0)
690
- end
691
- end
692
-
693
- class DbmStorageTest < Test::Unit::TestCase
694
- include StorageTests
695
-
696
- def setup
697
- rmtestdir('storage_test')
698
- @st=Roma::Storage::DbmStorage.new
699
- @st.vn_list = [0,1,2,3,4,5,6,7,8,9]
700
- @st.storage_path = 'storage_test'
701
- @st.opendb
702
- end
703
-
704
- def test_close_after_each_clean_up
705
- h={}
706
- 1000.times{|i|
707
- h[i.to_s]=[i%10,Time.now.to_i,0,Time.now.to_i].pack('NNNN')+'old data'
708
- }
709
- dmp=Marshal.dump(h)
710
- @st.load(dmp)
711
-
712
- assert_raise RuntimeError do
713
- @st.each_clean_up(Time.now.to_i-100, Hash.new(:primary) ){|k,vn|
714
- @st.closedb
715
- }
716
- end
717
- end
718
- end
719
-
720
8
  class TCStorageTest < Test::Unit::TestCase
9
+ self.test_order = :defined
721
10
  include StorageTests
722
11
 
723
12
  def setup
@@ -737,6 +26,7 @@ class TCStorageTest < Test::Unit::TestCase
737
26
  end
738
27
 
739
28
  class RubyHashStorageTest < Test::Unit::TestCase
29
+ self.test_order = :defined
740
30
  include StorageTests
741
31
 
742
32
  def setup
@@ -800,34 +90,8 @@ class RubyHashStorageTest < Test::Unit::TestCase
800
90
 
801
91
  end
802
92
 
803
- class SQLite3StorageTest < Test::Unit::TestCase
804
- include StorageTests
805
-
806
- def setup
807
- rmtestdir('storage_test')
808
- @st=Roma::Storage::SQLite3Storage.new
809
- @st.vn_list = [0,1,2,3,4,5,6,7,8,9]
810
- @st.storage_path = 'storage_test'
811
- @st.opendb
812
- end
813
-
814
- def test_close_after_each_clean_up
815
- h={}
816
- 1000.times{|i|
817
- h[i.to_s]=[i%10,Time.now.to_i,0,Time.now.to_i].pack('NNNN')+'old data'
818
- }
819
- dmp=Marshal.dump(h)
820
- @st.load(dmp)
821
-
822
- assert_raise SQLite3::BusyException do
823
- @st.each_clean_up(Time.now.to_i-100, Hash.new(:primary) ){|k,vn|
824
- @st.closedb
825
- }
826
- end
827
- end
828
- end
829
-
830
93
  class TCMemStorageTest < Test::Unit::TestCase
94
+ self.test_order = :defined
831
95
  include StorageTests
832
96
 
833
97
  def setup
@@ -840,6 +104,7 @@ class TCMemStorageTest < Test::Unit::TestCase
840
104
  end
841
105
 
842
106
  class GroongaStorageTest < Test::Unit::TestCase
107
+ self.test_order = :defined
843
108
  include StorageTests
844
109
 
845
110
  def storage_path