roma 0.8.2 → 0.8.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANG +326 -0
- data/CHANGELOG +132 -0
- data/{README.rdoc → FETCH_HEAD} +0 -0
- data/{LICENSE.rdoc → LICENSE} +0 -1
- data/README +17 -0
- data/Rakefile +33 -18
- data/ruby/server/bin/chg_redundancy +10 -0
- data/ruby/server/bin/key_access +7 -0
- data/ruby/server/bin/key_list +7 -0
- data/ruby/server/bin/mkconfig +19 -0
- data/{bin → ruby/server/bin}/mkrecent +0 -1
- data/{bin → ruby/server/bin}/mkroute +0 -1
- data/ruby/server/bin/multi_commander +19 -0
- data/ruby/server/bin/recoverlost +10 -0
- data/ruby/server/bin/recoverlost_alist +10 -0
- data/ruby/server/bin/recoverlost_alist_all +10 -0
- data/ruby/server/bin/recoverlost_alist_keys +10 -0
- data/{bin/recoverlost → ruby/server/bin/roma_watcher} +1 -2
- data/ruby/server/bin/romad +36 -0
- data/{bin → ruby/server/bin}/sample_watcher +0 -1
- data/{bin → ruby/server/bin}/sample_watcher2 +0 -1
- data/{bin/simple_bench → ruby/server/bin/sample_watcher3} +1 -2
- data/ruby/server/bin/simple_bench +26 -0
- data/{bin → ruby/server/bin}/ssroute +0 -1
- data/ruby/server/bin/test-scenario +11 -0
- data/{bin → ruby/server/bin}/tribunus +0 -1
- data/{lib → ruby/server/lib}/roma/async_process.rb +67 -15
- data/{lib → ruby/server/lib}/roma/command/bg_command_receiver.rb +1 -1
- data/ruby/server/lib/roma/command/command_definition.rb +422 -0
- data/ruby/server/lib/roma/command/mh_command_receiver.rb +127 -0
- data/ruby/server/lib/roma/command/receiver.rb +64 -0
- data/{lib → ruby/server/lib}/roma/command/rt_command_receiver.rb +6 -1
- data/ruby/server/lib/roma/command/sys_command_receiver.rb +609 -0
- data/{lib → ruby/server/lib}/roma/command/util_command_receiver.rb +15 -5
- data/{lib → ruby/server/lib}/roma/command/vn_command_receiver.rb +12 -4
- data/{lib → ruby/server/lib}/roma/command_plugin.rb +0 -0
- data/ruby/server/lib/roma/config.rb +84 -0
- data/{lib → ruby/server/lib}/roma/event/con_pool.rb +12 -1
- data/ruby/server/lib/roma/event/handler.rb +256 -0
- data/ruby/server/lib/roma/live_patch-20120302-001.rb +107 -0
- data/ruby/server/lib/roma/logging/rlogger.rb +163 -0
- data/ruby/server/lib/roma/messaging/con_pool.rb +92 -0
- data/{lib → ruby/server/lib}/roma/plugin/plugin_alist.rb +118 -240
- data/ruby/server/lib/roma/plugin/plugin_debug.rb +31 -0
- data/ruby/server/lib/roma/plugin/plugin_map.rb +177 -0
- data/ruby/server/lib/roma/plugin/plugin_mapcount.rb +185 -0
- data/{lib/roma/command/st_command_receiver.rb → ruby/server/lib/roma/plugin/plugin_storage.rb} +170 -146
- data/ruby/server/lib/roma/plugin/plugin_stub.rb +283 -0
- data/{lib → ruby/server/lib}/roma/plugin/plugin_test.rb +0 -0
- data/{lib → ruby/server/lib}/roma/romad.rb +221 -94
- data/{lib → ruby/server/lib}/roma/routing/cb_rttable.rb +4 -6
- data/{lib → ruby/server/lib}/roma/routing/merkle_tree.rb +0 -0
- data/ruby/server/lib/roma/routing/routing_data.rb +307 -0
- data/{lib → ruby/server/lib}/roma/routing/rttable.rb +4 -0
- data/{lib → ruby/server/lib}/roma/stats.rb +19 -3
- data/{lib → ruby/server/lib}/roma/storage/basic_storage.rb +25 -26
- data/{lib → ruby/server/lib}/roma/storage/dbm_storage.rb +1 -23
- data/{lib → ruby/server/lib}/roma/storage/dummy_storage.rb +0 -0
- data/{lib → ruby/server/lib}/roma/storage/rh_storage.rb +0 -0
- data/{lib → ruby/server/lib}/roma/storage/sqlite3_storage.rb +0 -0
- data/{lib → ruby/server/lib}/roma/storage/tc_storage.rb +62 -2
- data/ruby/server/lib/roma/tools/chg_redundancy.rb +36 -0
- data/ruby/server/lib/roma/tools/key_access.rb +105 -0
- data/ruby/server/lib/roma/tools/key_list.rb +94 -0
- data/ruby/server/lib/roma/tools/mkconfig.rb +535 -0
- data/{lib → ruby/server/lib}/roma/tools/mkrecent.rb +0 -0
- data/{lib → ruby/server/lib}/roma/tools/mkroute.rb +0 -0
- data/ruby/server/lib/roma/tools/multi_commander.rb +45 -0
- data/{lib → ruby/server/lib}/roma/tools/recoverlost.rb +0 -0
- data/{lib → ruby/server/lib}/roma/tools/recoverlost_alist.rb +0 -0
- data/ruby/server/lib/roma/tools/recoverlost_alist_all.rb +8 -0
- data/ruby/server/lib/roma/tools/recoverlost_alist_keys.rb +16 -0
- data/ruby/server/lib/roma/tools/recoverlost_lib.rb +349 -0
- data/ruby/server/lib/roma/tools/roma_watcher.rb +150 -0
- data/ruby/server/lib/roma/tools/roma_watcher_config.yml.example +20 -0
- data/{lib → ruby/server/lib}/roma/tools/sample_watcher.rb +3 -1
- data/{lib → ruby/server/lib}/roma/tools/sample_watcher2.rb +3 -1
- data/ruby/server/lib/roma/tools/sample_watcher3.rb +49 -0
- data/{lib → ruby/server/lib}/roma/tools/simple_bench.rb +2 -0
- data/ruby/server/lib/roma/tools/simple_bench2.rb +78 -0
- data/{lib → ruby/server/lib}/roma/tools/ssroute.rb +0 -0
- data/ruby/server/lib/roma/tools/test-scenario.rb +327 -0
- data/{lib → ruby/server/lib}/roma/tools/tribunus.rb +0 -0
- data/ruby/server/lib/roma/version.rb +4 -0
- data/{lib → ruby/server/lib}/roma/write_behind.rb +1 -0
- data/ruby/server/test/config4mhash.rb +68 -0
- data/ruby/server/test/config4storage_error.rb +69 -0
- data/{lib/roma/config.rb → ruby/server/test/config4test.rb} +6 -3
- data/{test → ruby/server/test}/rcirb.rb +0 -1
- data/{test → ruby/server/test}/roma-test-utils.rb +21 -8
- data/{test → ruby/server/test}/run-test.rb +3 -2
- data/ruby/server/test/storage_error_storage.rb +37 -0
- data/ruby/server/test/t_command_definition.rb +326 -0
- data/{test → ruby/server/test}/t_cpdata.rb +9 -3
- data/{test → ruby/server/test}/t_listplugin.rb +48 -12
- data/ruby/server/test/t_mapcountplugin.rb +231 -0
- data/ruby/server/test/t_mapplugin.rb +131 -0
- data/ruby/server/test/t_mhash.rb +222 -0
- data/ruby/server/test/t_rclient.rb +199 -0
- data/{test → ruby/server/test}/t_routing_data.rb +56 -0
- data/{test → ruby/server/test}/t_storage.rb +107 -111
- data/ruby/server/test/t_storage_error.rb +61 -0
- data/ruby/server/test/t_writebehind.rb +374 -0
- metadata +150 -82
- data/bin/recoverlost_alist +0 -8
- data/bin/romad +0 -7
- data/lib/roma/command/mh_command_receiver.rb +0 -117
- data/lib/roma/command/receiver.rb +0 -287
- data/lib/roma/event/handler.rb +0 -159
- data/lib/roma/plugin/plugin_debug.rb +0 -19
- data/lib/roma/tools/recoverlost_lib.rb +0 -217
- data/lib/roma/version.rb +0 -4
- data/test/t_rclient.rb +0 -318
- 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
|