roma 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/LICENSE.rdoc +675 -0
  2. data/README.rdoc +0 -0
  3. data/Rakefile +70 -0
  4. data/bin/mkrecent +7 -0
  5. data/bin/mkroute +7 -0
  6. data/bin/recoverlost +8 -0
  7. data/bin/recoverlost_alist +8 -0
  8. data/bin/romad +7 -0
  9. data/bin/sample_watcher +8 -0
  10. data/bin/sample_watcher2 +8 -0
  11. data/bin/simple_bench +8 -0
  12. data/bin/ssroute +7 -0
  13. data/bin/tribunus +7 -0
  14. data/lib/roma/async_process.rb +696 -0
  15. data/lib/roma/command/bg_command_receiver.rb +188 -0
  16. data/lib/roma/command/mh_command_receiver.rb +117 -0
  17. data/lib/roma/command/receiver.rb +287 -0
  18. data/lib/roma/command/rt_command_receiver.rb +147 -0
  19. data/lib/roma/command/st_command_receiver.rb +564 -0
  20. data/lib/roma/command/util_command_receiver.rb +67 -0
  21. data/lib/roma/command/vn_command_receiver.rb +143 -0
  22. data/lib/roma/command_plugin.rb +11 -0
  23. data/lib/roma/config.rb +64 -0
  24. data/lib/roma/event/con_pool.rb +140 -0
  25. data/lib/roma/event/handler.rb +159 -0
  26. data/lib/roma/plugin/plugin_alist.rb +1572 -0
  27. data/lib/roma/plugin/plugin_debug.rb +19 -0
  28. data/lib/roma/plugin/plugin_test.rb +14 -0
  29. data/lib/roma/romad.rb +582 -0
  30. data/lib/roma/routing/cb_rttable.rb +326 -0
  31. data/lib/roma/routing/merkle_tree.rb +54 -0
  32. data/lib/roma/routing/rttable.rb +148 -0
  33. data/lib/roma/stats.rb +112 -0
  34. data/lib/roma/storage/basic_storage.rb +510 -0
  35. data/lib/roma/storage/dbm_storage.rb +80 -0
  36. data/lib/roma/storage/dummy_storage.rb +44 -0
  37. data/lib/roma/storage/rh_storage.rb +35 -0
  38. data/lib/roma/storage/sqlite3_storage.rb +73 -0
  39. data/lib/roma/storage/tc_storage.rb +133 -0
  40. data/lib/roma/tools/mkrecent.rb +138 -0
  41. data/lib/roma/tools/mkroute.rb +52 -0
  42. data/lib/roma/tools/recoverlost.rb +9 -0
  43. data/lib/roma/tools/recoverlost_alist.rb +9 -0
  44. data/lib/roma/tools/recoverlost_lib.rb +217 -0
  45. data/lib/roma/tools/sample_watcher.rb +38 -0
  46. data/lib/roma/tools/sample_watcher2.rb +38 -0
  47. data/lib/roma/tools/simple_bench.rb +57 -0
  48. data/lib/roma/tools/ssroute.rb +23 -0
  49. data/lib/roma/tools/tribunus.rb +299 -0
  50. data/lib/roma/version.rb +4 -0
  51. data/lib/roma/write_behind.rb +179 -0
  52. data/test/rcirb.rb +16 -0
  53. data/test/roma-test-utils.rb +65 -0
  54. data/test/run-test.rb +16 -0
  55. data/test/t_cpdata.rb +277 -0
  56. data/test/t_listplugin.rb +592 -0
  57. data/test/t_rclient.rb +318 -0
  58. data/test/t_routing_data.rb +100 -0
  59. data/test/t_storage.rb +644 -0
  60. data/test/t_writebehind.rb +200 -0
  61. metadata +134 -0
@@ -0,0 +1,592 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'roma/client/rclient'
5
+ require 'roma/plugin/plugin_alist'
6
+ require 'roma/storage/tc_storage'
7
+
8
+ Roma::Client::RomaClient.class_eval{
9
+ def init_sync_routing_proc
10
+ end
11
+ }
12
+
13
+ class ListPluginTest < Test::Unit::TestCase
14
+ include RomaTestUtils
15
+
16
+ def setup
17
+ start_roma
18
+ @rc=Roma::Client::RomaClient.new(
19
+ ["localhost_11211","localhost_11212"],
20
+ [::Roma::ClientPlugin::PluginAshiatoList])
21
+ end
22
+
23
+ def teardown
24
+ stop_roma
25
+ Roma::Messaging::ConPool::instance.close_all
26
+ end
27
+
28
+ def test_error_case
29
+ @rc.set("aa","123")
30
+ assert_raise(RuntimeError) do
31
+ @rc.alist_to_s("aa")
32
+ end
33
+
34
+ assert_raise(RuntimeError) do
35
+ @rc.alist_push("aa","123")
36
+ end
37
+ end
38
+
39
+ def test_at
40
+ @rc.alist_clear("aa")
41
+ assert_nil( @rc.alist_at("aa",0) )
42
+ assert_equal('STORED', @rc.alist_push("aa","11"))
43
+ assert_equal('STORED', @rc.alist_push("aa","22"))
44
+ assert_equal('STORED', @rc.alist_push("aa","33"))
45
+ assert_equal('STORED', @rc.alist_push("aa","44"))
46
+
47
+ assert_equal('11',@rc.alist_at("aa",0) )
48
+ assert_equal('22', @rc.alist_at("aa",1) )
49
+ assert_equal('33', @rc.alist_at("aa",2) )
50
+ assert_equal('44', @rc.alist_at("aa",3) )
51
+ assert_nil( @rc.alist_at("aa",4) )
52
+ end
53
+
54
+ def test_delete
55
+ @rc.alist_clear("aa")
56
+ assert_equal('STORED', @rc.alist_push("aa","11") )
57
+ assert_equal('STORED', @rc.alist_push("aa","22") )
58
+ assert_equal('STORED', @rc.alist_push("aa","33") )
59
+ assert_equal('STORED', @rc.alist_push("aa","44") )
60
+
61
+ assert_equal('NOT_FOUND', @rc.alist_delete("bb","11") )
62
+ assert_equal('NOT_DELETED', @rc.alist_delete("aa","55") )
63
+
64
+ assert_equal('DELETED', @rc.alist_delete("aa","33"))
65
+ assert_equal(["11","22","44"], @rc.alist_to_s("aa")[1] )
66
+ assert_raise RuntimeError do
67
+ @rc.alist_delete("aa",33)
68
+ end
69
+ end
70
+
71
+ def test_delete_at
72
+ @rc.alist_clear("aa")
73
+ assert_equal('STORED', @rc.alist_push("aa","11"))
74
+ assert_equal('STORED', @rc.alist_push("aa","22"))
75
+ assert_equal('STORED', @rc.alist_push("aa","33"))
76
+ assert_equal('STORED', @rc.alist_push("aa","44"))
77
+
78
+ assert_equal('NOT_FOUND', @rc.alist_delete_at("bb",1))
79
+ assert_equal('NOT_DELETED', @rc.alist_delete_at("aa",55))
80
+
81
+ assert_equal('DELETED', @rc.alist_delete_at("aa",2))
82
+ assert_equal(["11","22","44"], @rc.alist_to_s("aa")[1])
83
+ end
84
+
85
+ def test_empty?
86
+ @rc.delete("aa")
87
+ assert_equal('NOT_FOUND', @rc.alist_empty?("aa"))
88
+ assert_equal('STORED', @rc.alist_push("aa","11"))
89
+ assert_equal('false', @rc.alist_empty?("aa"))
90
+ @rc.alist_clear("aa")
91
+ assert_equal('true', @rc.alist_empty?("aa"))
92
+ end
93
+
94
+ def test_first_last
95
+ @rc.alist_clear("aa")
96
+
97
+ assert_nil( @rc.alist_first("aa"))
98
+ assert_nil( @rc.alist_first("bb"))
99
+ assert_nil( @rc.alist_last("aa"))
100
+ assert_nil( @rc.alist_last("bb"))
101
+
102
+ assert_equal('STORED', @rc.alist_push("aa","11"))
103
+ assert_equal('11', @rc.alist_first("aa"))
104
+ assert_equal('11', @rc.alist_last("aa"))
105
+ assert_equal('STORED', @rc.alist_push("aa","22"))
106
+ assert_equal('STORED', @rc.alist_push("aa","33"))
107
+ assert_equal('33', @rc.alist_last("aa"))
108
+ assert_equal('STORED', @rc.alist_push("aa","44"))
109
+ assert_equal('11', @rc.alist_first("aa"))
110
+ assert_equal('44', @rc.alist_last("aa"))
111
+ end
112
+
113
+ def test_gets
114
+ @rc.alist_clear("aa")
115
+
116
+ assert_nil( @rc.alist_gets("aa") )
117
+ assert( @rc.alist_push("aa","11")=='STORED' )
118
+ assert( @rc.alist_gets("aa") == [1,"11"] )
119
+ assert( @rc.alist_push("aa","22")=='STORED' )
120
+ assert( @rc.alist_push("aa","33")=='STORED' )
121
+ assert( @rc.alist_gets("aa") == [3,"11","22","33"] )
122
+ assert( @rc.alist_push("aa","44")=='STORED' )
123
+ assert( @rc.alist_push("aa","55")=='STORED' )
124
+ assert( @rc.alist_gets("aa",1..3)==[5, "22", "33", "44"] )
125
+ ret = @rc.alist_gets_with_time("aa")
126
+ assert( ret[0]==5 )
127
+ assert( ret.values_at(1,3,5,7,9) == ["11","22","33","44","55"] )
128
+ end
129
+
130
+ def test_include?
131
+ @rc.delete("aa")
132
+
133
+ assert_equal('NOT_FOUND', @rc.alist_include?("aa","11"))
134
+ assert_equal('STORED', @rc.alist_push("aa","11"))
135
+ assert_equal('true', @rc.alist_include?("aa","11"))
136
+ assert_equal('false', @rc.alist_include?("aa","22"))
137
+ assert_equal('STORED', @rc.alist_push("aa","22"))
138
+ assert_equal('true', @rc.alist_include?("aa","22"))
139
+ end
140
+
141
+ def test_index
142
+ @rc.delete("aa")
143
+
144
+ assert_equal('NOT_FOUND', @rc.alist_index("aa","22"))
145
+ assert_equal('STORED', @rc.alist_push("aa","11"))
146
+ assert_equal(0, @rc.alist_index("aa","11") )
147
+ assert_nil( @rc.alist_index("aa","22") )
148
+ assert_equal('STORED', @rc.alist_push("aa","22"))
149
+ assert_equal(0, @rc.alist_index("aa","11") )
150
+ assert_equal(1, @rc.alist_index("aa","22") )
151
+ end
152
+
153
+ def test_insert
154
+ @rc.delete("aa")
155
+
156
+ assert_equal('STORED', @rc.alist_insert("aa",0,"11"))
157
+ assert_equal('STORED', @rc.alist_insert("aa",0,"22"))
158
+ assert_equal('STORED', @rc.alist_insert("aa",1,"33"))
159
+ assert_equal(["22","33","11"], @rc.alist_to_s("aa")[1])
160
+ end
161
+
162
+ def test_sized_insert
163
+ @rc.delete("aa")
164
+
165
+ assert_equal('STORED', @rc.alist_sized_insert("aa",5,"11"))
166
+ assert_equal('STORED', @rc.alist_sized_insert("aa",5,"22"))
167
+ assert_equal('STORED', @rc.alist_sized_insert("aa",5,"33"))
168
+ assert_equal('STORED', @rc.alist_sized_insert("aa",5,"44"))
169
+ assert_equal('STORED', @rc.alist_sized_insert("aa",5,"55"))
170
+ assert_equal(["55","44","33","22","11"], @rc.alist_to_s("aa")[1] )
171
+ assert_equal('STORED', @rc.alist_sized_insert("aa",5,"66"))
172
+ assert_equal(["66","55","44","33","22"], @rc.alist_to_s("aa")[1] )
173
+ assert_equal('STORED', @rc.alist_sized_insert("aa",5,"55"))
174
+ assert_equal(["55","66","55","44","33"], @rc.alist_to_s("aa")[1])
175
+ assert_equal('STORED', @rc.alist_sized_insert("aa",3,"22"))
176
+ assert_equal(["22","55","66"], @rc.alist_to_s("aa")[1] )
177
+ end
178
+
179
+ def test_sized_insert2
180
+ @rc.delete("aa")
181
+
182
+ 100.times{|i|
183
+ v = (i % 10).to_s * 1024
184
+ assert_equal('STORED', @rc.alist_sized_insert("aa",50,v))
185
+ if i+1 >= 50
186
+ assert_equal(50, @rc.alist_length("aa"))
187
+ else
188
+ assert_equal(i+1, @rc.alist_length("aa"))
189
+ end
190
+ }
191
+ res = @rc.alist_join("aa",",")
192
+ assert_equal(50, res[0])
193
+ assert_equal(50, res[1].split(",").length)
194
+ end
195
+
196
+ def test_swap_and_insert
197
+ @rc.delete("aa")
198
+
199
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","11"))
200
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","22"))
201
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","33"))
202
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","44"))
203
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","55"))
204
+ assert_equal(["55","44","33","22","11"], @rc.alist_to_s("aa")[1])
205
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","66"))
206
+ assert_equal(["66","55","44","33","22","11"], @rc.alist_to_s("aa")[1])
207
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","55"))
208
+ assert_equal(["55","66","44","33","22","11"], @rc.alist_to_s("aa")[1])
209
+ assert_equal('STORED', @rc.alist_swap_and_insert("aa","22"))
210
+ assert_equal(["22","55","66","44","33","11"], @rc.alist_to_s("aa")[1])
211
+ end
212
+
213
+ def test_swap_and_sized_insert
214
+ @rc.delete("aa")
215
+
216
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",5,"11"))
217
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",5,"22"))
218
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",5,"33"))
219
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",5,"44"))
220
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",5,"55"))
221
+ assert_equal(["55","44","33","22","11"], @rc.alist_to_s("aa")[1])
222
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",5,"66"))
223
+ assert_equal(["66","55","44","33","22"], @rc.alist_to_s("aa")[1])
224
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",5,"55"))
225
+ assert_equal(["55","66","44","33","22"], @rc.alist_to_s("aa")[1])
226
+ assert_equal('STORED', @rc.alist_swap_and_sized_insert("aa",3,"22"))
227
+ assert_equal(["22","55","66"], @rc.alist_to_s("aa")[1])
228
+ end
229
+
230
+ def test_expired_swap_and_insert
231
+ @rc.delete("aa")
232
+
233
+ assert_equal('STORED', @rc.alist_expired_swap_and_insert("aa",5,"11"))
234
+ assert_equal('STORED', @rc.alist_expired_swap_and_insert("aa",5,"22"))
235
+ assert_equal('STORED', @rc.alist_expired_swap_and_insert("aa",5,"33"))
236
+ assert_equal(["33","22","11"], @rc.alist_to_s("aa")[1])
237
+ assert_equal('STORED', @rc.alist_expired_swap_and_insert("aa",5,"11"))
238
+ assert_equal(["11","33","22"], @rc.alist_to_s("aa")[1])
239
+ assert_equal('STORED', @rc.alist_expired_swap_and_insert("aa",5,"33"))
240
+ assert_equal(["33","11","22"], @rc.alist_to_s("aa")[1])
241
+ assert_equal('STORED', @rc.alist_expired_swap_and_insert("aa",0,"44"))
242
+ assert_equal(["44"], @rc.alist_to_s("aa")[1])
243
+ end
244
+
245
+ def test_expired_swap_and_sized_insert
246
+ @rc.delete("aa")
247
+
248
+ # for sized logic
249
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"00"))
250
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"11"))
251
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"22"))
252
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"33"))
253
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"44"))
254
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"55"))
255
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"66"))
256
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"77"))
257
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"88"))
258
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"99"))
259
+ assert_equal(["99","88","77","66","55","44","33","22","11","00"], @rc.alist_to_s("aa")[1])
260
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"aa"))
261
+ assert_equal(["aa","99","88","77","66","55","44","33","22","11"], @rc.alist_to_s("aa")[1])
262
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"bb"))
263
+ assert_equal(["bb","aa","99","88","77","66","55","44","33","22"], @rc.alist_to_s("aa")[1])
264
+
265
+ # for swaped logic
266
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",5,10,"55"))
267
+ assert_equal(["55","bb","aa","99","88","77","66","44","33","22"], @rc.alist_to_s("aa")[1])
268
+
269
+ # for expired logic
270
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert("aa",0,10,"44"))
271
+ assert_equal(["44"], @rc.alist_to_s("aa")[1])
272
+ end
273
+
274
+ def test_join
275
+ @rc.delete("aa")
276
+
277
+ assert( @rc.alist_join("aa","|")==nil )
278
+ t = Time.now.to_i
279
+ assert( @rc.alist_push("aa","11")=='STORED' )
280
+ assert( @rc.alist_join("aa","|")[1]=="11" )
281
+ # 挿入時間を取得、おそらく1秒以内
282
+ assert_operator(1,:>,t - @rc.alist_join_with_time("aa","|")[2].to_i)
283
+ assert_equal('STORED', @rc.alist_push("aa","22"))
284
+ assert_equal("11|22", @rc.alist_join("aa","|")[1])
285
+ assert_equal('STORED', @rc.alist_push("aa","33"))
286
+ assert_equal('STORED', @rc.alist_push("aa","44"))
287
+ assert_equal('STORED', @rc.alist_push("aa","55"))
288
+ assert_equal('STORED', @rc.alist_push("aa","66"))
289
+ assert_equal('STORED', @rc.alist_push("aa","77"))
290
+ ret = @rc.alist_join_with_time("aa","|")
291
+ assert_equal(7,ret[0] )
292
+ assert_equal(7, ret[1].split('|').length )
293
+ assert_equal(7, ret[2].split('|').length )
294
+ assert_nil( @rc.alist_join("aa","|",10) ) # out of index
295
+ assert_equal("66", @rc.alist_join("aa","|",5)[1])
296
+ assert_equal(7, @rc.alist_join("aa","|",1..4)[0] )
297
+ assert_equal("22|33|44|55", @rc.alist_join("aa","|",1..4)[1])
298
+ assert_equal("22|33|44|55|66|77", @rc.alist_join("aa","|",1..10)[1])
299
+ assert_equal("22|33|44|55|66|77", @rc.alist_join("aa","|",1..-1)[1])
300
+ ret = @rc.alist_join_with_time("aa","|",1..4)
301
+ assert_equal(7, ret[0] )
302
+ assert_equal("22|33|44|55", ret[1])
303
+ assert_equal(4, ret[2].split('|').length )
304
+ end
305
+
306
+ def test_json
307
+ @rc.delete("aa")
308
+
309
+ assert_nil( @rc.alist_to_json("aa") )
310
+ assert_equal('STORED', @rc.alist_push("aa","11"))
311
+ assert_equal('["11"]', @rc.alist_to_json("aa"))
312
+ assert_equal('STORED', @rc.alist_push("aa","22"))
313
+ assert_equal('["11","22"]', @rc.alist_to_json("aa"))
314
+ assert_equal('STORED', @rc.alist_push("aa","33"))
315
+ assert_equal('STORED', @rc.alist_push("aa","44"))
316
+ assert_equal('STORED', @rc.alist_push("aa","55"))
317
+ assert_equal('STORED', @rc.alist_push("aa","66"))
318
+ assert_equal('STORED', @rc.alist_push("aa","77"))
319
+
320
+ assert_nil( @rc.alist_to_json("aa",10) )
321
+ assert_equal('["66"]', @rc.alist_to_json("aa",5))
322
+ assert_equal('["22","33","44","55"]', @rc.alist_to_json("aa",1..4))
323
+ assert_equal('["22","33","44","55","66","77"]', @rc.alist_to_json("aa",1..10))
324
+ assert_equal('["22","33","44","55","66","77"]', @rc.alist_to_json("aa",1..-1))
325
+ end
326
+
327
+ def test_length
328
+ @rc.delete("aa")
329
+
330
+ assert_equal('NOT_FOUND', @rc.alist_length("aa"))
331
+ assert_equal('STORED', @rc.alist_push("aa","11"))
332
+ assert_equal(1, @rc.alist_length("aa") )
333
+ assert_equal('STORED', @rc.alist_push("aa","22"))
334
+ assert_equal('STORED', @rc.alist_push("aa","33"))
335
+ assert_equal('STORED', @rc.alist_push("aa","44"))
336
+ assert_equal('STORED', @rc.alist_push("aa","55"))
337
+ assert_equal(5, @rc.alist_length("aa") )
338
+ @rc.alist_clear("aa")
339
+ assert_equal(0, @rc.alist_length("aa") )
340
+ end
341
+
342
+ def test_pop
343
+ @rc.delete("aa")
344
+
345
+ assert_nil( @rc.alist_pop("aa") )
346
+ assert_equal('STORED', @rc.alist_push("aa","11"))
347
+ assert_equal(1, @rc.alist_length("aa") )
348
+ assert_equal('11', @rc.alist_pop("aa") )
349
+ assert_equal(0, @rc.alist_length("aa") )
350
+ assert_equal('STORED', @rc.alist_push("aa","11"))
351
+ assert_equal('STORED', @rc.alist_push("aa","22"))
352
+ assert_equal('STORED', @rc.alist_push("aa","33"))
353
+ assert_equal('STORED', @rc.alist_push("aa","44"))
354
+ assert_equal(4, @rc.alist_length("aa"))
355
+ assert_equal('44', @rc.alist_pop("aa"))
356
+ assert_equal(3, @rc.alist_length("aa"))
357
+ assert_equal('33', @rc.alist_pop("aa"))
358
+ assert_equal('22', @rc.alist_pop("aa"))
359
+ assert_equal('11', @rc.alist_pop("aa"))
360
+ assert_equal(0, @rc.alist_length("aa"))
361
+ end
362
+
363
+ def test_push
364
+ @rc.alist_clear("aa")
365
+ assert_equal('STORED', @rc.alist_push("aa","11"))
366
+ res = @rc.alist_to_s("aa")
367
+ assert_equal(2, res.length )
368
+ assert_equal(1, res[0] )
369
+ assert_equal('11', res[1][0] )
370
+
371
+ assert_equal('STORED', @rc.alist_push("aa","22"))
372
+ assert_equal('STORED', @rc.alist_push("aa","33"))
373
+ assert_equal('STORED', @rc.alist_push("aa","44"))
374
+
375
+ res = @rc.alist_to_s("aa")
376
+ assert_equal(4, res[0])
377
+ assert_equal('11', res[1][0])
378
+ assert_equal('22', res[1][1])
379
+ assert_equal('33', res[1][2])
380
+ assert_equal('44', res[1][3])
381
+ end
382
+
383
+ def test_sized_push
384
+ @rc.alist_clear("aa")
385
+ assert_equal('STORED', @rc.alist_sized_push("aa",5,"11"))
386
+ assert_equal('STORED', @rc.alist_sized_push("aa",5,"22"))
387
+ assert_equal('STORED', @rc.alist_sized_push("aa",5,"33"))
388
+ assert_equal('STORED', @rc.alist_sized_push("aa",5,"44"))
389
+ assert_equal('STORED', @rc.alist_sized_push("aa",5,"55"))
390
+ assert_equal('NOT_PUSHED', @rc.alist_sized_push("aa",5,"66"))
391
+ assert_equal('NOT_PUSHED', @rc.alist_sized_push("aa",5,"77"))
392
+ assert_equal(5, @rc.alist_to_s("aa")[0])
393
+ end
394
+
395
+ def test_swap_and_push
396
+ @rc.alist_clear("aa")
397
+ assert_equal('STORED', @rc.alist_swap_and_push("aa","11"))
398
+ assert_equal(["11"], @rc.alist_to_s("aa")[1])
399
+ assert_equal('STORED', @rc.alist_swap_and_push("aa","22"))
400
+ assert_equal(["11", "22"], @rc.alist_to_s("aa")[1])
401
+ assert_equal('STORED', @rc.alist_swap_and_push("aa","33"))
402
+ assert_equal(["11", "22", "33"], @rc.alist_to_s("aa")[1])
403
+ assert_equal('STORED', @rc.alist_swap_and_push("aa","11"))
404
+ assert_equal(["22", "33", "11"], @rc.alist_to_s("aa")[1])
405
+ assert_equal('STORED', @rc.alist_swap_and_push("aa","44"))
406
+ assert_equal(["22", "33", "11", "44"], @rc.alist_to_s("aa")[1])
407
+ end
408
+
409
+ def test_swap_and_sized_push
410
+ @rc.alist_clear("aa")
411
+ assert_equal('STORED', @rc.alist_swap_and_sized_push("aa",5,"11"))
412
+ assert_equal('STORED', @rc.alist_swap_and_sized_push("aa",5,"22"))
413
+ assert_equal('STORED', @rc.alist_swap_and_sized_push("aa",5,"33"))
414
+ assert_equal(["11","22","33"], @rc.alist_to_s("aa")[1])
415
+ assert_equal('STORED', @rc.alist_swap_and_sized_push("aa",5,"11"))
416
+ assert_equal(["22","33","11"], @rc.alist_to_s("aa")[1])
417
+ assert_equal('STORED', @rc.alist_swap_and_sized_push("aa",5,"44"))
418
+ assert_equal(["22","33","11","44"], @rc.alist_to_s("aa")[1])
419
+ assert_equal('STORED', @rc.alist_swap_and_sized_push("aa",5,"55"))
420
+ assert_equal(["22","33","11","44","55"], @rc.alist_to_s("aa")[1])
421
+ assert_equal('NOT_PUSHED', @rc.alist_swap_and_sized_push("aa",5,"66"))
422
+ assert_equal(["22","33","11","44","55"], @rc.alist_to_s("aa")[1])
423
+ assert_equal('STORED', @rc.alist_swap_and_sized_push("aa",5,"22"))
424
+ assert_equal(["33","11","44","55","22"], @rc.alist_to_s("aa")[1])
425
+ end
426
+
427
+ def test_expired_swap_and_push
428
+ @rc.delete("aa")
429
+
430
+ assert_equal('STORED', @rc.alist_expired_swap_and_push("aa",5,"11"))
431
+ assert_equal('STORED', @rc.alist_expired_swap_and_push("aa",5,"22"))
432
+ assert_equal('STORED', @rc.alist_expired_swap_and_push("aa",5,"33"))
433
+ assert_equal(["11","22","33"], @rc.alist_to_s("aa")[1])
434
+ assert_equal('STORED', @rc.alist_expired_swap_and_push("aa",5,"11"))
435
+ assert_equal(["22","33","11"], @rc.alist_to_s("aa")[1])
436
+ assert_equal('STORED', @rc.alist_expired_swap_and_push("aa",5,"33"))
437
+ assert_equal(["22","11","33"], @rc.alist_to_s("aa")[1])
438
+ assert_equal('STORED', @rc.alist_expired_swap_and_push("aa",0,"44"))
439
+ assert_equal(["44"], @rc.alist_to_s("aa")[1])
440
+ end
441
+
442
+ def test_expired_swap_and_sized_push
443
+ @rc.delete("aa")
444
+
445
+ # for sized logic
446
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"00"))
447
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"11"))
448
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"22"))
449
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"33"))
450
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"44"))
451
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"55"))
452
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"66"))
453
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"77"))
454
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"88"))
455
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"99"))
456
+ assert_equal(["00","11","22","33","44","55","66","77","88","99"], @rc.alist_to_s("aa")[1])
457
+ assert_equal('NOT_PUSHED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"aa"))
458
+ assert_equal(["00","11","22","33","44","55","66","77","88","99"], @rc.alist_to_s("aa")[1])
459
+ assert_equal('NOT_PUSHED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"bb"))
460
+ assert_equal(["00","11","22","33","44","55","66","77","88","99"], @rc.alist_to_s("aa")[1])
461
+
462
+ # for swaped logic
463
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",5,10,"55"))
464
+ assert_equal(["00","11","22","33","44","66","77","88","99","55"], @rc.alist_to_s("aa")[1])
465
+
466
+ # for expired logic
467
+ assert_equal('STORED', @rc.alist_expired_swap_and_sized_push("aa",0,10,"44"))
468
+ assert_equal(["44"], @rc.alist_to_s("aa")[1])
469
+ end
470
+
471
+ def test_shift
472
+ @rc.delete("aa")
473
+
474
+ assert_nil( @rc.alist_shift("aa"))
475
+ assert_equal('STORED', @rc.alist_push("aa","11"))
476
+ assert_equal(1, @rc.alist_length("aa") )
477
+ assert_equal('11', @rc.alist_shift("aa") )
478
+ assert_equal(0, @rc.alist_length("aa") )
479
+ assert_equal('STORED', @rc.alist_push("aa","11"))
480
+ assert_equal('STORED', @rc.alist_push("aa","22"))
481
+ assert_equal('STORED', @rc.alist_push("aa","33"))
482
+ assert_equal('STORED', @rc.alist_push("aa","44"))
483
+ assert_equal(4, @rc.alist_length("aa") )
484
+ assert_equal('11', @rc.alist_shift("aa") )
485
+ assert_equal(3, @rc.alist_length("aa") )
486
+ assert_equal('22', @rc.alist_shift("aa") )
487
+ assert_equal('33', @rc.alist_shift("aa") )
488
+ assert_equal('44', @rc.alist_shift("aa") )
489
+ assert_equal(0, @rc.alist_length("aa") )
490
+ end
491
+
492
+ def test_to_s
493
+ @rc.delete("aa")
494
+
495
+ assert_nil( @rc.alist_to_s("aa") )
496
+ assert_equal('STORED', @rc.alist_push("aa","11"))
497
+ assert( @rc.alist_to_s("aa")[1]==['11'] )
498
+ @rc.alist_clear("aa")
499
+ assert_equal(0, @rc.alist_to_s("aa")[0] )
500
+ assert_equal('STORED', @rc.alist_push("aa","11"))
501
+ assert_equal('STORED', @rc.alist_push("aa","22"))
502
+ assert_equal('STORED', @rc.alist_push("aa","33"))
503
+ assert_equal('STORED', @rc.alist_push("aa","44"))
504
+ assert_equal(["11", "22", "33", "44"], @rc.alist_to_s("aa")[1])
505
+ assert_equal(['11'], @rc.alist_to_s("aa",0)[1] )
506
+ assert_nil( @rc.alist_to_s("aa",10)[1] )
507
+ assert_equal(["22", "33"], @rc.alist_to_s("aa",1..2)[1])
508
+ assert_equal(["11", "22", "33", "44"], @rc.alist_to_s("aa",0..3)[1])
509
+ assert_equal(["11", "22", "33", "44"], @rc.alist_to_s("aa",0..-1)[1])
510
+ assert_equal(["11", "22", "33", "44"], @rc.alist_to_s("aa",0..10)[1])
511
+ end
512
+
513
+ def test_alist_spushv
514
+
515
+ st, nid, vn = create_storage_and_calc_vn('aa')
516
+
517
+ # 過去のデータを作成
518
+ # 時刻は適当で OK
519
+ # リストの結合ロジックは delete and push
520
+ pt =Time.now.to_i
521
+ st.set(vn,'aa',0,0xffffffff,Marshal.dump([['11','22','33','44','55'],[pt,pt,pt,pt,pt]]))
522
+
523
+ @rc.delete("aa")
524
+ @rc.alist_push("aa","55")
525
+ @rc.alist_push("aa","33")
526
+ @rc.alist_push("aa","11")
527
+
528
+ push_a_vnode_stream(st, vn, nid)
529
+
530
+ assert_equal(["55", "33", "11", "22", "44"], @rc.alist_to_s("aa")[1])
531
+
532
+ # list 以外のデータを作成
533
+ st.set(vn,'aa',0,0xffffffff,'val-aa')
534
+ push_a_vnode_stream(st, vn, nid)
535
+ # 論クロックが小さいので上書きされない
536
+ assert_equal(["55", "33", "11", "22", "44"], @rc.alist_to_s("aa")[1])
537
+
538
+ # 論理クロックを進める
539
+ 10.times{
540
+ st.set(vn,'aa',0,0xffffffff,'val-aa')
541
+ }
542
+ push_a_vnode_stream(st, vn, nid)
543
+ # 論クロックが大きいので上書きされる
544
+ assert_equal('val-aa', @rc.get("aa"))
545
+ end
546
+
547
+ def create_storage_and_calc_vn(k)
548
+ # calc vn
549
+ nid,d = @rc.rttable.search_node("aa")
550
+ vn = @rc.rttable.get_vnode_id(d)
551
+
552
+ st = Roma::Storage::TCMemStorage.new
553
+ st.vn_list = [vn]
554
+ st.storage_path = 'storage_test'
555
+ st.opendb
556
+
557
+ [st,nid,vn]
558
+ end
559
+ private :create_storage_and_calc_vn
560
+
561
+ def push_a_vnode_stream(st, vn, nid)
562
+ con = Roma::Messaging::ConPool.instance.get_connection(nid)
563
+ con.write("alist_spushv roma #{vn}\r\n")
564
+ res = con.gets
565
+ st.each_vn_dump(vn){|data|
566
+ con.write(data)
567
+ }
568
+ con.write("\0"*20) # end of steram
569
+ res = con.gets # STORED\r\n or error string
570
+ Roma::Messaging::ConPool.instance.return_connection(nid,con)
571
+ end
572
+ private :push_a_vnode_stream
573
+
574
+ end # ListPluginTest
575
+
576
+ class ListPluginTestForceForward < ListPluginTest
577
+ def setup
578
+ super
579
+ @rc.rttable.instance_eval{
580
+ undef search_node
581
+
582
+ def search_node(key); search_node2(key); end
583
+
584
+ def search_node2(key)
585
+ d = Digest::SHA1.hexdigest(key).hex % @hbits
586
+ @rd.v_idx[d & @search_mask][1]
587
+ end
588
+ }
589
+ end
590
+
591
+ undef test_alist_spushv
592
+ end