roma 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG +21 -0
- data/Gemfile.lock +47 -0
- data/bin/check_tc_flag +39 -0
- data/bin/roma-adm +43 -0
- data/bin/ssroute +0 -3
- data/lib/roma/async_process.rb +203 -208
- data/lib/roma/command/sys_command_receiver.rb +52 -10
- data/lib/roma/config.rb +3 -0
- data/lib/roma/event/handler.rb +11 -4
- data/lib/roma/event/jaro_winkler.rb +23 -0
- data/lib/roma/event/levenshtein.rb +23 -0
- data/lib/roma/plugin/plugin_cmd_aliases.rb +1 -32
- data/lib/roma/romad.rb +23 -0
- data/lib/roma/routing/cb_rttable.rb +2 -0
- data/lib/roma/routing/random_partitioner.rb +43 -36
- data/lib/roma/routing/rttable.rb +5 -3
- data/lib/roma/stats.rb +4 -1
- data/lib/roma/tools/check_tc_flag.rb +25 -0
- data/lib/roma/tools/cpdb.rb +3 -2
- data/lib/roma/tools/mkconfig.rb +22 -13
- data/lib/roma/tools/roma-adm.rb +82 -0
- data/lib/roma/version.rb +1 -1
- data/test/config4mhash.rb +2 -0
- data/test/config4storage_error.rb +2 -0
- data/test/config4test.rb +2 -0
- data/test/cpdbtest/config4cpdb_base.rb +67 -0
- data/test/cpdbtest/config4cpdb_dbm.rb +9 -0
- data/test/cpdbtest/config4cpdb_groonga.rb +9 -0
- data/test/cpdbtest/config4cpdb_rh.rb +9 -0
- data/test/cpdbtest/config4cpdb_sqlite3.rb +9 -0
- data/test/cpdbtest/config4cpdb_tc.rb +9 -0
- data/test/cpdbtest/config4cpdb_tcmem.rb +9 -0
- data/test/roma-test-utils.rb +140 -40
- data/test/t_cpdata.rb +76 -80
- data/test/t_cpdb.rb +95 -0
- data/test/t_logshift.rb +86 -0
- data/test/t_mhash.rb +56 -54
- data/test/t_routing_logic.rb +121 -0
- data/test/t_writebehind.rb +202 -207
- metadata +25 -8
- data/bin/tc_data_restore.rb +0 -123
data/test/t_mhash.rb
CHANGED
@@ -3,31 +3,31 @@ require 'roma/client/rclient'
|
|
3
3
|
require 'roma/messaging/con_pool'
|
4
4
|
require 'roma/config'
|
5
5
|
|
6
|
-
Roma::Client::RomaClient.class_eval
|
6
|
+
Roma::Client::RomaClient.class_eval do
|
7
7
|
def init_sync_routing_proc
|
8
8
|
end
|
9
|
-
|
9
|
+
end
|
10
10
|
|
11
11
|
class MHashTest < Test::Unit::TestCase
|
12
12
|
include RomaTestUtils
|
13
13
|
|
14
14
|
def setup
|
15
15
|
start_roma 'config4mhash.rb'
|
16
|
-
@rc=Roma::Client::RomaClient.new(
|
16
|
+
@rc = Roma::Client::RomaClient.new(%w(localhost_11211 localhost_11212))
|
17
17
|
end
|
18
18
|
|
19
19
|
def teardown
|
20
20
|
stop_roma
|
21
|
-
Roma::Messaging::ConPool
|
21
|
+
Roma::Messaging::ConPool.instance.close_all
|
22
22
|
rescue => e
|
23
|
-
|
23
|
+
puts "#{e} #{$ERROR_POSITION}"
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_createhash
|
27
|
-
con = Roma::Messaging::ConPool.instance.get_connection(
|
27
|
+
con = Roma::Messaging::ConPool.instance.get_connection('localhost_11211')
|
28
28
|
con.write("hashlist\r\n")
|
29
29
|
ret = con.gets
|
30
|
-
assert_equal(
|
30
|
+
assert_equal('roma', ret.chomp)
|
31
31
|
|
32
32
|
con.write("createhash test\r\n")
|
33
33
|
ret = eval con.gets.chomp
|
@@ -41,28 +41,28 @@ class MHashTest < Test::Unit::TestCase
|
|
41
41
|
|
42
42
|
con.write("hashlist\r\n")
|
43
43
|
ret = con.gets
|
44
|
-
assert_equal(
|
45
|
-
|
46
|
-
assert_equal(
|
47
|
-
assert_equal(
|
48
|
-
@rc.default_hash_name='test'
|
49
|
-
assert_nil(
|
50
|
-
assert_equal(
|
51
|
-
assert_equal(
|
52
|
-
@rc.default_hash_name='roma'
|
53
|
-
assert_equal(
|
54
|
-
assert_equal(
|
55
|
-
|
56
|
-
@rc.default_hash_name='not_exist_hash'
|
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
57
|
[:get, :delete, :incr, :decr].each do |m|
|
58
|
-
assert_raise(RuntimeError,'SERVER_ERROR not_exist_hash does not exists.') do
|
59
|
-
@rc.send m,
|
58
|
+
assert_raise(RuntimeError, 'SERVER_ERROR not_exist_hash does not exists.') do
|
59
|
+
@rc.send m, 'key'
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
[:set, :add, :replace, :append, :prepend].each do |m|
|
64
|
-
assert_raise(RuntimeError,'SERVER_ERROR not_exist_hash does not exists.') do
|
65
|
-
@rc.send m,
|
64
|
+
assert_raise(RuntimeError, 'SERVER_ERROR not_exist_hash does not exists.') do
|
65
|
+
@rc.send m, 'key', 'value'
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -76,16 +76,16 @@ class MHashTest < Test::Unit::TestCase
|
|
76
76
|
con.close
|
77
77
|
|
78
78
|
# file check
|
79
|
-
assert(
|
80
|
-
assert(
|
79
|
+
assert(File.directory?('./localhost_11211/test') == false)
|
80
|
+
assert(File.directory?('./localhost_11212/test') == false)
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_createhash2
|
84
84
|
# add 'test' hash
|
85
|
-
con = Roma::Messaging::ConPool.instance.get_connection(
|
85
|
+
con = Roma::Messaging::ConPool.instance.get_connection('localhost_11211')
|
86
86
|
con.write("hashlist\r\n")
|
87
87
|
ret = con.gets
|
88
|
-
assert_equal(
|
88
|
+
assert_equal('roma', ret.chomp)
|
89
89
|
|
90
90
|
con.write("createhash test\r\n")
|
91
91
|
ret = eval con.gets.chomp
|
@@ -93,35 +93,37 @@ class MHashTest < Test::Unit::TestCase
|
|
93
93
|
assert_equal 'CREATED', ret['localhost_11211']
|
94
94
|
assert_equal 'CREATED', ret['localhost_11212']
|
95
95
|
|
96
|
-
assert_equal(
|
97
|
-
assert_equal(
|
98
|
-
@rc.default_hash_name='test'
|
99
|
-
assert_equal(
|
100
|
-
assert_equal(
|
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
101
|
|
102
102
|
# stop roam
|
103
103
|
stop_roma
|
104
104
|
|
105
105
|
# restart roma
|
106
106
|
sleep 1
|
107
|
-
|
107
|
+
DEFAULT_NODES.each do |node|
|
108
|
+
do_command_romad(node, 'config4mhash.rb')
|
109
|
+
end
|
108
110
|
sleep 1
|
109
111
|
|
110
112
|
Roma::Messaging::ConPool.instance.close_all
|
111
113
|
Roma::Client::ConPool.instance.close_all
|
112
114
|
|
113
|
-
@rc=Roma::Client::RomaClient.new(
|
114
|
-
|
115
|
-
@rc.default_hash_name='test'
|
116
|
-
con = Roma::Messaging::ConPool.instance.get_connection(
|
115
|
+
@rc = Roma::Client::RomaClient.new(%w(localhost_11211 localhost_11212))
|
116
|
+
|
117
|
+
@rc.default_hash_name = 'test'
|
118
|
+
con = Roma::Messaging::ConPool.instance.get_connection('localhost_11211')
|
117
119
|
con.write("hashlist\r\n")
|
118
120
|
ret = con.gets
|
119
121
|
|
120
|
-
assert_equal(
|
122
|
+
assert_equal('hname=test', @rc.get('roma'))
|
121
123
|
end
|
122
|
-
|
124
|
+
|
123
125
|
def test_createhash3
|
124
|
-
con = Roma::Messaging::ConPool.instance.get_connection(
|
126
|
+
con = Roma::Messaging::ConPool.instance.get_connection('localhost_11211')
|
125
127
|
|
126
128
|
# delete hash to a nothing hash
|
127
129
|
con.write("deletehash test\r\n")
|
@@ -129,7 +131,7 @@ class MHashTest < Test::Unit::TestCase
|
|
129
131
|
assert_equal 2, ret.length
|
130
132
|
assert_equal 'SERVER_ERROR test does not exists.', ret['localhost_11211']
|
131
133
|
assert_equal 'SERVER_ERROR test does not exists.', ret['localhost_11212']
|
132
|
-
|
134
|
+
|
133
135
|
# delete hash to default
|
134
136
|
con.write("deletehash roma\r\n")
|
135
137
|
ret = eval con.gets.chomp
|
@@ -139,36 +141,36 @@ class MHashTest < Test::Unit::TestCase
|
|
139
141
|
end
|
140
142
|
|
141
143
|
def test_defhash
|
142
|
-
con = Roma::Messaging::ConPool.instance.get_connection(
|
144
|
+
con = Roma::Messaging::ConPool.instance.get_connection('localhost_11211')
|
143
145
|
con.write("defhash\r\n")
|
144
146
|
ret = eval con.gets.chomp
|
145
147
|
assert_equal 2, ret.length
|
146
148
|
assert_equal 'roma', ret['localhost_11212']
|
147
149
|
assert_equal 'roma', ret['localhost_11211']
|
148
|
-
|
150
|
+
|
149
151
|
con.write("rdefhash not_exist_hash\r\n")
|
150
152
|
ret = con.gets.chomp
|
151
|
-
assert_equal(
|
153
|
+
assert_equal('CLIENT_ERROR not_exist_hash does not find.', ret)
|
152
154
|
|
153
155
|
con.write("createhash test\r\n")
|
154
156
|
con.gets
|
155
157
|
|
156
158
|
con.write("rdefhash test\r\n")
|
157
159
|
ret = con.gets.chomp
|
158
|
-
assert_equal(
|
160
|
+
assert_equal('STORED', ret)
|
159
161
|
end
|
160
162
|
|
161
163
|
def test_mounthash
|
162
|
-
con = Roma::Messaging::ConPool.instance.get_connection(
|
164
|
+
con = Roma::Messaging::ConPool.instance.get_connection('localhost_11211')
|
163
165
|
|
164
166
|
# file check
|
165
|
-
assert(
|
166
|
-
assert(
|
167
|
+
assert(File.directory?('./localhost_11211/test') == false)
|
168
|
+
assert(File.directory?('./localhost_11212/test') == false)
|
167
169
|
|
168
170
|
# umount
|
169
171
|
con.write("umounthash test\r\n")
|
170
172
|
ret = con.gets.chomp
|
171
|
-
assert_equal(
|
173
|
+
assert_equal('SERVER_ERROR test does not find.', ret)
|
172
174
|
|
173
175
|
# add 'test' hash
|
174
176
|
con.write("createhash test\r\n")
|
@@ -188,9 +190,9 @@ class MHashTest < Test::Unit::TestCase
|
|
188
190
|
assert_equal 'UNMOUNTED', ret['localhost_11211']
|
189
191
|
assert_equal 'UNMOUNTED', ret['localhost_11212']
|
190
192
|
|
191
|
-
@rc.default_hash_name='test'
|
192
|
-
assert_raise(RuntimeError,'SERVER_ERROR test does not exists.') do
|
193
|
-
@rc.set
|
193
|
+
@rc.default_hash_name = 'test'
|
194
|
+
assert_raise(RuntimeError, 'SERVER_ERROR test does not exists.') do
|
195
|
+
@rc.set 'key', 'value'
|
194
196
|
end
|
195
197
|
|
196
198
|
# mount
|
@@ -200,6 +202,6 @@ class MHashTest < Test::Unit::TestCase
|
|
200
202
|
assert_equal 'MOUNTED', ret['localhost_11211']
|
201
203
|
assert_equal 'MOUNTED', ret['localhost_11212']
|
202
204
|
|
203
|
-
assert_equal(
|
205
|
+
assert_equal('STORED', @rc.set('key', 'value'))
|
204
206
|
end
|
205
207
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class RoutingLogicTest < Test::Unit::TestCase
|
4
|
+
include RomaTestUtils
|
5
|
+
|
6
|
+
NEW_PORTS = %w(11213 11214)
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
stop_roma
|
10
|
+
rescue => e
|
11
|
+
puts "#{e} #{$ERROR_POSITION}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_join_single_host
|
15
|
+
join_test(true, NEW_PORTS.map { |port| "#{DEFAULT_HOST}_#{port}" })
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_join_multiple_hosts
|
19
|
+
join_test(false, NEW_PORTS.map { |port| "#{DEFAULT_IP}_#{port}" })
|
20
|
+
end
|
21
|
+
|
22
|
+
def multiple_hosts_include_some_hosts
|
23
|
+
join_test(false, ["#{DEFAULT_IP}_#{NEW_PORTS[0]}", "#{DEFAULT_HOST}_#{NEW_PORTS[1]}"])
|
24
|
+
end
|
25
|
+
|
26
|
+
def join_test(replication_in_host, new_nodes)
|
27
|
+
start_roma(div_bits: 6, replication_in_host: replication_in_host)
|
28
|
+
sleep 12 # Wait cluster starting, otherwise join will never finish
|
29
|
+
client = get_client
|
30
|
+
|
31
|
+
# Join nodes
|
32
|
+
assert_equal(DEFAULT_NODES.size, client.rttable.nodes.size)
|
33
|
+
new_nodes.each do |new_node|
|
34
|
+
join_roma(new_node, replication_in_host: replication_in_host)
|
35
|
+
wait_join(new_node)
|
36
|
+
stats = client.stats(node: new_node)
|
37
|
+
assert_match(/#{new_node}/, stats['routing.nodes'])
|
38
|
+
assert_not_equal(0, stats['routing.secondary1'].to_i)
|
39
|
+
end
|
40
|
+
|
41
|
+
new_node = new_nodes.last
|
42
|
+
|
43
|
+
# Release and stop a node
|
44
|
+
release_roma_node(new_node)
|
45
|
+
wait_release(new_node)
|
46
|
+
stop_roma_node(new_node)
|
47
|
+
wait_failover(new_node)
|
48
|
+
stats = client.stats
|
49
|
+
assert_no_match(/#{new_node}/, stats['routing.nodes'])
|
50
|
+
assert_equal(0, stats['routing.short_vnodes'].to_i)
|
51
|
+
|
52
|
+
# Join a node without short vnodes
|
53
|
+
join_roma(new_node, replication_in_host: replication_in_host)
|
54
|
+
wait_join(new_node)
|
55
|
+
stats = client.stats(node: new_node)
|
56
|
+
assert_match(/#{new_node}/, stats['routing.nodes'])
|
57
|
+
assert_not_equal(0, stats['routing.secondary1'].to_i)
|
58
|
+
|
59
|
+
# Stop a node and generate short vnodes
|
60
|
+
stop_roma_node(new_node)
|
61
|
+
wait_failover(new_node)
|
62
|
+
stats = client.stats
|
63
|
+
assert_no_match(/#{new_node}/, stats['routing.nodes'])
|
64
|
+
assert_not_equal(0, stats['routing.short_vnodes'].to_i)
|
65
|
+
|
66
|
+
# Join a node with short vnodes
|
67
|
+
join_roma(new_node, replication_in_host: replication_in_host)
|
68
|
+
wait_join(new_node)
|
69
|
+
stats = client.stats(node: new_node)
|
70
|
+
assert_match(/#{new_node}/, stats['routing.nodes'])
|
71
|
+
assert_not_equal(0, stats['routing.secondary1'].to_i)
|
72
|
+
end
|
73
|
+
private :join_test
|
74
|
+
|
75
|
+
def test_routing_logic_join_when_num_of_hosts_changing
|
76
|
+
replication_in_host = false
|
77
|
+
same_host_node = "#{DEFAULT_HOST}_#{NEW_PORTS[0]}"
|
78
|
+
other_host_node = "#{DEFAULT_IP}_#{NEW_PORTS[1]}"
|
79
|
+
|
80
|
+
start_roma(div_bits: 6, replication_in_host: replication_in_host)
|
81
|
+
sleep 12 # Wait cluster starting, otherwise join will never finish
|
82
|
+
client = get_client
|
83
|
+
|
84
|
+
# Join other_host_node
|
85
|
+
join_roma(other_host_node, replication_in_host: replication_in_host)
|
86
|
+
wait_join(other_host_node)
|
87
|
+
stats = client.stats(node: other_host_node)
|
88
|
+
assert_match(/#{other_host_node}/, stats['routing.nodes'])
|
89
|
+
assert_not_equal(0, stats['routing.secondary1'].to_i)
|
90
|
+
|
91
|
+
# Stop other_host_node and generate short vnodes
|
92
|
+
stop_roma_node(other_host_node)
|
93
|
+
wait_failover(other_host_node)
|
94
|
+
stats = client.stats
|
95
|
+
assert_no_match(/#{other_host_node}/, stats['routing.nodes'])
|
96
|
+
assert_not_equal(0, stats['routing.short_vnodes'].to_i)
|
97
|
+
|
98
|
+
# Join other_host_node
|
99
|
+
join_roma(other_host_node, replication_in_host: replication_in_host)
|
100
|
+
wait_join(other_host_node)
|
101
|
+
stats = client.stats(node: other_host_node)
|
102
|
+
assert_match(/#{other_host_node}/, stats['routing.nodes'])
|
103
|
+
assert_not_equal(0, stats['routing.secondary1'].to_i)
|
104
|
+
|
105
|
+
# Stop other_host_node and generate short vnodes
|
106
|
+
stop_roma_node(other_host_node)
|
107
|
+
wait_failover(other_host_node)
|
108
|
+
stats = client.stats
|
109
|
+
assert_no_match(/#{other_host_node}/, stats['routing.nodes'])
|
110
|
+
assert_not_equal(0, stats['routing.short_vnodes'].to_i)
|
111
|
+
|
112
|
+
# Join same_host_node (secondary will be 0 in this case)
|
113
|
+
join_roma(same_host_node, replication_in_host: replication_in_host)
|
114
|
+
wait_join(same_host_node)
|
115
|
+
stats = client.stats(node: same_host_node)
|
116
|
+
assert_match(/#{same_host_node}/, stats['routing.nodes'])
|
117
|
+
assert_equal(0, stats['routing.secondary1'].to_i)
|
118
|
+
end
|
119
|
+
|
120
|
+
# TODO: recover, balance command tests
|
121
|
+
end
|
data/test/t_writebehind.rb
CHANGED
@@ -8,49 +8,48 @@ require 'roma/client/plugin/alist'
|
|
8
8
|
require 'roma/client/plugin/map'
|
9
9
|
|
10
10
|
module FileWriterTests
|
11
|
-
|
12
11
|
# making and writing test
|
13
12
|
def test_wb_write
|
14
13
|
system('rm -rf wb_test')
|
15
|
-
fw = Roma::WriteBehind::FileWriter.new(
|
14
|
+
fw = Roma::WriteBehind::FileWriter.new('wb_test', 1024 * 1024, Logger.new(nil))
|
16
15
|
path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
|
17
16
|
|
18
17
|
assert(!File.exist?("#{path}/0.wb"))
|
19
|
-
100.times
|
20
|
-
fw.write('roma',i,"key-#{i}","val-#{i}")
|
21
|
-
|
18
|
+
100.times do |i|
|
19
|
+
fw.write('roma', i, "key-#{i}", "val-#{i}")
|
20
|
+
end
|
22
21
|
assert(File.exist?("#{path}/0.wb"))
|
23
22
|
assert(!File.exist?("#{path}/1.wb"))
|
24
23
|
|
25
24
|
fw.rotate('roma')
|
26
25
|
|
27
26
|
i = 100
|
28
|
-
fw.write('roma',i,"key-#{i}","val-#{i}")
|
27
|
+
fw.write('roma', i, "key-#{i}", "val-#{i}")
|
29
28
|
assert(File.exist?("#{path}/1.wb"))
|
30
29
|
|
31
30
|
fw.close_all
|
32
31
|
|
33
32
|
wb0 = read_wb("#{path}/0.wb")
|
34
|
-
assert_equal(100,wb0.length
|
35
|
-
wb0.each
|
36
|
-
assert_equal(
|
37
|
-
assert_equal(
|
38
|
-
|
33
|
+
assert_equal(100, wb0.length)
|
34
|
+
wb0.each do |_last, cmd, key, val|
|
35
|
+
assert_equal("key-#{cmd}", key)
|
36
|
+
assert_equal("val-#{cmd}", val)
|
37
|
+
end
|
39
38
|
wb1 = read_wb("#{path}/1.wb")
|
40
|
-
assert_equal(1,wb1.length
|
39
|
+
assert_equal(1, wb1.length)
|
41
40
|
end
|
42
41
|
|
43
42
|
# rotation test per data
|
44
43
|
def test_wb_rotation
|
45
44
|
system('rm -rf wb_test')
|
46
|
-
fw = Roma::WriteBehind::FileWriter.new(
|
45
|
+
fw = Roma::WriteBehind::FileWriter.new('wb_test', 900, Logger.new(nil))
|
47
46
|
path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
|
48
47
|
|
49
|
-
100.times
|
50
|
-
fw.write('roma',0,
|
51
|
-
sprintf(
|
52
|
-
sprintf(
|
53
|
-
|
48
|
+
100.times do |i|
|
49
|
+
fw.write('roma', 0,
|
50
|
+
sprintf('key-%04d', i),
|
51
|
+
sprintf('val-%04d', i))
|
52
|
+
end
|
54
53
|
|
55
54
|
assert(File.exist?("#{path}/0.wb"))
|
56
55
|
assert(File.exist?("#{path}/1.wb"))
|
@@ -62,60 +61,60 @@ module FileWriterTests
|
|
62
61
|
# rotation test per time
|
63
62
|
def test_rotation2
|
64
63
|
system('rm -rf wb_test')
|
65
|
-
fw = Roma::WriteBehind::FileWriter.new(
|
64
|
+
fw = Roma::WriteBehind::FileWriter.new('wb_test', 1024 * 1024, Logger.new(nil))
|
66
65
|
path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
|
67
66
|
|
68
67
|
# rottime's usec have some value,from instance was created
|
69
|
-
rt = fw.instance_eval{ @rottime }
|
70
|
-
assert_not_equal(0, rt.hour + rt.min + rt.sec+ rt.usec)
|
68
|
+
rt = fw.instance_eval { @rottime }
|
69
|
+
assert_not_equal(0, rt.hour + rt.min + rt.sec + rt.usec)
|
71
70
|
# formatting execute in today's date
|
72
71
|
assert_equal(Time.now.day, rt.day)
|
73
72
|
# confirming the file do not exist
|
74
73
|
assert(!File.exist?("#{path}/0.wb"))
|
75
|
-
fw.write('roma',1,
|
74
|
+
fw.write('roma', 1, 'key', 'val')
|
76
75
|
# Open when somenthing to write,and in same timing rottime is updated
|
77
|
-
rt = fw.instance_eval{ @rottime }
|
76
|
+
rt = fw.instance_eval { @rottime }
|
78
77
|
# In this time, under of date become "0"
|
79
|
-
assert_equal(0, rt.hour + rt.min + rt.sec+ rt.usec)
|
78
|
+
assert_equal(0, rt.hour + rt.min + rt.sec + rt.usec)
|
80
79
|
# date become tomorrow
|
81
80
|
assert_not_equal(Time.now.day, rt.day)
|
82
|
-
10.times
|
83
|
-
fw.write('roma',i,"key-#{i}","val-#{i}")
|
84
|
-
|
81
|
+
10.times do |i|
|
82
|
+
fw.write('roma', i, "key-#{i}", "val-#{i}")
|
83
|
+
end
|
85
84
|
# confirming file is only 1 not over 2
|
86
85
|
assert(File.exist?("#{path}/0.wb"))
|
87
86
|
assert(!File.exist?("#{path}/1.wb"))
|
88
87
|
|
89
88
|
# set rottime to now forcibly
|
90
|
-
fw.instance_eval{ @rottime=Time.now }
|
89
|
+
fw.instance_eval { @rottime = Time.now }
|
91
90
|
# confriming to change rottime
|
92
|
-
assert_not_equal(rt, fw.instance_eval{ @rottime })
|
91
|
+
assert_not_equal(rt, fw.instance_eval { @rottime })
|
93
92
|
# When something write, rotation is occured
|
94
|
-
fw.write('roma',1,
|
93
|
+
fw.write('roma', 1, 'key', 'val')
|
95
94
|
assert(File.exist?("#{path}/1.wb"))
|
96
95
|
# rottime turn back because of test shold not step over the day.
|
97
|
-
assert_equal(rt, fw.instance_eval{ @rottime })
|
96
|
+
assert_equal(rt, fw.instance_eval { @rottime })
|
98
97
|
end
|
99
98
|
|
100
99
|
# rotation test from outside
|
101
100
|
def test_wb_rotation3
|
102
101
|
system('rm -rf wb_test')
|
103
|
-
fw = Roma::WriteBehind::FileWriter.new(
|
102
|
+
fw = Roma::WriteBehind::FileWriter.new('wb_test', 1024 * 1024, Logger.new(nil))
|
104
103
|
path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
|
105
104
|
|
106
105
|
# confirming file don't exist
|
107
106
|
assert(!File.exist?("#{path}/0.wb"))
|
108
|
-
10.times
|
109
|
-
fw.write('roma',i,"key-#{i}","val-#{i}")
|
110
|
-
|
107
|
+
10.times do |i|
|
108
|
+
fw.write('roma', i, "key-#{i}", "val-#{i}")
|
109
|
+
end
|
111
110
|
# confirming file is only 1 not over 2
|
112
111
|
assert(File.exist?("#{path}/0.wb"))
|
113
112
|
assert(!File.exist?("#{path}/1.wb"))
|
114
113
|
|
115
114
|
fw.rotate('roma')
|
116
|
-
10.times
|
117
|
-
fw.write('roma',i,"key-#{i}","val-#{i}")
|
118
|
-
|
115
|
+
10.times do |i|
|
116
|
+
fw.write('roma', i, "key-#{i}", "val-#{i}")
|
117
|
+
end
|
119
118
|
# confirming files are 2 not over 3
|
120
119
|
assert(File.exist?("#{path}/0.wb"))
|
121
120
|
assert(File.exist?("#{path}/1.wb"))
|
@@ -129,9 +128,9 @@ module FileWriterTests
|
|
129
128
|
assert(File.exist?("#{path}/0.wb"))
|
130
129
|
assert(File.exist?("#{path}/1.wb"))
|
131
130
|
assert(!File.exist?("#{path}/2.wb"))
|
132
|
-
10.times
|
133
|
-
fw.write('roma',i,"key-#{i}","val-#{i}")
|
134
|
-
|
131
|
+
10.times do |i|
|
132
|
+
fw.write('roma', i, "key-#{i}", "val-#{i}")
|
133
|
+
end
|
135
134
|
# confirming files are 3 not over 4
|
136
135
|
assert(File.exist?("#{path}/0.wb"))
|
137
136
|
assert(File.exist?("#{path}/1.wb"))
|
@@ -139,48 +138,46 @@ module FileWriterTests
|
|
139
138
|
assert(!File.exist?("#{path}/3.wb"))
|
140
139
|
end
|
141
140
|
|
142
|
-
|
143
141
|
def test_wb_get_current_file_path
|
144
142
|
system('rm -rf wb_test')
|
145
|
-
fw = Roma::WriteBehind::FileWriter.new(
|
143
|
+
fw = Roma::WriteBehind::FileWriter.new('wb_test', 900, Logger.new(nil))
|
146
144
|
|
147
|
-
assert_nil(
|
145
|
+
assert_nil(fw.get_current_file_path('roma'))
|
148
146
|
|
149
|
-
fw.write('roma',0,
|
147
|
+
fw.write('roma', 0, 'key', 'val')
|
150
148
|
|
151
149
|
path = File.expand_path("./wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/")
|
152
|
-
assert_equal(
|
150
|
+
assert_equal(File.join(path, '0.wb'), fw.get_current_file_path('roma'))
|
153
151
|
|
154
152
|
fw.rotate('roma')
|
155
|
-
assert_nil(
|
153
|
+
assert_nil(fw.get_current_file_path('roma'))
|
156
154
|
|
157
|
-
fw.write('roma',0,
|
158
|
-
assert_equal(
|
155
|
+
fw.write('roma', 0, 'key', 'val')
|
156
|
+
assert_equal(File.join(path, '1.wb'), fw.get_current_file_path('roma'))
|
159
157
|
end
|
160
158
|
|
161
159
|
def test_wb_get_path
|
162
160
|
system('rm -rf wb_test')
|
163
|
-
fw = Roma::WriteBehind::FileWriter.new(
|
164
|
-
path = File.expand_path(
|
165
|
-
assert_equal(
|
161
|
+
fw = Roma::WriteBehind::FileWriter.new('wb_test', 900, Logger.new(nil))
|
162
|
+
path = File.expand_path('./wb_test/roma0_11211/roma')
|
163
|
+
assert_equal(path, fw.wb_get_path('roma'))
|
166
164
|
end
|
167
165
|
|
168
166
|
def read_wb(fname)
|
169
167
|
ret = []
|
170
|
-
open(fname,'rb')
|
171
|
-
until
|
168
|
+
open(fname, 'rb') do |f|
|
169
|
+
until f.eof?
|
172
170
|
b1 = f.read(10)
|
173
171
|
last, cmd, klen = b1.unpack('NnN')
|
174
172
|
key = f.read(klen)
|
175
173
|
b2 = f.read(4)
|
176
174
|
vlen = b2.unpack('N')[0]
|
177
175
|
val = f.read(vlen)
|
178
|
-
ret << [last,cmd,key,val]
|
176
|
+
ret << [last, cmd, key, val]
|
179
177
|
end
|
180
|
-
|
178
|
+
end
|
181
179
|
ret
|
182
180
|
end
|
183
|
-
|
184
181
|
end
|
185
182
|
|
186
183
|
class FileWriterTest < Test::Unit::TestCase
|
@@ -189,7 +186,7 @@ class FileWriterTest < Test::Unit::TestCase
|
|
189
186
|
def setup
|
190
187
|
@stats = Roma::Stats.instance
|
191
188
|
@stats.address = 'roma0'
|
192
|
-
@stats.port =
|
189
|
+
@stats.port = 11_211
|
193
190
|
end
|
194
191
|
|
195
192
|
def teardown
|
@@ -203,89 +200,87 @@ class WriteBehindTest < Test::Unit::TestCase
|
|
203
200
|
|
204
201
|
def setup
|
205
202
|
start_roma
|
206
|
-
@rc=Roma::Client::RomaClient.new(
|
207
|
-
|
208
|
-
|
203
|
+
@rc = Roma::Client::RomaClient.new(%w(localhost_11211 localhost_11212),
|
204
|
+
[Roma::Client::Plugin::Alist,
|
205
|
+
Roma::Client::Plugin::Map])
|
209
206
|
system('rm -rf wb')
|
210
207
|
end
|
211
208
|
|
212
209
|
def teardown
|
213
210
|
stop_roma
|
214
|
-
Roma::Messaging::ConPool
|
211
|
+
Roma::Messaging::ConPool.instance.close_all
|
215
212
|
rescue => e
|
216
|
-
|
213
|
+
puts "#{e} #{$ERROR_POSITION}"
|
217
214
|
end
|
218
215
|
|
219
216
|
def test_wb2_stat
|
220
|
-
ret = send_cmd(
|
217
|
+
ret = send_cmd('localhost_11211', 'stat wb_command_map')
|
221
218
|
assert_equal("stats.wb_command_map {}\r\n", ret)
|
222
219
|
end
|
223
220
|
|
224
221
|
def test_wb2_command_map
|
225
|
-
send_cmd(
|
226
|
-
ret = send_cmd(
|
222
|
+
send_cmd('localhost_11211', 'wb_command_map {:set=>1}')
|
223
|
+
ret = send_cmd('localhost_11211', 'stat wb_command_map')
|
227
224
|
assert_equal("stats.wb_command_map {:set=>1}\r\n", ret)
|
228
225
|
end
|
229
226
|
|
230
227
|
def test_wb2_set
|
231
|
-
send_cmd(
|
232
|
-
assert_equal(
|
233
|
-
send_cmd(
|
228
|
+
send_cmd('localhost_11211', 'wb_command_map {:set=>1}')
|
229
|
+
assert_equal('STORED', @rc.set('abc', 'value abc', 0, true))
|
230
|
+
send_cmd('localhost_11211', 'writebehind_rotate roma')
|
234
231
|
|
235
232
|
wb0 = read_wb("#{wb_path}/0.wb")
|
236
233
|
assert_equal(1, wb0.length)
|
237
|
-
wb0.each do |
|
238
|
-
puts "#{cmd} #{key} #{val.inspect}"
|
234
|
+
wb0.each do |_last, cmd, key, val|
|
235
|
+
# puts "#{cmd} #{key} #{val.inspect}"
|
239
236
|
assert_equal(1, cmd)
|
240
|
-
assert_equal(
|
241
|
-
assert_equal(
|
237
|
+
assert_equal('abc', key)
|
238
|
+
assert_equal('value abc', val)
|
242
239
|
end
|
243
240
|
end
|
244
241
|
|
245
242
|
def test_wb2_set2
|
246
|
-
send_cmd(
|
247
|
-
assert_equal(
|
248
|
-
assert_equal(
|
249
|
-
send_cmd(
|
243
|
+
send_cmd('localhost_11211', 'wb_command_map {:set=>1, :set__prev=>2}')
|
244
|
+
assert_equal('STORED', @rc.set('abc', 'val1', 0, true))
|
245
|
+
assert_equal('STORED', @rc.set('abc', 'val2', 0, true))
|
246
|
+
send_cmd('localhost_11211', 'writebehind_rotate roma')
|
250
247
|
|
251
|
-
res = [[1,
|
248
|
+
res = [[1, 'abc', 'val1'], [2, 'abc', 'val1'], [1, 'abc', 'val2']]
|
252
249
|
wb0 = read_wb("#{wb_path}/0.wb")
|
253
250
|
assert_equal(3, wb0.length)
|
254
251
|
i = 0
|
255
|
-
wb0.each do |
|
252
|
+
wb0.each do |_last, cmd, key, val|
|
256
253
|
# puts "#{cmd} #{key} #{val.inspect} #{i}"
|
257
254
|
assert_equal(res[i][0], cmd)
|
258
255
|
assert_equal(res[i][1], key)
|
259
256
|
assert_equal(res[i][2], val)
|
260
|
-
i+=1
|
257
|
+
i += 1
|
261
258
|
end
|
262
259
|
end
|
263
260
|
|
264
|
-
|
265
261
|
def test_wb2_storage_commands
|
266
|
-
h = {:
|
267
|
-
send_cmd(
|
268
|
-
assert_equal(
|
269
|
-
assert_equal(
|
270
|
-
assert_equal(
|
271
|
-
assert_equal(
|
272
|
-
assert_equal(
|
273
|
-
assert_equal(
|
274
|
-
res = @rc.cas(
|
275
|
-
v =
|
262
|
+
h = { set: 1, delete: 2, add: 3, replace: 4, append: 5, prepend: 6, cas: 7, incr: 8, decr: 9, set_expt: 10 }
|
263
|
+
send_cmd('localhost_11211', "wb_command_map #{h}")
|
264
|
+
assert_equal('STORED', @rc.set('abc', '1', 0, true))
|
265
|
+
assert_equal('DELETED', @rc.delete('abc'))
|
266
|
+
assert_equal('STORED', @rc.add('abc', '1', 0, true))
|
267
|
+
assert_equal('STORED', @rc.replace('abc', '2', 0, true))
|
268
|
+
assert_equal('STORED', @rc.append('abc', '3'))
|
269
|
+
assert_equal('STORED', @rc.prepend('abc', '1'))
|
270
|
+
res = @rc.cas('abc', 0, true) do |_v|
|
271
|
+
v = '128'
|
276
272
|
end
|
277
|
-
assert_equal(
|
278
|
-
assert_equal(129, @rc.incr(
|
279
|
-
assert_equal(128, @rc.decr(
|
280
|
-
res = send_cmd(
|
281
|
-
assert_equal(
|
282
|
-
send_cmd(
|
283
|
-
|
284
|
-
|
285
|
-
res = {1=>'1',2=>'1',3=>'1',4=>'2',5=>'23',6=>'123',7=>'128',8=>'129',9=>'128', 10=>nil}
|
273
|
+
assert_equal('STORED', res)
|
274
|
+
assert_equal(129, @rc.incr('abc'))
|
275
|
+
assert_equal(128, @rc.decr('abc'))
|
276
|
+
res = send_cmd('localhost_11211', 'set_expt abc 100')
|
277
|
+
assert_equal('STORED', res.chomp)
|
278
|
+
send_cmd('localhost_11211', 'writebehind_rotate roma')
|
279
|
+
|
280
|
+
res = { 1 => '1', 2 => '1', 3 => '1', 4 => '2', 5 => '23', 6 => '123', 7 => '128', 8 => '129', 9 => '128', 10 => nil }
|
286
281
|
wb0 = read_wb("#{wb_path}/0.wb")
|
287
282
|
assert_equal(10, wb0.length)
|
288
|
-
wb0.each do |
|
283
|
+
wb0.each do |_last, cmd, _key, val|
|
289
284
|
# puts "#{cmd} #{key} #{val.inspect}"
|
290
285
|
assert_equal(res[cmd], val) if res[cmd]
|
291
286
|
end
|
@@ -293,52 +288,52 @@ class WriteBehindTest < Test::Unit::TestCase
|
|
293
288
|
|
294
289
|
def test_wb2_storage_commands2
|
295
290
|
h = {
|
296
|
-
:
|
297
|
-
:
|
298
|
-
:
|
299
|
-
:
|
300
|
-
:
|
301
|
-
:
|
302
|
-
:
|
303
|
-
:
|
304
|
-
:
|
305
|
-
:
|
291
|
+
set: 1, set__prev: 11,
|
292
|
+
delete: 2, delete__prev: 12,
|
293
|
+
add: 3, add__prev: 13,
|
294
|
+
replace: 4, replace__prev: 14,
|
295
|
+
append: 5, append__prev: 15,
|
296
|
+
prepend: 6, prepend__prev: 16,
|
297
|
+
cas: 7, cas__prev: 17,
|
298
|
+
incr: 8, incr__prev: 18,
|
299
|
+
decr: 9, decr__prev: 19,
|
300
|
+
set_expt: 10, set_expt__prev: 20
|
306
301
|
}
|
307
|
-
send_cmd(
|
308
|
-
assert_equal(
|
309
|
-
assert_equal(
|
310
|
-
assert_equal(
|
311
|
-
assert_equal(
|
312
|
-
assert_equal(
|
313
|
-
assert_equal(
|
314
|
-
res = @rc.cas(
|
315
|
-
v =
|
302
|
+
send_cmd('localhost_11211', "wb_command_map #{h}")
|
303
|
+
assert_equal('STORED', @rc.set('abc', '1', 0, true))
|
304
|
+
assert_equal('DELETED', @rc.delete('abc'))
|
305
|
+
assert_equal('STORED', @rc.add('abc', '1', 0, true))
|
306
|
+
assert_equal('STORED', @rc.replace('abc', '2', 0, true))
|
307
|
+
assert_equal('STORED', @rc.append('abc', '3'))
|
308
|
+
assert_equal('STORED', @rc.prepend('abc', '1'))
|
309
|
+
res = @rc.cas('abc', 0, true) do |_v|
|
310
|
+
v = '128'
|
316
311
|
end
|
317
|
-
assert_equal(
|
318
|
-
assert_equal(129, @rc.incr(
|
319
|
-
assert_equal(128, @rc.decr(
|
320
|
-
res = send_cmd(
|
321
|
-
assert_equal(
|
312
|
+
assert_equal('STORED', res)
|
313
|
+
assert_equal(129, @rc.incr('abc'))
|
314
|
+
assert_equal(128, @rc.decr('abc'))
|
315
|
+
res = send_cmd('localhost_11211', 'set_expt abc 100')
|
316
|
+
assert_equal('STORED', res.chomp)
|
322
317
|
|
323
|
-
send_cmd(
|
318
|
+
send_cmd('localhost_11211', 'writebehind_rotate roma')
|
324
319
|
|
325
320
|
res = [
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
321
|
+
[1, 'abc', '1'], [12, 'abc', '1'],
|
322
|
+
[2, 'abc', '1'],
|
323
|
+
[3, 'abc', '1'], [14, 'abc', '1'],
|
324
|
+
[4, 'abc', '2'], [15, 'abc', '2'],
|
325
|
+
[5, 'abc', '23'], [16, 'abc', '23'],
|
326
|
+
[6, 'abc', '123'], [17, 'abc', '123'],
|
327
|
+
[7, 'abc', '128'], [18, 'abc', '128'],
|
328
|
+
[8, 'abc', '129'], [19, 'abc', '129'],
|
329
|
+
[9, 'abc', '128'],
|
330
|
+
[20, 'abc'], [10, 'abc']
|
331
|
+
]
|
337
332
|
|
338
333
|
wb0 = read_wb("#{wb_path}/0.wb")
|
339
334
|
assert_equal(18, wb0.length)
|
340
335
|
i = 0
|
341
|
-
wb0.each do |
|
336
|
+
wb0.each do |_last, cmd, key, val|
|
342
337
|
# puts "#{cmd} #{key} #{val.inspect}"
|
343
338
|
assert_equal(res[i][0], cmd)
|
344
339
|
assert_equal(res[i][1], key)
|
@@ -349,49 +344,49 @@ class WriteBehindTest < Test::Unit::TestCase
|
|
349
344
|
|
350
345
|
def test_wb2_alist_commands
|
351
346
|
h = {
|
352
|
-
:
|
353
|
-
:
|
354
|
-
:
|
355
|
-
:
|
356
|
-
:
|
357
|
-
:
|
358
|
-
:
|
359
|
-
:
|
360
|
-
:
|
361
|
-
:
|
362
|
-
:
|
363
|
-
:
|
364
|
-
:
|
365
|
-
:
|
366
|
-
:
|
367
|
-
:
|
347
|
+
alist_clear: 1,
|
348
|
+
alist_delete: 2,
|
349
|
+
alist_delete_at: 3,
|
350
|
+
alist_insert: 4,
|
351
|
+
alist_sized_insert: 5,
|
352
|
+
alist_swap_and_insert: 6,
|
353
|
+
alist_swap_and_sized_insert: 7,
|
354
|
+
alist_expired_swap_and_insert: 8,
|
355
|
+
alist_expired_swap_and_sized_insert: 9,
|
356
|
+
alist_push: 10,
|
357
|
+
alist_sized_push: 11,
|
358
|
+
alist_swap_and_push: 12,
|
359
|
+
alist_swap_and_sized_push: 13,
|
360
|
+
alist_expired_swap_and_push: 14,
|
361
|
+
alist_expired_swap_and_sized_push: 15,
|
362
|
+
alist_update_at: 16
|
368
363
|
}
|
369
|
-
send_cmd(
|
370
|
-
assert_equal('STORED', @rc.alist_push(
|
371
|
-
assert_equal('STORED', @rc.alist_insert(
|
372
|
-
assert_equal('STORED', @rc.alist_sized_insert(
|
373
|
-
assert_equal('STORED', @rc.alist_swap_and_insert(
|
374
|
-
assert_equal('STORED', @rc.alist_swap_and_sized_insert(
|
375
|
-
assert_equal('STORED', @rc.alist_expired_swap_and_insert(
|
376
|
-
assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert(
|
377
|
-
assert_equal('STORED', @rc.alist_sized_push(
|
378
|
-
assert_equal('STORED', @rc.alist_swap_and_push(
|
379
|
-
assert_equal('STORED', @rc.alist_swap_and_sized_push(
|
380
|
-
assert_equal('STORED', @rc.alist_expired_swap_and_push(
|
381
|
-
assert_equal('STORED', @rc.alist_expired_swap_and_sized_push(
|
382
|
-
assert_equal('STORED', @rc.alist_update_at(
|
383
|
-
assert_equal('DELETED', @rc.alist_delete(
|
384
|
-
assert_equal('DELETED', @rc.alist_delete_at(
|
385
|
-
assert_equal('CLEARED', @rc.alist_clear(
|
386
|
-
send_cmd(
|
364
|
+
send_cmd('localhost_11211', "wb_command_map #{h}")
|
365
|
+
assert_equal('STORED', @rc.alist_push('abc', '1')) # ['1']
|
366
|
+
assert_equal('STORED', @rc.alist_insert('abc', 0, '2')) # ['2','1']
|
367
|
+
assert_equal('STORED', @rc.alist_sized_insert('abc', 5, '3')) # ['3','2','1']
|
368
|
+
assert_equal('STORED', @rc.alist_swap_and_insert('abc', '4')) # ['4','3','2','1']
|
369
|
+
assert_equal('STORED', @rc.alist_swap_and_sized_insert('abc', 5, '5')) # ['5','4','3','2','1']
|
370
|
+
assert_equal('STORED', @rc.alist_expired_swap_and_insert('abc', 100, '6')) # ['6','5','4','3','2','1']
|
371
|
+
assert_equal('STORED', @rc.alist_expired_swap_and_sized_insert('abc', 100, 10, '7')) # ['7','6','5','4','3','2','1']
|
372
|
+
assert_equal('STORED', @rc.alist_sized_push('abc', 10, '8')) # ['7','6','5','4','3','2','1','8']
|
373
|
+
assert_equal('STORED', @rc.alist_swap_and_push('abc', '9')) # ['7','6','5','4','3','2','1','8','9']
|
374
|
+
assert_equal('STORED', @rc.alist_swap_and_sized_push('abc', 10, '10')) # ['7','6','5','4','3','2','1','8','9','10']
|
375
|
+
assert_equal('STORED', @rc.alist_expired_swap_and_push('abc', 100, '11')) # ['7','6','5','4','3','2','1','8','9','10','11']
|
376
|
+
assert_equal('STORED', @rc.alist_expired_swap_and_sized_push('abc', 100, 12, '12')) # ['7','6','5','4','3','2','1','8','9','10','12']
|
377
|
+
assert_equal('STORED', @rc.alist_update_at('abc', 0, '13')) # ['13','6','5','4','3','2','1','8','9','10','12']
|
378
|
+
assert_equal('DELETED', @rc.alist_delete('abc', '3')) # ['13','6','5','4','2','1','8','9','10','12']
|
379
|
+
assert_equal('DELETED', @rc.alist_delete_at('abc', 1)) # ['13','5','4','2','1','8','9','10','12']
|
380
|
+
assert_equal('CLEARED', @rc.alist_clear('abc'))
|
381
|
+
send_cmd('localhost_11211', 'writebehind_rotate roma')
|
387
382
|
|
388
383
|
res = {
|
389
|
-
10=>'1',4=>'2',5=>'3',6=>'4',7=>'5',8=>'6',9=>'7',11=>'8',12=>'9',
|
390
|
-
13=>'10',14=>'11',15=>'12',16=>'13',2=>'3',3=>'6',
|
391
|
-
1=>
|
384
|
+
10 => '1', 4 => '2', 5 => '3', 6 => '4', 7 => '5', 8 => '6', 9 => '7', 11 => '8', 12 => '9',
|
385
|
+
13 => '10', 14 => '11', 15 => '12', 16 => '13', 2 => '3', 3 => '6',
|
386
|
+
1 => %w(13 5 4 2 1 8 9 10 11 12) }
|
392
387
|
wb0 = read_wb("#{wb_path}/0.wb")
|
393
388
|
assert_equal(16, wb0.length)
|
394
|
-
wb0.each do |
|
389
|
+
wb0.each do |_last, cmd, _key, val|
|
395
390
|
begin
|
396
391
|
val = Marshal.load(val)[0]
|
397
392
|
rescue
|
@@ -403,21 +398,21 @@ class WriteBehindTest < Test::Unit::TestCase
|
|
403
398
|
|
404
399
|
def test_wb2_map_commands
|
405
400
|
h = {
|
406
|
-
:
|
407
|
-
:
|
408
|
-
:
|
401
|
+
map_set: 1,
|
402
|
+
map_delete: 2,
|
403
|
+
map_clear: 3
|
409
404
|
}
|
410
|
-
send_cmd(
|
411
|
-
assert_equal('STORED', @rc.map_set('abc','mapkey1','value1'))
|
405
|
+
send_cmd('localhost_11211', "wb_command_map #{h}")
|
406
|
+
assert_equal('STORED', @rc.map_set('abc', 'mapkey1', 'value1'))
|
412
407
|
assert_equal('DELETED', @rc.map_delete('abc', 'mapkey1'))
|
413
|
-
assert_equal('STORED', @rc.map_set('abc','mapkey1','value1'))
|
414
|
-
assert_equal('CLEARED', @rc.map_clear(
|
415
|
-
send_cmd(
|
408
|
+
assert_equal('STORED', @rc.map_set('abc', 'mapkey1', 'value1'))
|
409
|
+
assert_equal('CLEARED', @rc.map_clear('abc'))
|
410
|
+
send_cmd('localhost_11211', 'writebehind_rotate roma')
|
416
411
|
|
417
|
-
res = {1=>{
|
412
|
+
res = { 1 => { 'mapkey1' => 'value1' }, 2 => {}, 3 => {} }
|
418
413
|
wb0 = read_wb("#{wb_path}/0.wb")
|
419
414
|
assert_equal(4, wb0.length)
|
420
|
-
wb0.each do |
|
415
|
+
wb0.each do |_last, cmd, _key, val|
|
421
416
|
begin
|
422
417
|
val = Marshal.load(val)
|
423
418
|
rescue
|
@@ -429,36 +424,36 @@ class WriteBehindTest < Test::Unit::TestCase
|
|
429
424
|
|
430
425
|
def test_wb2_map_commands2
|
431
426
|
h = {
|
432
|
-
:
|
433
|
-
:
|
434
|
-
:
|
427
|
+
map_set: 1, map_set__prev: 11,
|
428
|
+
map_delete: 2, map_delete__prev: 12,
|
429
|
+
map_clear: 3, map_clear__prev: 13
|
435
430
|
}
|
436
|
-
send_cmd(
|
437
|
-
assert_equal('STORED', @rc.map_set('abc','mapkey1','value1'))
|
438
|
-
assert_equal('STORED', @rc.map_set('abc','mapkey2','value2'))
|
431
|
+
send_cmd('localhost_11211', "wb_command_map #{h}")
|
432
|
+
assert_equal('STORED', @rc.map_set('abc', 'mapkey1', 'value1'))
|
433
|
+
assert_equal('STORED', @rc.map_set('abc', 'mapkey2', 'value2'))
|
439
434
|
assert_equal('DELETED', @rc.map_delete('abc', 'mapkey1'))
|
440
|
-
assert_equal('STORED', @rc.map_set('abc','mapkey1','value1'))
|
441
|
-
assert_equal('CLEARED', @rc.map_clear(
|
442
|
-
send_cmd(
|
435
|
+
assert_equal('STORED', @rc.map_set('abc', 'mapkey1', 'value1'))
|
436
|
+
assert_equal('CLEARED', @rc.map_clear('abc'))
|
437
|
+
send_cmd('localhost_11211', 'writebehind_rotate roma')
|
443
438
|
|
444
439
|
res = [
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
440
|
+
[1, { 'mapkey1' => 'value1' }],
|
441
|
+
[11, { 'mapkey1' => 'value1' }], [1, { 'mapkey1' => 'value1', 'mapkey2' => 'value2' }],
|
442
|
+
[12, { 'mapkey1' => 'value1', 'mapkey2' => 'value2' }], [2, { 'mapkey2' => 'value2' }],
|
443
|
+
[11, { 'mapkey2' => 'value2' }], [1, { 'mapkey2' => 'value2', 'mapkey1' => 'value1' }],
|
444
|
+
[13, { 'mapkey2' => 'value2', 'mapkey1' => 'value1' }], [3, {}]
|
450
445
|
|
451
446
|
]
|
452
447
|
wb0 = read_wb("#{wb_path}/0.wb")
|
453
448
|
assert_equal(res.length, wb0.length)
|
454
449
|
cnt = 0
|
455
|
-
wb0.each do |
|
450
|
+
wb0.each do |_last, cmd, _key, val|
|
456
451
|
begin
|
457
452
|
val = Marshal.load(val)
|
458
453
|
rescue
|
459
454
|
end
|
460
|
-
#puts "#{cmd} #{key} #{val.inspect}"
|
461
|
-
|
455
|
+
# puts "#{cmd} #{key} #{val.inspect}"
|
456
|
+
assert_equal(res[cnt][0], cmd)
|
462
457
|
assert_equal(res[cnt][1], val)
|
463
458
|
cnt += 1
|
464
459
|
end
|
@@ -477,10 +472,10 @@ class WriteBehindTest < Test::Unit::TestCase
|
|
477
472
|
end
|
478
473
|
|
479
474
|
def wb_hostname
|
480
|
-
if File.exist?(
|
481
|
-
|
482
|
-
elsif File.exist?(
|
483
|
-
|
475
|
+
if File.exist?('wb/localhost_11211')
|
476
|
+
'localhost_11211'
|
477
|
+
elsif File.exist?('wb/localhost_11212')
|
478
|
+
'localhost_11212'
|
484
479
|
else
|
485
480
|
nil
|
486
481
|
end
|