okuyama 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/okuyama/client.rb +132 -37
- data/lib/okuyama/fast_client.rb +222 -0
- data/lib/okuyama/protocol/abstract_protocol.rb +31 -0
- data/lib/okuyama/protocol/version1.rb +306 -0
- data/lib/okuyama.rb +10 -1
- data/okuyama.gemspec +72 -0
- data/spec/okuyama/client/decr_value_spec.rb +99 -0
- data/spec/okuyama/client/incr_value_spec.rb +99 -0
- data/spec/okuyama/client/search_spec.rb +140 -0
- data/spec/okuyama/client_spec.rb +497 -20
- data/spec/okuyama/protocol/version1_spec.rb +24 -0
- data/spec/spec_helper.rb +6 -1
- metadata +12 -5
- data/lib/okuyama/protocol.rb +0 -21
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Okuyama::Client do
|
4
|
+
|
5
|
+
[true, false].each do |base64_encode_flag|
|
6
|
+
describe "when base64_encode_flag = #{base64_encode_flag}" do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@testnumval_int = 10
|
10
|
+
|
11
|
+
@testnumkey = 'testnumkey'
|
12
|
+
@testnumval = @testnumval_int.to_s
|
13
|
+
@testkey1 = 'testkey1'
|
14
|
+
@testval1 = 'testval1'
|
15
|
+
@testkey2 = 'testkey2'
|
16
|
+
@testval2 = 'testval2'
|
17
|
+
@testnewkey = 'testnewkey'
|
18
|
+
@testnewval = 'testnewval'
|
19
|
+
@testnewval1 = 'testnewval1'
|
20
|
+
@testtag = 'testtag'
|
21
|
+
@testnewtag = 'testnewtag'
|
22
|
+
@testgroup = 'testgroup'
|
23
|
+
@testnewgroup = 'testnewgroup'
|
24
|
+
@testquery1 = 'testval'
|
25
|
+
@testquery2 = 'val1'
|
26
|
+
@testnewquery = 'testnewval'
|
27
|
+
|
28
|
+
if base64_encode_flag == false then
|
29
|
+
@testnumkey = Base64.encode64(@testnumkey).chomp
|
30
|
+
@testnumval = Base64.encode64(@testnumval).chomp
|
31
|
+
@testkey1 = Base64.encode64(@testkey1).chomp
|
32
|
+
@testval1 = Base64.encode64(@testval1).chomp
|
33
|
+
@testkey2 = Base64.encode64(@testkey2).chomp
|
34
|
+
@testval2 = Base64.encode64(@testval2).chomp
|
35
|
+
@testnewkey = Base64.encode64(@testnewkey).chomp
|
36
|
+
@testnewval = Base64.encode64(@testnewval).chomp
|
37
|
+
@testnewval1 = Base64.encode64(@testnewval1).chomp
|
38
|
+
@testtag = Base64.encode64(@testtag).chomp
|
39
|
+
@testnewtag = Base64.encode64(@testnewtag).chomp
|
40
|
+
@testgroup = Base64.encode64(@testgroup).chomp
|
41
|
+
@testnewgroup = Base64.encode64(@testnewgroup).chomp
|
42
|
+
@testquery1 = Base64.encode64(@testquery1).chomp
|
43
|
+
@testquery2 = Base64.encode64(@testquery2).chomp
|
44
|
+
@testnewquery = Base64.encode64(@testnewquery).chomp
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
@client = Okuyama::Client.new(:host=>'localhost', :port=>8888, :base64_encode_flag=>base64_encode_flag)
|
49
|
+
@client.debug = true
|
50
|
+
@client.remove_value(@testnumkey)
|
51
|
+
@client.remove_value(@testkey1)
|
52
|
+
@client.remove_value(@testkey2)
|
53
|
+
@client.remove_value(@testnewkey)
|
54
|
+
@client.remove_tag_from_key(@testnewtag, @testkey1)
|
55
|
+
@client.set_value(@testnumkey, @testnumval)
|
56
|
+
@client.set_value_and_create_index(@testkey1, @testval1, :tags=>[@testtag], :group=>@testgroup, :min_n=>1, :max_n=>3)
|
57
|
+
@client.set_value(@testkey2, @testval2, @testtag)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
after :each do
|
62
|
+
@client.close
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "set_value_and_create_index(key, val, :tags=>tags, :group=>group, :min_n=>min_n, :max_n=>max_n)" do
|
66
|
+
describe "when key exists," do
|
67
|
+
it "should success" do
|
68
|
+
Okuyama.logger.debug("send: #{@client.protocol.message_of_set_value_and_create_index(@testkey1, @testval1, @testtag, @testgroup, '1', '3').inspect}")
|
69
|
+
result = @client.set_value_and_create_index(@testkey1, @testval1, :tags=>[@testtag], :group=>@testgroup, :min_n=>1, :max_n=>3)
|
70
|
+
result.should be_true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
describe "when key does not exist," do
|
74
|
+
it "should success" do
|
75
|
+
Okuyama.logger.debug("send: #{@client.protocol.message_of_set_value_and_create_index(@testnewkey, @testnewval, @testnewtag, @testnewgroup, '1', '3').inspect}")
|
76
|
+
result = @client.set_value_and_create_index(@testnewkey, @testnewval, :tags=>[@testnewtag], :group=>@testnewgroup, :min_n=>1, :max_n=>3)
|
77
|
+
result.should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "search_value(query)" do
|
83
|
+
describe "when key exists," do
|
84
|
+
it "should return keys" do
|
85
|
+
Okuyama.logger.debug("send: #{@client.protocol.message_of_search_value([@testquery1]).inspect}")
|
86
|
+
result = @client.search_value(@testquery1)
|
87
|
+
result.sort!
|
88
|
+
result.should == [@testkey1]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
describe "when key does not exist," do
|
92
|
+
it "should return []" do
|
93
|
+
result = @client.search_value(@testnewquery)
|
94
|
+
result.should == []
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "search_value(query, :condition=>:and, :group=>group, :nsize=>nsize)" do
|
100
|
+
if false then
|
101
|
+
describe "when key exists," do
|
102
|
+
it "should return keys" do
|
103
|
+
Okuyama.logger.debug("send: #{@client.protocol.message_of_search_value([@testquery1, @testquery2], '1', @testgroup, '3').inspect}")
|
104
|
+
result = @client.search_value([@testquery1, @testquery2], :condition=>:and, :group=>@testgroup, :nsize=>3)
|
105
|
+
result.sort!
|
106
|
+
result.should == ['testkey1']
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
describe "when key does not exist," do
|
111
|
+
it "should return []" do
|
112
|
+
result = @client.search_value([@testquery1, @testnewquery], :condition=>:and, :group=>@testgroup, :nsize=>3)
|
113
|
+
result.should == []
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "search_value(query, :condition=>:or, :group=>group, :nsize=>nsize)" do
|
119
|
+
if false then
|
120
|
+
describe "when key exists," do
|
121
|
+
it "should return keys" do
|
122
|
+
Okuyama.logger.debug("send: #{@client.protocol.message_of_search_value([@testquery1, @testquery2], '2', @testgroup, '3').inspect}")
|
123
|
+
result = @client.search_value([@testquery1, @testquery2], :condition=>:or, :group=>@testgroup, :nsize=>3)
|
124
|
+
result.sort!
|
125
|
+
result.should == ['testkey1']
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
describe "when key does not exist," do
|
130
|
+
it "should return []" do
|
131
|
+
result = @client.search_value([@testnewquery, @testnewquery], :condition=>:or, :group=>@testgroup, :nsize=>3)
|
132
|
+
result.should == []
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
data/spec/okuyama/client_spec.rb
CHANGED
@@ -1,29 +1,506 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Okuyama::Client do
|
4
|
-
before :each do
|
5
|
-
@client = Okuyama::Client.new(:host=>'localhost', :port=>8888)
|
6
|
-
end
|
7
|
-
|
8
|
-
after :each do
|
9
|
-
@client.close
|
10
|
-
end
|
11
4
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
[nil, true, false].each do |base64_encode_flag|
|
6
|
+
describe "when base64_encode_flag = #{base64_encode_flag}" do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@testnumkey = 'testnumkey'
|
10
|
+
@testnumval = '10'
|
11
|
+
@testkey1 = 'testkey1'
|
12
|
+
@testval1 = 'testval1'
|
13
|
+
@testkey2 = 'testkey2'
|
14
|
+
@testval2 = 'testval2'
|
15
|
+
@testnewkey = 'testnewkey'
|
16
|
+
@testnewval = 'testnewval'
|
17
|
+
@testnewval1 = 'testnewval1'
|
18
|
+
@testtag = 'testtag'
|
19
|
+
@testnewtag = 'testnewtag'
|
20
|
+
@testgroup = 'testgroup'
|
21
|
+
@testnewgroup = 'testnewgroup'
|
22
|
+
@testquery1 = 'testval'
|
23
|
+
@testquery2 = 'val1'
|
24
|
+
@testnewquery = 'testnewval'
|
25
|
+
|
26
|
+
if base64_encode_flag == false then
|
27
|
+
@testnumkey = Base64.encode64(@testnumkey).chomp
|
28
|
+
@testnumval = Base64.encode64(@testnumval).chomp
|
29
|
+
@testkey1 = Base64.encode64(@testkey1).chomp
|
30
|
+
@testval1 = Base64.encode64(@testval1).chomp
|
31
|
+
@testkey2 = Base64.encode64(@testkey2).chomp
|
32
|
+
@testval2 = Base64.encode64(@testval2).chomp
|
33
|
+
@testnewkey = Base64.encode64(@testnewkey).chomp
|
34
|
+
@testnewval = Base64.encode64(@testnewval).chomp
|
35
|
+
@testnewval1 = Base64.encode64(@testnewval1).chomp
|
36
|
+
@testtag = Base64.encode64(@testtag).chomp
|
37
|
+
@testnewtag = Base64.encode64(@testnewtag).chomp
|
38
|
+
@testgroup = Base64.encode64(@testgroup).chomp
|
39
|
+
@testnewgroup = Base64.encode64(@testnewgroup).chomp
|
40
|
+
@testquery1 = Base64.encode64(@testquery1).chomp
|
41
|
+
@testquery2 = Base64.encode64(@testquery2).chomp
|
42
|
+
@testnewquery = Base64.encode64(@testnewquery).chomp
|
43
|
+
end
|
44
|
+
|
45
|
+
@client = Okuyama::Client.new(:host=>'localhost', :port=>8888, :base64_encode_flag=>base64_encode_flag)
|
46
|
+
@client.debug = true
|
47
|
+
@client.remove_value(@testnumkey)
|
48
|
+
@client.remove_value(@testkey1)
|
49
|
+
@client.remove_value(@testkey2)
|
50
|
+
@client.remove_value(@testnewkey)
|
51
|
+
@client.remove_tag_from_key(@testnewtag, @testkey1)
|
52
|
+
@client.set_value(@testnumkey, @testnumval)
|
53
|
+
@client.set_value_and_create_index(@testkey1, @testval1, :tags=>[@testtag], :group=>@testgroup, :min_n=>1, :max_n=>3)
|
54
|
+
@client.set_value(@testkey2, @testval2, @testtag)
|
16
55
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
56
|
+
end
|
57
|
+
|
58
|
+
after :each do
|
59
|
+
@client.close
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "protocol_version" do
|
63
|
+
it "should return protocol version" do
|
64
|
+
result = @client.protocol_version
|
65
|
+
result.should == '1.0.0'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "init_count" do
|
70
|
+
it "should return init count(integer)" do
|
71
|
+
result = @client.init_count
|
72
|
+
result.should > 0
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return init count(text)" do
|
76
|
+
@client.to_i_flag = false
|
77
|
+
result = @client.init_count
|
78
|
+
result.should =~ /[0-9]+/
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "set_value(key, value)" do
|
83
|
+
describe "when key exists," do
|
84
|
+
it "should set value" do
|
85
|
+
result = @client.set_value(@testkey1, @testnewval1)
|
86
|
+
result.should == true
|
87
|
+
val = @client.get_value(@testkey1)
|
88
|
+
val.should == @testnewval1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
describe "when key does not exist," do
|
92
|
+
it "should set value" do
|
93
|
+
result = @client.set_value(@testnewkey, @testnewval)
|
94
|
+
result.should == true
|
95
|
+
val = @client.get_value(@testnewkey)
|
96
|
+
val.should == @testnewval
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "set_value(key, value, tag): tag is a String" do
|
102
|
+
describe "when key exists," do
|
103
|
+
it "should set value" do
|
104
|
+
result = @client.set_value(@testkey1, @testnewval1, @testnewtag)
|
105
|
+
result.should == true
|
106
|
+
val = @client.get_value(@testkey1)
|
107
|
+
val.should == @testnewval1
|
108
|
+
key_list = @client.get_tag_keys(@testtag)
|
109
|
+
key_list.include?(@testkey1).should be_true
|
110
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
111
|
+
key_list.include?(@testkey1).should be_true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
describe "when key does not exist," do
|
115
|
+
it "should set value" do
|
116
|
+
result = @client.set_value(@testnewkey, @testnewval, @testnewtag)
|
117
|
+
result.should == true
|
118
|
+
val = @client.get_value(@testnewkey)
|
119
|
+
val.should == @testnewval
|
120
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
121
|
+
key_list.include?(@testnewkey).should be_true
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "set_value(key, value, tags): 'tags' is a Array of String" do
|
127
|
+
describe "when key exists," do
|
128
|
+
it "should set value" do
|
129
|
+
result = @client.set_value(@testkey1, @testnewval1, [@testtag])
|
130
|
+
result.should == true
|
131
|
+
val = @client.get_value(@testkey1)
|
132
|
+
val.should == @testnewval1
|
133
|
+
key_list = @client.get_tag_keys(@testtag)
|
134
|
+
key_list.include?(@testkey1).should be_true
|
135
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
136
|
+
key_list.include?(@testkey1).should be_false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
describe "when key does not exist," do
|
140
|
+
it "should set value" do
|
141
|
+
result = @client.set_value(@testnewkey, @testnewval, [@testtag])
|
142
|
+
result.should == true
|
143
|
+
val = @client.get_value(@testnewkey)
|
144
|
+
val.should == @testnewval
|
145
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
146
|
+
key_list.include?(@testnewkey).should be_true
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "set_value(key, value, :tags=>tags): 'tags' is a Array of String" do
|
152
|
+
describe "when key exists," do
|
153
|
+
it "should set value" do
|
154
|
+
result = @client.set_value(@testkey1, @testnewval1, :tags=>[@testtag])
|
155
|
+
result.should == true
|
156
|
+
val = @client.get_value(@testkey1)
|
157
|
+
val.should == @testnewval1
|
158
|
+
key_list = @client.get_tag_keys(@testtag)
|
159
|
+
key_list.include?(@testkey1).should be_true
|
160
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
161
|
+
key_list.include?(@testkey1).should be_false
|
162
|
+
end
|
163
|
+
end
|
164
|
+
describe "when key does not exist," do
|
165
|
+
it "should set value" do
|
166
|
+
result = @client.set_value(@testnewkey, @testnewval, :tags=>[@testnewtag])
|
167
|
+
result.should == true
|
168
|
+
val = @client.get_value(@testnewkey)
|
169
|
+
val.should == @testnewval
|
170
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
171
|
+
key_list.include?(@testnewkey).should be_true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "get_value(key)" do
|
177
|
+
describe "when key exists," do
|
178
|
+
it "should return value" do
|
179
|
+
result = @client.get_value(@testkey1)
|
180
|
+
result.should == @testval1
|
181
|
+
end
|
182
|
+
end
|
183
|
+
describe "when key does not exist," do
|
184
|
+
it "should fail" do
|
185
|
+
result = @client.get_value(@testnewkey)
|
186
|
+
result.should be_nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "get_tag_keys(tag)" do
|
192
|
+
describe "when tag exists," do
|
193
|
+
it "should return keys" do
|
194
|
+
result = @client.get_tag_keys(@testtag)
|
195
|
+
result.sort!
|
196
|
+
result.shift == @testkey1
|
197
|
+
result.shift == @testkey2
|
198
|
+
result == []
|
199
|
+
end
|
200
|
+
end
|
201
|
+
describe "when tag does not exist," do
|
202
|
+
it "should return []" do
|
203
|
+
result = @client.get_tag_keys(@testnewtag)
|
204
|
+
result.should == []
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "remove_value(key)" do
|
210
|
+
describe "when key does not exist," do
|
211
|
+
it "should fail" do
|
212
|
+
result = @client.remove_value(@testnewkey)
|
213
|
+
result.should be_nil
|
214
|
+
end
|
215
|
+
end
|
216
|
+
describe "when key exists," do
|
217
|
+
it "should success" do
|
218
|
+
result = @client.remove_value(@testkey1)
|
219
|
+
result.should == true
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "set_new_value(key, value)" do
|
225
|
+
describe "when key exists," do
|
226
|
+
it "should fail" do
|
227
|
+
result = @client.set_new_value(@testkey1, @testnewval1)
|
228
|
+
result.should be_nil
|
229
|
+
val = @client.get_value(@testkey1)
|
230
|
+
val.should == @testval1
|
231
|
+
end
|
232
|
+
end
|
233
|
+
describe "when key does not exist," do
|
234
|
+
it "should set value" do
|
235
|
+
result = @client.set_new_value(@testnewkey, @testnewval)
|
236
|
+
result.should == true
|
237
|
+
val = @client.get_value(@testnewkey)
|
238
|
+
val.should == @testnewval
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "set_new_value(key, value, tag): 'tag' is a String" do
|
244
|
+
describe "when key exists," do
|
245
|
+
it "should fail" do
|
246
|
+
result = @client.set_new_value(@testkey1, @testnewval1, @testnewtag)
|
247
|
+
result.should be_nil
|
248
|
+
end
|
249
|
+
end
|
250
|
+
describe "when key does not exist," do
|
251
|
+
it "should set value" do
|
252
|
+
result = @client.set_new_value(@testnewkey, @testnewval, @testnewtag)
|
253
|
+
result.should == true
|
254
|
+
val = @client.get_value(@testnewkey)
|
255
|
+
val.should == @testnewval
|
256
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
257
|
+
key_list.include?(@testnewkey).should be_true
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe "set_new_value(key, value, tags): 'tags' is a Array of String" do
|
263
|
+
describe "when key exists," do
|
264
|
+
it "should fail" do
|
265
|
+
result = @client.set_new_value(@testkey1, @testnewval1, [@testtag])
|
266
|
+
result.should be_nil
|
267
|
+
end
|
268
|
+
end
|
269
|
+
describe "when key does not exist," do
|
270
|
+
it "should set value" do
|
271
|
+
result = @client.set_new_value(@testnewkey, @testnewval, [@testtag])
|
272
|
+
result.should == true
|
273
|
+
val = @client.get_value(@testnewkey)
|
274
|
+
val.should == @testnewval
|
275
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
276
|
+
key_list.include?(@testnewkey).should be_true
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe "set_new_value(key, value, :tags=>tags): 'tags' is a Array of String" do
|
282
|
+
describe "when key exists," do
|
283
|
+
it "should fail" do
|
284
|
+
result = @client.set_new_value(@testkey1, @testnewval1, :tags=>[@testtag])
|
285
|
+
result.should be_nil
|
286
|
+
end
|
287
|
+
end
|
288
|
+
describe "when key does not exist," do
|
289
|
+
it "should set value" do
|
290
|
+
result = @client.set_new_value(@testnewkey, @testnewval, :tags=>[@testnewtag])
|
291
|
+
result.should == true
|
292
|
+
val = @client.get_value(@testnewkey)
|
293
|
+
val.should == @testnewval
|
294
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
295
|
+
key_list.include?(@testnewkey).should be_true
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe "get_value_version_check(key)" do
|
301
|
+
describe "when key exists," do
|
302
|
+
it "should return value and version number" do
|
303
|
+
result = @client.get_value_version_check(@testkey1)
|
304
|
+
result.size.should == 2
|
305
|
+
result[0].should == @testval1
|
306
|
+
result[1].length.should > 0
|
307
|
+
end
|
308
|
+
end
|
309
|
+
describe "when key does not exist," do
|
310
|
+
it "should set value" do
|
311
|
+
result = @client.get_value_version_check(@testnewkey)
|
312
|
+
result.should be_nil
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
describe "set_value_version_check(key, value, version)" do
|
318
|
+
describe "when key exists," do
|
319
|
+
describe "when version number is same" do
|
320
|
+
it "should set value" do
|
321
|
+
result = @client.get_value_version_check(@testkey1)
|
322
|
+
version = result[1]
|
323
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, result[1])
|
324
|
+
result.should == true
|
325
|
+
val = @client.get_value(@testkey1)
|
326
|
+
val.should == @testnewval1
|
327
|
+
end
|
328
|
+
end
|
329
|
+
describe "when version number is different" do
|
330
|
+
it "should fail" do
|
331
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, 'differentversion')
|
332
|
+
result.should be_nil
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
describe "when key does not exist," do
|
337
|
+
it "should fail" do
|
338
|
+
result = @client.set_value_version_check(@testnewkey, @testnewval, 'newversion')
|
339
|
+
result.should be_nil
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "set_value_version_check(key, value, version, tag): tag is a String" do
|
345
|
+
describe "when key exists," do
|
346
|
+
describe "when version number is same" do
|
347
|
+
it "should set value" do
|
348
|
+
result = @client.get_value_version_check(@testkey1)
|
349
|
+
version = result[1]
|
350
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, version, @testnewtag)
|
351
|
+
result.should == true
|
352
|
+
val = @client.get_value(@testkey1)
|
353
|
+
val.should == @testnewval1
|
354
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
355
|
+
key_list.include?(@testkey1).should be_true
|
356
|
+
end
|
357
|
+
end
|
358
|
+
describe "when version number is different" do
|
359
|
+
it "should fail" do
|
360
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, 'differentversion')
|
361
|
+
result.should be_nil
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
describe "when key does not exist," do
|
366
|
+
it "should fail" do
|
367
|
+
result = @client.set_value_version_check(@testnewkey, @testnewval, 'newversion')
|
368
|
+
result.should be_nil
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
describe "set_value_version_check(key, value, version, tags): 'tags' is a Array of String" do
|
374
|
+
describe "when key exists," do
|
375
|
+
describe "when version number is same" do
|
376
|
+
it "should set value" do
|
377
|
+
result = @client.get_value_version_check(@testkey1)
|
378
|
+
version = result[1]
|
379
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, version, [@testnewtag])
|
380
|
+
result.should == true
|
381
|
+
val = @client.get_value(@testkey1)
|
382
|
+
val.should == @testnewval1
|
383
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
384
|
+
key_list.include?(@testkey1).should be_true
|
385
|
+
end
|
386
|
+
end
|
387
|
+
describe "when version number is different" do
|
388
|
+
it "should fail" do
|
389
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, 'differentversion')
|
390
|
+
result.should be_nil
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
describe "when key does not exist," do
|
395
|
+
it "should fail" do
|
396
|
+
result = @client.set_value_version_check(@testnewkey, @testnewval, 'newversion')
|
397
|
+
result.should be_nil
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
describe "set_value_version_check(key, value, version, :tags=>tags): 'tags' is a Array of String" do
|
403
|
+
describe "when key exists," do
|
404
|
+
describe "when version number is same" do
|
405
|
+
it "should set value" do
|
406
|
+
result = @client.get_value_version_check(@testkey1)
|
407
|
+
version = result[1]
|
408
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, version, :tags=>[@testnewtag])
|
409
|
+
result.should == true
|
410
|
+
val = @client.get_value(@testkey1)
|
411
|
+
val.should == @testnewval1
|
412
|
+
key_list = @client.get_tag_keys(@testnewtag)
|
413
|
+
key_list.include?(@testkey1).should be_true
|
414
|
+
end
|
415
|
+
end
|
416
|
+
describe "when version number is different" do
|
417
|
+
it "should fail" do
|
418
|
+
result = @client.set_value_version_check(@testkey1, @testnewval1, 'differentno')
|
419
|
+
result.should be_nil
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
describe "when key does not exist," do
|
424
|
+
it "should fail" do
|
425
|
+
result = @client.set_value_version_check(@testnewkey, @testnewval, 'newversion')
|
426
|
+
result.should be_nil
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe "get_multi_value(key)" do
|
432
|
+
describe "when all keys exist," do
|
433
|
+
it "should return values" do
|
434
|
+
result = @client.get_multi_value([@testkey1, @testkey2])
|
435
|
+
result.should == [@testval1, @testval2]
|
436
|
+
end
|
437
|
+
end
|
438
|
+
describe "when keys exist or not," do
|
439
|
+
it "should return existing values" do
|
440
|
+
result = @client.get_multi_value([@testkey1, @testnewkey])
|
441
|
+
result.should == [@testval1, nil]
|
442
|
+
end
|
443
|
+
end
|
444
|
+
describe "when no keys exist," do
|
445
|
+
it "should return nils" do
|
446
|
+
result = @client.get_multi_value([@testnewkey, @testnewkey])
|
447
|
+
result.should == [nil, nil]
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
21
451
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
452
|
+
describe "get_tag_values(tag)" do
|
453
|
+
describe "when keys exist," do
|
454
|
+
it "should return key-values" do
|
455
|
+
result = @client.get_tag_values(@testtag)
|
456
|
+
result.sort!{|a,b|a[0]<=>b[0]}
|
457
|
+
result.shift.should == [@testkey1, @testval1]
|
458
|
+
result.shift.should == [@testkey2, @testval2]
|
459
|
+
result.should == []
|
460
|
+
end
|
461
|
+
end
|
462
|
+
describe "when no keys exist," do
|
463
|
+
it "should return []" do
|
464
|
+
result = @client.get_tag_values(@testnewtag)
|
465
|
+
result.should == []
|
466
|
+
end
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
describe "remove_tag_from_key(tag, key)" do
|
471
|
+
describe "when tag&key exist," do
|
472
|
+
it "should remove tag from key" do
|
473
|
+
result = @client.remove_tag_from_key(@testtag, @testkey1)
|
474
|
+
result.should be_true
|
475
|
+
key_list = @client.get_tag_keys(@testtag)
|
476
|
+
key_list.include?(@testkey1).should be_false
|
477
|
+
end
|
478
|
+
end
|
479
|
+
describe "when tag&key do not exist," do
|
480
|
+
it "should fail" do
|
481
|
+
result = @client.remove_tag_from_key(@testnewtag, @testkey1)
|
482
|
+
result.should be_nil
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
describe "set_value_and_create_index(key, val)" do
|
488
|
+
describe "when key exists," do
|
489
|
+
it "should success" do
|
490
|
+
result = @client.set_value_and_create_index(@testkey1, @testval1)
|
491
|
+
result.should be_true
|
492
|
+
end
|
493
|
+
end
|
494
|
+
describe "when key does not exist," do
|
495
|
+
it "should success" do
|
496
|
+
result = @client.set_value_and_create_index(@testnewkey, @testnewval)
|
497
|
+
result.should be_true
|
498
|
+
end
|
499
|
+
end
|
500
|
+
end
|
27
501
|
|
502
|
+
|
503
|
+
end
|
504
|
+
end
|
28
505
|
end
|
29
506
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Okuyama::Protocol::Version1 do
|
4
|
+
before :each do
|
5
|
+
@protocol = Okuyama::Protocol::Version1.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should write incr_value message" do
|
9
|
+
result = @protocol.message_of_incr_value('testnumkey', '1')
|
10
|
+
result.chomp.should == "13,dGVzdG51bWtleQ==,0,MQ=="
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should write set_value_and_create_index message" do
|
14
|
+
result = @protocol.message_of_set_value_and_create_index('key', 'val', ['tag'], 'group', '1', '3')
|
15
|
+
result.chomp.should == "42,a2V5,dGFn,0,dmFs,Z3JvdXA=,1,3"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should write search_value message" do
|
19
|
+
result = @protocol.message_of_search_value(['query1', 'query2'], '1', 'group', '3')
|
20
|
+
result.chomp.should == "43,cXVlcnkx:cXVlcnky,1,Z3JvdXA=,3"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|