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
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env ruby
2
+ require 'roma/client/rclient'
3
+ require 'roma/messaging/con_pool'
4
+ require 'roma/config'
5
+
6
+ Roma::Client::RomaClient.class_eval{
7
+ def init_sync_routing_proc
8
+ end
9
+ }
10
+
11
+ class MHashTest < Test::Unit::TestCase
12
+ include RomaTestUtils
13
+
14
+ def setup
15
+ start_roma 'config4mhash.rb'
16
+ @rc=Roma::Client::RomaClient.new(["localhost_11211","localhost_11212"])
17
+ end
18
+
19
+ def teardown
20
+ stop_roma
21
+ Roma::Messaging::ConPool::instance.close_all
22
+ rescue => e
23
+ puts "#{e} #{$@}"
24
+ end
25
+
26
+ def test_createhash
27
+ con = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
28
+ con.write("hashlist\r\n")
29
+ ret = con.gets
30
+ assert_equal("roma", ret.chomp )
31
+
32
+ con.write("createhash test\r\n")
33
+ ret = eval con.gets.chomp
34
+ assert_equal 2, ret.length
35
+ assert_equal 'CREATED', ret['localhost_11211']
36
+ assert_equal 'CREATED', ret['localhost_11212']
37
+
38
+ # file check
39
+ assert(File.directory? './localhost_11211/test')
40
+ assert(File.directory? './localhost_11212/test')
41
+
42
+ con.write("hashlist\r\n")
43
+ ret = con.gets
44
+ assert_equal("roma test", ret.chomp )
45
+
46
+ assert_equal("STORED", @rc.set("roma","hname=roma"))
47
+ assert_equal("hname=roma", @rc.get("roma"))
48
+ @rc.default_hash_name='test'
49
+ assert_nil( @rc.get("roma") )
50
+ assert_equal("STORED", @rc.set("roma","hname=test"))
51
+ assert_equal("hname=test", @rc.get("roma"))
52
+ @rc.default_hash_name='roma'
53
+ assert_equal("hname=roma", @rc.get("roma"))
54
+ assert_equal("DELETED", @rc.delete("roma"))
55
+
56
+ @rc.default_hash_name='not_exist_hash'
57
+ [:get, :delete, :incr, :decr].each do |m|
58
+ assert_raise(RuntimeError,'SERVER_ERROR not_exist_hash dose not exists.') do
59
+ @rc.send m, "key"
60
+ end
61
+ end
62
+
63
+ [:set, :add, :replace, :append, :prepend].each do |m|
64
+ assert_raise(RuntimeError,'SERVER_ERROR not_exist_hash dose not exists.') do
65
+ @rc.send m, "key","value"
66
+ end
67
+ end
68
+
69
+ # delete hash
70
+ con.write("deletehash test\r\n")
71
+ ret = eval con.gets.chomp
72
+ assert_equal 2, ret.length
73
+ assert_equal 'DELETED', ret['localhost_11211']
74
+ assert_equal 'DELETED', ret['localhost_11212']
75
+
76
+ con.close
77
+
78
+ # file check
79
+ assert( File.directory?('./localhost_11211/test') == false)
80
+ assert( File.directory?('./localhost_11212/test') == false)
81
+ end
82
+
83
+ def test_createhash2
84
+ # add 'test' hash
85
+ con = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
86
+ con.write("hashlist\r\n")
87
+ ret = con.gets
88
+ assert_equal("roma", ret.chomp)
89
+
90
+ con.write("createhash test\r\n")
91
+ ret = eval con.gets.chomp
92
+ assert_equal 2, ret.length
93
+ assert_equal 'CREATED', ret['localhost_11211']
94
+ assert_equal 'CREATED', ret['localhost_11212']
95
+
96
+ assert_equal("STORED", @rc.set("roma","hname=roma"))
97
+ assert_equal("hname=roma", @rc.get("roma"))
98
+ @rc.default_hash_name='test'
99
+ assert_equal("STORED", @rc.set("roma","hname=test"))
100
+ assert_equal("hname=test", @rc.get("roma"))
101
+
102
+ # stop roam
103
+ stop_roma
104
+
105
+ # restart roma
106
+ sleep 1
107
+ do_command_romad 'config4mhash.rb'
108
+ sleep 1
109
+
110
+ Roma::Messaging::ConPool.instance.close_all
111
+ Roma::Client::ConPool.instance.close_all
112
+
113
+ @rc=Roma::Client::RomaClient.new(["localhost_11211","localhost_11212"])
114
+
115
+ @rc.default_hash_name='test'
116
+ con = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
117
+ con.write("hashlist\r\n")
118
+ ret = con.gets
119
+
120
+ assert_equal("hname=test", @rc.get("roma"))
121
+ end
122
+
123
+ def test_createhash3
124
+ con = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
125
+
126
+ # delete hash to a nothing hash
127
+ con.write("deletehash test\r\n")
128
+ ret = eval con.gets.chomp
129
+ assert_equal 2, ret.length
130
+ assert_equal 'SERVER_ERROR test dose not exists.', ret['localhost_11211']
131
+ assert_equal 'SERVER_ERROR test dose not exists.', ret['localhost_11212']
132
+
133
+ # delete hash to default
134
+ con.write("deletehash roma\r\n")
135
+ ret = eval con.gets.chomp
136
+ assert_equal 2, ret.length
137
+ assert_equal "SERVER_ERROR default hash can't unmount.", ret['localhost_11211']
138
+ assert_equal "SERVER_ERROR default hash can't unmount.", ret['localhost_11212']
139
+ end
140
+
141
+ def test_defhash
142
+ con = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
143
+ con.write("defhash\r\n")
144
+ ret = eval con.gets.chomp
145
+ assert_equal 2, ret.length
146
+ assert_equal 'roma', ret['localhost_11212']
147
+ assert_equal 'roma', ret['localhost_11211']
148
+
149
+ con.write("rdefhash not_exist_hash\r\n")
150
+ ret = con.gets.chomp
151
+ assert_equal("CLIENT_ERROR not_exist_hash dose not find.", ret)
152
+
153
+ con.write("createhash test\r\n")
154
+ con.gets
155
+
156
+ con.write("rdefhash test\r\n")
157
+ ret = con.gets.chomp
158
+ assert_equal("STORED", ret)
159
+ end
160
+
161
+ def test_mounthash
162
+ con = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
163
+
164
+ # file check
165
+ assert( File.directory?('./localhost_11211/test') == false)
166
+ assert( File.directory?('./localhost_11212/test') == false)
167
+
168
+ # umount
169
+ con.write("umounthash test\r\n")
170
+ ret = con.gets.chomp
171
+ assert_equal("SERVER_ERROR test dose not find.", ret)
172
+
173
+ # add 'test' hash
174
+ con.write("createhash test\r\n")
175
+ ret = eval con.gets.chomp
176
+ assert_equal 2, ret.length
177
+ assert_equal 'CREATED', ret['localhost_11211']
178
+ assert_equal 'CREATED', ret['localhost_11212']
179
+
180
+ # file check
181
+ assert(File.directory? './localhost_11211/test')
182
+ assert(File.directory? './localhost_11212/test')
183
+
184
+ # umount
185
+ con.write("umounthash test\r\n")
186
+ ret = eval con.gets.chomp
187
+ assert_equal 2, ret.length
188
+ assert_equal 'UNMOUNTED', ret['localhost_11211']
189
+ assert_equal 'UNMOUNTED', ret['localhost_11212']
190
+
191
+ @rc.default_hash_name='test'
192
+ assert_raise(RuntimeError,'SERVER_ERROR test dose not exists.') do
193
+ @rc.set "key", "value"
194
+ end
195
+
196
+ # mount
197
+ con.write("mounthash test\r\n")
198
+ ret = eval con.gets.chomp
199
+ assert_equal 2, ret.length
200
+ assert_equal 'MOUNTED', ret['localhost_11211']
201
+ assert_equal 'MOUNTED', ret['localhost_11212']
202
+
203
+ assert_equal("STORED", @rc.set("key", "value"))
204
+ end
205
+ end
206
+
207
+ class MHashTestForward < RClientTest
208
+ def setup
209
+ super
210
+ @rc.rttable.instance_eval{
211
+ undef search_node
212
+
213
+ def search_node(key); search_node2(key); end
214
+
215
+ def search_node2(key)
216
+ d = Digest::SHA1.hexdigest(key).hex % @hbits
217
+ @rd.v_idx[d & @search_mask][1]
218
+ end
219
+ }
220
+ end
221
+
222
+ end
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'roma/client/rclient'
5
+ require 'roma/messaging/con_pool'
6
+ require 'roma/config'
7
+
8
+ Roma::Client::RomaClient.class_eval{
9
+ def init_sync_routing_proc
10
+ end
11
+ }
12
+
13
+ class RClientTest < Test::Unit::TestCase
14
+ include RomaTestUtils
15
+
16
+ def setup
17
+ start_roma
18
+ @rc=Roma::Client::RomaClient.new(["localhost_11211","localhost_11212"])
19
+ end
20
+
21
+ def teardown
22
+ stop_roma
23
+ Roma::Messaging::ConPool::instance.close_all
24
+ rescue => e
25
+ puts "#{e} #{$@}"
26
+ end
27
+
28
+ def test_set_expt_and_get
29
+ assert_equal("STORED", @rc.set("abc","value abc", 1))
30
+ assert_equal("value abc", @rc.get("abc"))
31
+ sleep 2
32
+ assert_nil( @rc.get("abc") )
33
+ end
34
+
35
+ def test_set_get_delete
36
+ @rc.delete("abc")
37
+ assert_nil( @rc.get("abc") )
38
+ assert_equal("STORED", @rc.set("abc","value abc"))
39
+ assert_equal("value abc", @rc.get("abc"))
40
+ assert_equal("STORED", @rc.set("abc","value abc")) # over write will be success
41
+ assert_equal("DELETED", @rc.delete("abc"))
42
+ assert_nil( @rc.get("abc"))
43
+ assert_equal("NOT_FOUND", @rc.delete("abc"))
44
+ end
45
+
46
+ def test_set_get
47
+ 10.times{|i|
48
+ s = i.to_s * 1024000
49
+ assert_equal("STORED", @rc.set("abc", s))
50
+ assert(s == @rc.get("abc"))
51
+ }
52
+ end
53
+
54
+ def test_cas
55
+ @rc.set("cnt", 1)
56
+ res = @rc.cas("cnt"){|v|
57
+ assert_equal(1, v)
58
+ v += 1
59
+ }
60
+ assert_equal("STORED", res)
61
+ assert_equal(2, @rc.get("cnt"))
62
+
63
+ res = @rc.cas("cnt"){|v|
64
+ res2 = @rc.cas("cnt"){|v2|
65
+ v += 2
66
+ }
67
+ assert_equal("STORED", res2)
68
+ v += 1
69
+ }
70
+ assert_equal("EXISTS", res)
71
+ assert_equal(4, @rc.get("cnt"))
72
+ end
73
+
74
+ def test_set_gets
75
+ keys = []
76
+ assert_equal(@rc.gets(["key-1","key-2"]).length,0)
77
+ 10.times{|i|
78
+ assert_equal("STORED", @rc.set("key-#{i}", "value-#{i}"))
79
+ keys << "key-#{i}"
80
+ }
81
+ ret = @rc.gets(keys)
82
+ assert_equal(ret.length,10)
83
+ ret.each_pair{|k,v|
84
+ assert_equal(k[-1],v[-1])
85
+ assert_equal(k[0..3],"key-")
86
+ assert_equal(v[0..5],"value-")
87
+ }
88
+ keys << "key-99"
89
+ ret = @rc.gets(keys)
90
+ assert_equal(ret.length,10)
91
+
92
+ assert_equal("DELETED", @rc.delete("key-5"))
93
+ ret = @rc.gets(keys)
94
+ assert_equal(ret.length,9)
95
+ end
96
+
97
+ def test_out
98
+ @rc.out("key-out")
99
+ # will return NOT_DELETED
100
+ assert_equal("NOT_DELETED", @rc.out("key-out"))
101
+ assert_equal("STORED", @rc.set("key-out","value out"))
102
+ assert_equal("DELETED", @rc.out("key-out"))
103
+ assert_equal("STORED", @rc.set("key-out","value out"))
104
+ # create a delete mark
105
+ assert_equal("DELETED", @rc.delete("key-out"))
106
+ # will return DELETED cause for delete mark
107
+ assert_equal("DELETED", @rc.out("key-out"))
108
+ end
109
+
110
+ def test_add
111
+ assert_nil( @rc.get("add") )
112
+ assert_equal("STORED", @rc.add("add","value add"))
113
+ assert_equal("NOT_STORED", @rc.add("add","value add")) # will fail
114
+ assert_equal("DELETED", @rc.delete("add"))
115
+ assert_equal("STORED", @rc.add("add","value add")) # will success add after delete
116
+ assert_equal("DELETED", @rc.delete("add"))
117
+ end
118
+
119
+ def test_replace
120
+ assert_nil( @rc.get("replace") )
121
+ assert_equal("NOT_STORED", @rc.replace("replace","value replace"))
122
+ assert_nil( @rc.get("replace") )
123
+ assert_equal("STORED", @rc.add("replace","value add"))
124
+ assert_equal("STORED", @rc.replace("replace","value replace"))
125
+ assert_equal("DELETED", @rc.delete("replace"))
126
+ end
127
+
128
+ def test_append
129
+ assert_nil( @rc.get("append") )
130
+ assert_equal("NOT_STORED", @rc.append("append","append"))
131
+ assert_equal("STORED", @rc.set("append","set",0,true))
132
+ assert_equal("set", @rc.get("append",true))
133
+ assert_equal("STORED", @rc.append("append","append"))
134
+ assert_equal("setappend", @rc.get("append",true))
135
+ assert_equal("DELETED", @rc.delete("append"))
136
+ end
137
+
138
+ def test_prepend
139
+ assert_nil( @rc.get("prepend"))
140
+ assert_equal("NOT_STORED", @rc.prepend("prepend","prepend"))
141
+ assert_equal("STORED", @rc.set("prepend","set",0,true))
142
+ assert_equal("set", @rc.get("prepend",true))
143
+ assert_equal("STORED", @rc.prepend("prepend","prepend"))
144
+ assert_equal("prependset", @rc.get("prepend",true))
145
+ assert_equal("DELETED", @rc.delete("prepend"))
146
+ end
147
+
148
+ def test_incr
149
+ assert_nil( @rc.get("incr"))
150
+ assert_equal("NOT_FOUND", @rc.incr("incr"))
151
+ assert_equal("STORED", @rc.set("incr","100",0,true))
152
+ assert_equal(101, @rc.incr("incr"))
153
+ assert_equal(102, @rc.incr("incr"))
154
+ assert_equal("DELETED", @rc.delete("incr"))
155
+ end
156
+
157
+ def test_decr
158
+ assert_nil( @rc.get("decr") )
159
+ assert_equal("NOT_FOUND", @rc.decr("decr"))
160
+ assert_equal("STORED", @rc.set("decr","100",0,true))
161
+ assert_equal(99, @rc.decr("decr"))
162
+ assert_equal(98, @rc.decr("decr"))
163
+ assert_equal("DELETED", @rc.delete("decr"))
164
+ end
165
+
166
+ def test_routingdump_bin
167
+ con = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
168
+ con.write("routingdump bin\r\n")
169
+ len = con.gets
170
+ bin = con.read(len.to_i)
171
+ con.gets
172
+ con.close
173
+
174
+ magic, ver, dgst_bits, div_bits, rn, nodeslen = bin.unpack('a2nCCCn')
175
+ assert_equal('RT', magic)
176
+ assert_equal(1, ver)
177
+ assert_equal(32, dgst_bits)
178
+ assert_equal(3, div_bits)
179
+ assert_equal(2, rn)
180
+ assert_equal(2, nodeslen)
181
+ end
182
+ end
183
+
184
+ class RClientTestForceForward < RClientTest
185
+ def setup
186
+ super
187
+ @rc.rttable.instance_eval{
188
+ undef search_node
189
+
190
+ def search_node(key); search_node2(key); end
191
+
192
+ def search_node2(key)
193
+ d = Digest::SHA1.hexdigest(key).hex % @hbits
194
+ @rd.v_idx[d & @search_mask][1]
195
+ end
196
+ }
197
+ end
198
+
199
+ end
@@ -97,4 +97,60 @@ class RoutingDataTest < Test::Unit::TestCase
97
97
  assert( (c1-c2).abs < rd.v_idx.length/10 )
98
98
  end
99
99
 
100
+ def test_dump_binary
101
+ rd=Roma::Routing::RoutingData.create(32,9,2,['roma0_3300','roma1_3300'])
102
+ # set to a bummy clock
103
+ (2**rd.div_bits).times{|i|
104
+ vn=i<<(rd.dgst_bits-rd.div_bits)
105
+ rd.v_clk[vn] = i
106
+ }
107
+
108
+ bin = rd.dump_binary
109
+ # puts bin.length
110
+
111
+ magic, ver, dgst_bits, div_bits, rn, nodeslen = bin.unpack('a2nCCCn')
112
+ assert_equal('RT', magic)
113
+ assert_equal(1, ver)
114
+ assert_equal(rd.dgst_bits, dgst_bits)
115
+ assert_equal(rd.div_bits, div_bits)
116
+ assert_equal(rd.rn, rn)
117
+ assert_equal(rd.nodes.length, nodeslen)
118
+ bin = bin[9..-1]
119
+ nodeslen.times{|i|
120
+ len, = bin.unpack('n')
121
+ bin = bin[2..-1]
122
+ nid, = bin.unpack("a#{len}")
123
+ bin = bin[len..-1]
124
+ assert_equal(rd.nodes[i], nid)
125
+ }
126
+ (2**div_bits).times{|i|
127
+ vn=i<<(dgst_bits-div_bits)
128
+ v_clk,len = bin.unpack('Nc')
129
+ assert_equal(i, rd.v_clk[vn])
130
+ assert_equal(rd.v_idx[vn].length, len)
131
+ # puts "#{i} #{vn} #{v_clk} #{len}"
132
+ bin = bin[5..-1]
133
+ len.times{|i|
134
+ idx, = bin.unpack('n')
135
+ assert_equal(rd.nodes[idx], rd.v_idx[vn][i])
136
+ bin = bin[2..-1]
137
+ # puts rd.nodes[idx]
138
+ }
139
+ }
140
+ assert_equal(0, bin.length)
141
+ end
142
+
143
+ def test_dump_binary2
144
+ rd=Roma::Routing::RoutingData.create(32,9,2,['roma0_3300','roma1_3300'])
145
+ # set to a bummy clock
146
+ (2**rd.div_bits).times{|i|
147
+ vn=i<<(rd.dgst_bits-rd.div_bits)
148
+ rd.v_clk[vn] = i
149
+ }
150
+
151
+ bin = rd.dump_binary
152
+ bin2 = Roma::Routing::RoutingData.decode_binary(bin).dump_binary
153
+
154
+ assert_equal(bin, bin2)
155
+ end
100
156
  end