couchbase-jruby-client 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/couchbase-jruby-client.gemspec +1 -1
- data/lib/couchbase.rb +21 -15
- data/lib/couchbase/bucket.rb +39 -41
- data/lib/couchbase/operations/store.rb +1 -1
- data/lib/couchbase/version.rb +1 -1
- data/test/setup.rb +8 -145
- data/test/test_arithmetic.rb +53 -76
- data/test/test_async.rb +74 -102
- data/test/test_bucket.rb +71 -63
- data/test/test_cas.rb +9 -23
- data/test/test_couchbase.rb +5 -4
- data/test/test_delete.rb +41 -43
- data/test/test_design_docs.rb +8 -18
- data/test/test_errors.rb +9 -18
- data/test/test_format.rb +21 -31
- data/test/test_get.rb +107 -150
- data/test/test_stats.rb +9 -24
- data/test/test_store.rb +53 -62
- data/test/test_timer.rb +3 -12
- data/test/test_touch.rb +26 -33
- data/test/test_unlock.rb +45 -78
- data/test/test_utils.rb +2 -11
- data/test/test_version.rb +4 -14
- data/test/test_view.rb +4 -11
- metadata +5 -5
data/test/test_get.rb
CHANGED
@@ -19,155 +19,136 @@ require File.join(File.dirname(__FILE__), 'setup')
|
|
19
19
|
|
20
20
|
class TestGet < MiniTest::Test
|
21
21
|
|
22
|
-
def setup
|
23
|
-
@mock = start_mock
|
24
|
-
end
|
25
|
-
|
26
|
-
def teardown
|
27
|
-
stop_mock(@mock)
|
28
|
-
end
|
29
|
-
|
30
22
|
def test_trivial_get
|
31
|
-
|
32
|
-
|
33
|
-
val = connection.get(uniq_id)
|
23
|
+
cb.set(uniq_id, "bar")
|
24
|
+
val = cb.get(uniq_id)
|
34
25
|
assert_equal "bar", val
|
35
26
|
end
|
36
27
|
|
37
28
|
def test_extended_get
|
38
|
-
|
39
|
-
|
40
|
-
orig_cas = connection.set(uniq_id, "bar")
|
41
|
-
val, flags, cas = connection.get(uniq_id, :extended => true)
|
29
|
+
orig_cas = cb.set(uniq_id, "bar")
|
30
|
+
val, flags, cas = cb.get(uniq_id, :extended => true)
|
42
31
|
assert_equal "bar", val
|
43
32
|
#assert_equal 0x0, flags
|
44
33
|
assert_equal orig_cas, cas
|
45
34
|
|
46
|
-
orig_cas =
|
47
|
-
val, flags, cas =
|
35
|
+
orig_cas = cb.set(uniq_id, "bar", :flags => 0x1000)
|
36
|
+
val, flags, cas = cb.get(uniq_id, :extended => true)
|
48
37
|
assert_equal "bar", val
|
49
38
|
#assert_equal 0x1000, flags
|
50
39
|
assert_equal orig_cas, cas
|
51
40
|
end
|
52
41
|
|
53
42
|
def test_multi_get
|
54
|
-
|
55
|
-
|
56
|
-
connection.set(uniq_id(1), "foo1")
|
57
|
-
connection.set(uniq_id(2), "foo2")
|
43
|
+
cb.set(uniq_id(1), "foo1")
|
44
|
+
cb.set(uniq_id(2), "foo2")
|
58
45
|
|
59
|
-
val1, val2 =
|
46
|
+
val1, val2 = cb.get(uniq_id(1), uniq_id(2))
|
60
47
|
assert_equal "foo1", val1
|
61
48
|
assert_equal "foo2", val2
|
62
49
|
end
|
63
50
|
|
64
51
|
def test_multi_get_extended
|
65
52
|
skip 'Looking like Java client doesnt support multi_get_extended'
|
66
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
67
53
|
|
68
|
-
cas1 =
|
69
|
-
cas2 =
|
54
|
+
cas1 = cb.set(uniq_id(1), "foo1")
|
55
|
+
cas2 = cb.set(uniq_id(2), "foo2")
|
70
56
|
|
71
|
-
results =
|
57
|
+
results = cb.get(uniq_id(1), uniq_id(2), :extended => true)
|
72
58
|
assert_equal ["foo1", nil, cas1], results[uniq_id(1)]
|
73
59
|
assert_equal ["foo2", nil, cas2], results[uniq_id(2)]
|
74
60
|
end
|
75
61
|
|
76
62
|
def test_multi_get_and_touch
|
77
|
-
|
78
|
-
|
79
|
-
connection.set(uniq_id(2), "foo2")
|
63
|
+
cb.set(uniq_id(1), "foo1")
|
64
|
+
cb.set(uniq_id(2), "foo2")
|
80
65
|
|
81
|
-
results =
|
66
|
+
results = cb.get(uniq_id(1) => 1, uniq_id(2) => 1)
|
82
67
|
assert results.is_a?(Hash)
|
83
68
|
assert_equal "foo1", results[uniq_id(1)]
|
84
69
|
assert_equal "foo2", results[uniq_id(2)]
|
85
70
|
sleep(2)
|
86
71
|
assert_raises(Couchbase::Error::NotFound) do
|
87
|
-
|
72
|
+
cb.get(uniq_id(1), uniq_id(2))
|
88
73
|
end
|
89
|
-
assert
|
74
|
+
assert cb.get(uniq_id(1), uniq_id(2), :quiet => true).compact.empty?
|
90
75
|
end
|
91
76
|
|
92
77
|
def test_multi_get_and_touch_extended
|
93
|
-
|
78
|
+
cas1 = cb.set(uniq_id(1), "foo1")
|
79
|
+
cas2 = cb.set(uniq_id(2), "foo2")
|
94
80
|
|
95
|
-
|
96
|
-
cas2 = connection.set(uniq_id(2), "foo2")
|
97
|
-
|
98
|
-
results = connection.get({uniq_id(1) => 1, uniq_id(2) => 1}, :extended => true)
|
81
|
+
results = cb.get({uniq_id(1) => 1, uniq_id(2) => 1}, :extended => true)
|
99
82
|
assert_equal ["foo1", nil, cas1], results[uniq_id(1)]
|
100
83
|
assert_equal ["foo2", nil, cas2], results[uniq_id(2)]
|
101
84
|
end
|
102
85
|
|
103
86
|
def test_multi_get_and_touch_with_single_key
|
104
|
-
|
105
|
-
connection.set(uniq_id, "foo1")
|
87
|
+
cb.set(uniq_id, "foo1")
|
106
88
|
|
107
|
-
results =
|
89
|
+
results = cb.get(uniq_id => 1)
|
108
90
|
assert results.is_a?(Hash)
|
109
91
|
assert_equal "foo1", results[uniq_id]
|
110
92
|
sleep(2)
|
111
93
|
assert_raises(Couchbase::Error::NotFound) do
|
112
|
-
|
94
|
+
cb.get(uniq_id)
|
113
95
|
end
|
114
96
|
end
|
115
97
|
|
116
98
|
def test_missing_in_quiet_mode
|
117
|
-
|
118
|
-
cas1 =
|
119
|
-
cas2 =
|
99
|
+
cb.quiet = true
|
100
|
+
cas1 = cb.set(uniq_id(1), "foo1")
|
101
|
+
cas2 = cb.set(uniq_id(2), "foo2")
|
120
102
|
|
121
|
-
val =
|
103
|
+
val = cb.get(uniq_id(:missing))
|
122
104
|
refute(val)
|
123
|
-
val =
|
105
|
+
val = cb.get(uniq_id(:missing), :extended => true)
|
124
106
|
refute(val)
|
125
107
|
|
126
|
-
val1, missing, val2 =
|
108
|
+
val1, missing, val2 = cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
|
127
109
|
assert_equal "foo1", val1
|
128
110
|
refute missing
|
129
111
|
assert_equal "foo2", val2
|
130
112
|
|
131
113
|
# TODO: multi get with cas
|
132
|
-
# results =
|
114
|
+
# results = cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
|
133
115
|
# assert_equal ["foo1", nil, cas1], results[uniq_id(1)]
|
134
116
|
# refute results[uniq_id(:missing)]
|
135
117
|
# assert_equal ["foo2", nil, cas2], results[uniq_id(2)]
|
118
|
+
ensure
|
119
|
+
cb.quiet = false
|
136
120
|
end
|
137
121
|
|
138
122
|
def test_it_allows_temporary_quiet_flag
|
139
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => false)
|
140
123
|
assert_raises(Couchbase::Error::NotFound) do
|
141
|
-
|
124
|
+
cb.get(uniq_id(:missing))
|
142
125
|
end
|
143
|
-
refute
|
126
|
+
refute cb.get(uniq_id(:missing), :quiet => true)
|
144
127
|
end
|
145
128
|
|
146
129
|
def test_missing_in_verbose_mode
|
147
|
-
|
148
|
-
|
149
|
-
connection.set(uniq_id(2), "foo2")
|
130
|
+
cb.set(uniq_id(1), "foo1")
|
131
|
+
cb.set(uniq_id(2), "foo2")
|
150
132
|
|
151
133
|
assert_raises(Couchbase::Error::NotFound) do
|
152
|
-
|
134
|
+
cb.get(uniq_id(:missing))
|
153
135
|
end
|
154
136
|
|
155
137
|
assert_raises(Couchbase::Error::NotFound) do
|
156
|
-
|
138
|
+
cb.get(uniq_id(:missing), :extended => true)
|
157
139
|
end
|
158
140
|
|
159
141
|
assert_raises(Couchbase::Error::NotFound) do
|
160
|
-
|
142
|
+
cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
|
161
143
|
end
|
162
144
|
|
163
145
|
assert_raises(Couchbase::Error::NotFound) do
|
164
|
-
|
146
|
+
cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
|
165
147
|
end
|
166
148
|
end
|
167
149
|
|
168
150
|
def test_asynchronous_get
|
169
|
-
|
170
|
-
cas = connection.set(uniq_id, "foo")
|
151
|
+
cas = cb.set(uniq_id, "foo")
|
171
152
|
res = []
|
172
153
|
|
173
154
|
suite = lambda do |conn|
|
@@ -188,21 +169,20 @@ class TestGet < MiniTest::Test
|
|
188
169
|
end
|
189
170
|
end
|
190
171
|
|
191
|
-
|
172
|
+
cb.run(&suite)
|
192
173
|
checks.call
|
193
174
|
|
194
|
-
|
175
|
+
cb.run{ suite.call(cb) }
|
195
176
|
checks.call
|
196
177
|
end
|
197
178
|
|
198
179
|
def test_asynchronous_multi_get
|
199
180
|
skip
|
200
|
-
|
201
|
-
|
202
|
-
connection.set(uniq_id(2), "bar")
|
181
|
+
cb.set(uniq_id(1), "foo")
|
182
|
+
cb.set(uniq_id(2), "bar")
|
203
183
|
|
204
184
|
res = {}
|
205
|
-
|
185
|
+
cb.run do |conn|
|
206
186
|
conn.get(uniq_id(1), uniq_id(2)) {|ret| res[ret.key] = ret.value}
|
207
187
|
end
|
208
188
|
|
@@ -214,8 +194,7 @@ class TestGet < MiniTest::Test
|
|
214
194
|
|
215
195
|
def test_asynchronous_get_missing
|
216
196
|
skip
|
217
|
-
|
218
|
-
connection.set(uniq_id, "foo")
|
197
|
+
cb.set(uniq_id, "foo")
|
219
198
|
res = {}
|
220
199
|
missing = []
|
221
200
|
|
@@ -239,14 +218,14 @@ class TestGet < MiniTest::Test
|
|
239
218
|
conn.get(uniq_id, uniq_id(:missing2), &get_handler)
|
240
219
|
end
|
241
220
|
|
242
|
-
|
221
|
+
cb.run(&suite)
|
243
222
|
refute res.has_key?(uniq_id(:missing1))
|
244
223
|
refute res.has_key?(uniq_id(:missing2))
|
245
224
|
assert_equal [uniq_id(:missing1), uniq_id(:missing2)], missing.sort
|
246
225
|
assert_equal "foo", res[uniq_id]
|
247
226
|
|
248
|
-
|
249
|
-
|
227
|
+
cb.quiet = true
|
228
|
+
cb.run(&suite)
|
250
229
|
assert_equal "foo", res[uniq_id]
|
251
230
|
assert res.has_key?(uniq_id(:missing1)) # handler was called with nil
|
252
231
|
refute res[uniq_id(:missing1)]
|
@@ -256,16 +235,14 @@ class TestGet < MiniTest::Test
|
|
256
235
|
end
|
257
236
|
|
258
237
|
def test_get_using_brackets
|
259
|
-
|
260
|
-
|
261
|
-
orig_cas = connection.set(uniq_id, "foo", :flags => 0x1100)
|
238
|
+
orig_cas = cb.set(uniq_id, "foo", :flags => 0x1100)
|
262
239
|
|
263
|
-
val =
|
240
|
+
val = cb[uniq_id]
|
264
241
|
assert_equal "foo", val
|
265
242
|
|
266
243
|
if RUBY_VERSION =~ /^1\.9/
|
267
244
|
eval <<-EOC
|
268
|
-
val, flags, cas =
|
245
|
+
val, flags, cas = cb[uniq_id, :extended => true]
|
269
246
|
assert_equal "foo", val
|
270
247
|
#assert_equal 0x1100, flags
|
271
248
|
assert_equal orig_cas, cas
|
@@ -275,16 +252,15 @@ class TestGet < MiniTest::Test
|
|
275
252
|
|
276
253
|
def test_it_allows_to_store_nil
|
277
254
|
skip "TODO: figure out nil storage"
|
278
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
279
255
|
|
280
|
-
orig_cas =
|
256
|
+
orig_cas = cb.set(uniq_id, nil)
|
281
257
|
assert orig_cas.is_a?(Numeric)
|
282
258
|
|
283
|
-
refute
|
259
|
+
refute cb.get(uniq_id)
|
284
260
|
# doesn't raise NotFound exception
|
285
|
-
refute
|
261
|
+
refute cb.get(uniq_id, :quiet => false)
|
286
262
|
# returns CAS
|
287
|
-
value, flags, cas =
|
263
|
+
value, flags, cas = cb.get(uniq_id, :extended => true)
|
288
264
|
refute value
|
289
265
|
#assert_equal 0x00, flags
|
290
266
|
assert_equal orig_cas, cas
|
@@ -292,125 +268,106 @@ class TestGet < MiniTest::Test
|
|
292
268
|
|
293
269
|
def test_zero_length_string_is_not_nil
|
294
270
|
skip("zero length string")
|
295
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
296
271
|
|
297
|
-
|
298
|
-
assert_equal "",
|
272
|
+
cb.set(uniq_id, "", :format => :document)
|
273
|
+
assert_equal "", cb.get(uniq_id)
|
299
274
|
|
300
|
-
|
301
|
-
assert_equal "",
|
275
|
+
cb.set(uniq_id, "", :format => :plain)
|
276
|
+
assert_equal "", cb.get(uniq_id)
|
302
277
|
|
303
|
-
|
304
|
-
assert_equal "",
|
278
|
+
cb.set(uniq_id, "", :format => :marshal)
|
279
|
+
assert_equal "", cb.get(uniq_id)
|
305
280
|
|
306
|
-
|
307
|
-
assert_equal nil,
|
281
|
+
cb.set(uniq_id, nil, :format => :document)
|
282
|
+
assert_equal nil, cb.get(uniq_id, :quiet => false)
|
308
283
|
|
309
284
|
assert_raises Couchbase::Error::ValueFormat do
|
310
|
-
|
285
|
+
cb.set(uniq_id, nil, :format => :plain)
|
311
286
|
end
|
312
287
|
|
313
|
-
|
314
|
-
assert_equal nil,
|
288
|
+
cb.set(uniq_id, nil, :format => :marshal)
|
289
|
+
assert_equal nil, cb.get(uniq_id, :quiet => false)
|
315
290
|
end
|
316
291
|
|
317
292
|
def test_format_forcing
|
318
293
|
skip("format forcing")
|
319
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
320
294
|
|
321
|
-
|
322
|
-
value, flags, _ =
|
295
|
+
cb.set(uniq_id, '{"foo":"bar"}', :format => :plain)
|
296
|
+
value, flags, _ = cb.get(uniq_id, :extended => true)
|
323
297
|
assert_equal '{"foo":"bar"}', value
|
324
298
|
assert_equal 0x02, flags
|
325
299
|
|
326
|
-
value, flags, _ =
|
300
|
+
value, flags, _ = cb.get(uniq_id, :extended => true, :format => :document)
|
327
301
|
expected = {"foo" => "bar"}
|
328
302
|
assert_equal expected, value
|
329
303
|
assert_equal 0x02, flags
|
330
304
|
|
331
|
-
|
305
|
+
cb.prepend(uniq_id, "NOT-A-JSON")
|
332
306
|
assert_raises Couchbase::Error::ValueFormat do
|
333
|
-
|
307
|
+
cb.get(uniq_id, :format => :document)
|
334
308
|
end
|
335
309
|
end
|
336
310
|
|
337
311
|
# http://www.couchbase.com/issues/browse/RCBC-31
|
338
312
|
def test_consistent_behaviour_for_arrays
|
339
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
340
313
|
|
341
|
-
cas =
|
342
|
-
|
314
|
+
cas = cb.set(uniq_id("foo"), "foo")
|
315
|
+
cb.set(uniq_id("bar"), "bar")
|
343
316
|
|
344
|
-
assert_equal "foo",
|
345
|
-
assert_equal ["foo"],
|
346
|
-
assert_equal ["foo", "bar"],
|
347
|
-
assert_equal ["foo", "bar"],
|
317
|
+
assert_equal "foo", cb.get(uniq_id("foo"))
|
318
|
+
assert_equal ["foo"], cb.get([uniq_id("foo")])
|
319
|
+
assert_equal ["foo", "bar"], cb.get([uniq_id("foo"), uniq_id("bar")])
|
320
|
+
assert_equal ["foo", "bar"], cb.get(uniq_id("foo"), uniq_id("bar"))
|
348
321
|
# expected = {uniq_id("foo") => ["foo", nil, cas]}
|
349
|
-
# assert_equal expected,
|
322
|
+
# assert_equal expected, cb.get([uniq_id("foo")], :extended => true)
|
350
323
|
assert_raises TypeError do
|
351
|
-
|
324
|
+
cb.get([uniq_id("foo"), uniq_id("bar")], [uniq_id("foo")])
|
352
325
|
end
|
353
326
|
end
|
354
327
|
|
355
328
|
def test_get_with_lock_trivial
|
356
|
-
|
357
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
358
|
-
connection.set(uniq_id, "foo")
|
329
|
+
cb.set(uniq_id, "foo")
|
359
330
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
end
|
364
|
-
sleep(2)
|
365
|
-
connection.set(uniq_id, "bar")
|
366
|
-
else
|
367
|
-
skip("implement GETL in CouchbaseMock.jar")
|
331
|
+
assert_equal "foo", cb.get(uniq_id, :lock => 1)
|
332
|
+
assert_raises Couchbase::Error::KeyExists do
|
333
|
+
cb.set(uniq_id, "bar")
|
368
334
|
end
|
335
|
+
sleep(2)
|
336
|
+
cb.set(uniq_id, "bar")
|
369
337
|
end
|
370
338
|
|
371
339
|
def test_multi_get_with_lock
|
372
340
|
skip("multi_get_with_lock")
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
assert_raises Couchbase::Error::KeyExists do
|
382
|
-
connection.set(uniq_id(2), "bar")
|
383
|
-
end
|
384
|
-
else
|
385
|
-
skip("implement GETL in CouchbaseMock.jar")
|
341
|
+
cb.set(uniq_id(1), "foo1")
|
342
|
+
cb.set(uniq_id(2), "foo2")
|
343
|
+
assert_equal ["foo1", "foo2"], cb.get([uniq_id(1), uniq_id(2)], :lock => 1)
|
344
|
+
assert_raises Couchbase::Error::KeyExists do
|
345
|
+
cb.set(uniq_id(1), "bar")
|
346
|
+
end
|
347
|
+
assert_raises Couchbase::Error::KeyExists do
|
348
|
+
cb.set(uniq_id(2), "bar")
|
386
349
|
end
|
387
350
|
end
|
388
351
|
|
389
352
|
def test_multi_get_with_custom_locks
|
390
353
|
skip("multi_get_with_custom_locks")
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
assert_raises Couchbase::Error::KeyExists do
|
401
|
-
connection.set(uniq_id(2), "foo")
|
402
|
-
end
|
403
|
-
else
|
404
|
-
skip("implement GETL in CouchbaseMock.jar")
|
354
|
+
cb.set(uniq_id(1), "foo1")
|
355
|
+
cb.set(uniq_id(2), "foo2")
|
356
|
+
expected = {uniq_id(1) => "foo1", uniq_id(2) => "foo2"}
|
357
|
+
assert_equal expected, cb.get({uniq_id(1) => 1, uniq_id(2) => 2}, :lock => true)
|
358
|
+
assert_raises Couchbase::Error::KeyExists do
|
359
|
+
cb.set(uniq_id(1), "foo")
|
360
|
+
end
|
361
|
+
assert_raises Couchbase::Error::KeyExists do
|
362
|
+
cb.set(uniq_id(2), "foo")
|
405
363
|
end
|
406
364
|
end
|
407
365
|
|
408
366
|
def test_multi_get_result_hash_assembling
|
409
|
-
|
410
|
-
|
411
|
-
connection.set(uniq_id(2), "bar")
|
367
|
+
cb.set(uniq_id(1), "foo")
|
368
|
+
cb.set(uniq_id(2), "bar")
|
412
369
|
|
413
370
|
expected = {uniq_id(1) => "foo", uniq_id(2) => "bar"}
|
414
|
-
assert_equal expected,
|
371
|
+
assert_equal expected, cb.get(uniq_id(1), uniq_id(2), :assemble_hash => true)
|
415
372
|
end
|
416
373
|
end
|